Allow multiple staff roles and display with delimiter

This commit is contained in:
Brian Miyaji
2017-11-14 22:34:43 +11:00
parent cf4dd17239
commit d5098b0ef7
6 changed files with 43 additions and 26 deletions

View File

@@ -217,6 +217,11 @@
max-height: 2em; max-height: 2em;
} }
/* Staff */
.sp-staff-role-delimiter {
margin: 0 0.125em;
}
/* Button */ /* Button */
.sp-button { .sp-button {
border: none; border: none;

View File

@@ -49,31 +49,26 @@ class SP_Meta_Box_Staff_Details {
endif; endif;
$roles = get_the_terms( $post->ID, 'sp_role' ); $roles = get_the_terms( $post->ID, 'sp_role' );
if ( $roles ): $role_ids = wp_list_pluck( $roles, 'term_id' );
$term = array_shift( $roles );
$role = $term->term_id;
else:
$role = null;
endif;
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) ); $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 ) ); $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 ) ); $current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?> ?>
<p><strong><?php _e( 'Job', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Jobs', 'sportspress' ); ?></strong></p>
<p><?php <p><?php
$args = array( $args = array(
'taxonomy' => 'sp_role', 'taxonomy' => 'sp_role',
'name' => 'sp_role', 'name' => 'tax_input[sp_role][]',
'selected' => $role, 'selected' => $role_ids,
'values' => 'term_id', 'values' => 'term_id',
'show_option_blank' => true, 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Jobs', 'sportspress' ) ),
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Job', 'sportspress' ) ),
'class' => 'widefat', 'class' => 'widefat',
'property' => 'multiple',
'chosen' => true, 'chosen' => true,
); );
if ( ! sp_dropdown_taxonomies( $args ) ): if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_role', 'sp_player', __( 'Add New', 'sportspress' ) ); sp_taxonomy_adder( 'sp_role', 'sp_staff', __( 'Add New', 'sportspress' ) );
endif; endif;
?></p> ?></p>
@@ -155,8 +150,6 @@ class SP_Meta_Box_Staff_Details {
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_role', null ), 'sp_role', false );
sp_update_post_meta_recursive( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', array() ) );
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_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() ) ); sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );

View File

@@ -56,4 +56,19 @@ class SP_Staff extends SP_Custom_Post {
return false; return false;
endif; endif;
} }
/**
* Returns roles
*
* @access public
* @return array
*/
public function roles() {
$roles = get_the_terms( $this->ID, 'sp_role' );
if ( $roles && ! is_wp_error( $roles ) ):
return (array) $roles;
else:
return array();
endif;
}
} }

View File

@@ -44,9 +44,10 @@ function sportspress_the_title( $title, $id = null ) {
endif; endif;
elseif ( is_singular( 'sp_staff' ) ): elseif ( is_singular( 'sp_staff' ) ):
$staff = new SP_Staff( $id ); $staff = new SP_Staff( $id );
$role = $staff->role(); $roles = $staff->roles();
if ( $role ): if ( ! empty( $roles ) ):
$title = '<strong class="sp-staff-role">' . $role->name . '</strong> ' . $title; $roles = wp_list_pluck( $roles, 'name' );
$title = '<strong class="sp-staff-role">' . implode( '<span class="sp-staff-role-delimiter">/</span>', $roles ) . '</strong> ' . $title;
endif; endif;
endif; endif;
endif; endif;

View File

@@ -36,12 +36,13 @@ extract( $defaults, EXTR_SKIP );
$staff = new SP_Staff( $staff_id ); $staff = new SP_Staff( $staff_id );
$role = $staff->role(); $roles = $staff->roles();
if ( ! empty( $roles ) ):
if ( $role ) $roles = wp_list_pluck( $roles, 'name' );
echo $role->name; echo implode( '<span class="sp-staff-role-delimiter">/</span>', $roles );
else else:
_e( 'Staff', 'sportspress' ); _e( 'Staff', 'sportspress' );
endif;
echo ': '; echo ': ';

View File

@@ -20,10 +20,12 @@ foreach ( $members as $staff ):
$name = $staff->post_title; $name = $staff->post_title;
$staff = new SP_Staff( $id ); $staff = new SP_Staff( $id );
$role = $staff->role(); $roles = $staff->roles();
if ( $role ) if ( ! empty( $roles ) ):
$name = '<span class="sp-staff-role">' . $role->name . '</span> ' . $name; $roles = wp_list_pluck( $roles, 'name' );
$name = '<span class="sp-staff-role">' . implode( '<span class="sp-staff-role-delimiter">/</span>', $roles ) . '</span> ' . $name;
endif;
?> ?>
<h4 class="sp-staff-name"><?php echo $name; ?></h4> <h4 class="sp-staff-name"><?php echo $name; ?></h4>
<?php <?php