Add roles taxonomy to staff close #45

This commit is contained in:
Brian Miyaji
2014-08-24 16:43:46 +10:00
parent f683ba0387
commit df3f8612a4
6 changed files with 93 additions and 18 deletions

View File

@@ -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
*/

View File

@@ -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 );

View File

@@ -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() ) );