From df3f8612a4bd4be82fa9328607d0048466cacd16 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 24 Aug 2014 16:43:46 +1000 Subject: [PATCH] Add roles taxonomy to staff close #45 --- includes/admin/class-sp-admin-menus.php | 24 ++++++++++----- .../post-types/class-sp-admin-cpt-staff.php | 3 +- .../class-sp-meta-box-staff-details.php | 26 +++++++++++++++-- includes/class-sp-post-types.php | 29 +++++++++++++++++++ includes/class-sp-staff.php | 17 ++++++++++- templates/event-staff.php | 12 ++++---- 6 files changed, 93 insertions(+), 18 deletions(-) diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php index 3b5999c7..bf6cf040 100755 --- a/includes/admin/class-sp-admin-menus.php +++ b/includes/admin/class-sp-admin-menus.php @@ -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 */ diff --git a/includes/admin/post-types/class-sp-admin-cpt-staff.php b/includes/admin/post-types/class-sp-admin-cpt-staff.php index 8e09bbe9..bed88e9c 100644 --- a/includes/admin/post-types/class-sp-admin-cpt-staff.php +++ b/includes/admin/post-types/class-sp-admin-cpt-staff.php @@ -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 ); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php index 1e80217e..0fc6aef2 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-staff-details.php @@ -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 ) ); ?>

-

+

'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; + ?>