Add roles taxonomy to staff close #45
This commit is contained in:
@@ -27,6 +27,7 @@ class SP_Admin_Menus {
|
||||
add_action( 'admin_menu', array( $this, 'overview_menu' ), 8 );
|
||||
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 9 );
|
||||
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 10 );
|
||||
add_filter( 'admin_menu', array( $this, 'menu_add' ), 20 );
|
||||
|
||||
if ( current_user_can( 'manage_options' ) )
|
||||
add_action( 'admin_menu', array( $this, 'status_menu' ), 20 );
|
||||
@@ -94,7 +95,10 @@ class SP_Admin_Menus {
|
||||
*/
|
||||
public function menu_highlight() {
|
||||
global $typenow, $submenu;
|
||||
if ( is_sp_config_type( $typenow ) )
|
||||
$screen = get_current_screen();
|
||||
if ( $screen->id == 'edit-sp_role' )
|
||||
$this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit-tags.php?taxonomy=sp_role&post_type=sp_player' );
|
||||
elseif ( is_sp_config_type( $typenow ) )
|
||||
$this->highlight_admin_menu( 'sportspress', 'sp-config' );
|
||||
elseif ( $typenow == 'sp_calendar' )
|
||||
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
|
||||
@@ -213,12 +217,6 @@ class SP_Admin_Menus {
|
||||
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_seasons' ) );
|
||||
endif;
|
||||
|
||||
// Remove "Leagues" and "Seasons" links from Staff submenu
|
||||
if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ):
|
||||
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_leagues' ) );
|
||||
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
|
||||
endif;
|
||||
|
||||
$user_roles = $current_user->roles;
|
||||
$user_role = array_shift($user_roles);
|
||||
|
||||
@@ -229,6 +227,18 @@ class SP_Admin_Menus {
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing SP menu items in admin.
|
||||
*/
|
||||
public function menu_add() {
|
||||
global $menu, $submenu, $current_user;
|
||||
|
||||
// Add "Roles" to Players submenu
|
||||
if ( isset( $submenu['edit.php?post_type=sp_player'] ) ):
|
||||
array_splice( $submenu['edit.php?post_type=sp_player'], 5, 0, array( array( __( 'Roles', 'sportspress' ), 'manage_categories', 'edit-tags.php?taxonomy=sp_role&post_type=sp_player' ) ) );
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the overview page
|
||||
*/
|
||||
|
||||
@@ -79,8 +79,7 @@ class SP_Admin_CPT_Staff extends SP_Admin_CPT {
|
||||
public function custom_columns( $column, $post_id ) {
|
||||
switch ( $column ):
|
||||
case 'sp_role':
|
||||
$role = get_post_meta ( $post_id, 'sp_role', true );
|
||||
echo $role ? $role : '—';
|
||||
echo get_the_terms( $post_id, 'sp_role' ) ? the_terms( $post_id, 'sp_role' ) : '—';
|
||||
break;
|
||||
case 'sp_team':
|
||||
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
|
||||
|
||||
@@ -22,7 +22,6 @@ class SP_Meta_Box_Staff_Details {
|
||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||
$continents = SP()->countries->continents;
|
||||
|
||||
$role = get_post_meta( $post->ID, 'sp_role', true );
|
||||
$nationality = get_post_meta( $post->ID, 'sp_nationality', true );
|
||||
|
||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||
@@ -40,13 +39,34 @@ class SP_Meta_Box_Staff_Details {
|
||||
$season_ids[] = $season->term_id;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
$roles = get_the_terms( $post->ID, 'sp_role' );
|
||||
if ( $roles ):
|
||||
$term = array_pop( $roles );
|
||||
$role = $term->term_id;
|
||||
else:
|
||||
$role = null;
|
||||
endif;
|
||||
|
||||
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
|
||||
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
|
||||
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
|
||||
?>
|
||||
<p><strong><?php _e( 'Role', 'sportspress' ); ?></strong></p>
|
||||
<p><input type="text" id="sp_role" name="sp_role" value="<?php echo $role; ?>"></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_role',
|
||||
'name' => 'sp_role',
|
||||
'selected' => $role,
|
||||
'values' => 'term_id',
|
||||
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Role', 'sportspress' ) ),
|
||||
'class' => 'widefat',
|
||||
'chosen' => true,
|
||||
);
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||
sp_taxonomy_adder( 'sp_role', 'sp_player', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></p>
|
||||
|
||||
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
|
||||
<p><select id="sp_nationality" name="sp_nationality" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
|
||||
@@ -126,7 +146,7 @@ class SP_Meta_Box_Staff_Details {
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_role', sp_array_value( $_POST, 'sp_role', '' ) );
|
||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_role', null ), 'sp_role', false );
|
||||
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
|
||||
|
||||
@@ -146,6 +146,35 @@ class SP_Post_types {
|
||||
foreach ( $object_types as $object_type ):
|
||||
register_taxonomy_for_object_type( 'sp_position', $object_type );
|
||||
endforeach;
|
||||
|
||||
$labels = array(
|
||||
'name' => __( 'Roles', 'sportspress' ),
|
||||
'singular_name' => __( 'Role', 'sportspress' ),
|
||||
'all_items' => __( 'All', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Role', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'update_item' => __( 'Update', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New', 'sportspress' ),
|
||||
'new_item_name' => __( 'Name', 'sportspress' ),
|
||||
'parent_item' => __( 'Parent', 'sportspress' ),
|
||||
'parent_item_colon' => __( 'Parent:', 'sportspress' ),
|
||||
'search_items' => __( 'Search', 'sportspress' ),
|
||||
'not_found' => __( 'No results found.', 'sportspress' ),
|
||||
);
|
||||
$args = array(
|
||||
'label' => __( 'Roles', 'sportspress' ),
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
'show_tagcloud' => false,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => get_option( 'sportspress_role_slug', 'role' ) ),
|
||||
);
|
||||
$object_types = apply_filters( 'sportspress_role_object_types', array( 'sp_staff' ) );
|
||||
register_taxonomy( 'sp_role', $object_types, $args );
|
||||
foreach ( $object_types as $object_type ):
|
||||
register_taxonomy_for_object_type( 'sp_role', $object_type );
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The SportsPress staff class handles individual staff data.
|
||||
*
|
||||
* @class SP_Staff
|
||||
* @version 0.8
|
||||
* @version 1.3
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
@@ -21,4 +21,19 @@ class SP_Staff extends SP_Custom_Post {
|
||||
public function past_teams() {
|
||||
return get_post_meta( $this->ID, 'sp_past_team', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns role
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function role() {
|
||||
$roles = get_the_terms( $this->ID, 'sp_role' );
|
||||
if ( $roles ):
|
||||
return array_pop( $roles );
|
||||
else:
|
||||
return false;
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@ $defaults = array(
|
||||
'link_posts' => get_option( 'sportspress_link_staff', 'yes' ) == 'yes' ? true : false,
|
||||
);
|
||||
|
||||
$staff = array_filter( sp_array_between( (array)get_post_meta( $id, 'sp_staff', false ), 0, $index ) );
|
||||
$staffs = array_filter( sp_array_between( (array)get_post_meta( $id, 'sp_staff', false ), 0, $index ) );
|
||||
|
||||
if ( ! $staff ) return;
|
||||
if ( ! $staffs ) return;
|
||||
|
||||
extract( $defaults, EXTR_SKIP );
|
||||
?>
|
||||
<p class="sp-event-staff">
|
||||
<?php
|
||||
foreach( $staff as $staff_id ):
|
||||
foreach( $staffs as $staff_id ):
|
||||
|
||||
if ( ! $staff_id )
|
||||
continue;
|
||||
@@ -33,10 +33,12 @@ foreach( $staff as $staff_id ):
|
||||
if ( ! $name )
|
||||
continue;
|
||||
|
||||
$role = get_post_meta( $staff_id, 'sp_role', true );
|
||||
$staff = new SP_Staff( $staff_id );
|
||||
|
||||
$role = $staff->role();
|
||||
|
||||
if ( $role )
|
||||
echo $role;
|
||||
echo $role->name;
|
||||
else
|
||||
_e( 'Staff', 'sportspress' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user