Allow multiple staff roles and display with delimiter
This commit is contained in:
@@ -217,6 +217,11 @@
|
||||
max-height: 2em;
|
||||
}
|
||||
|
||||
/* Staff */
|
||||
.sp-staff-role-delimiter {
|
||||
margin: 0 0.125em;
|
||||
}
|
||||
|
||||
/* Button */
|
||||
.sp-button {
|
||||
border: none;
|
||||
|
||||
@@ -49,31 +49,26 @@ class SP_Meta_Box_Staff_Details {
|
||||
endif;
|
||||
|
||||
$roles = get_the_terms( $post->ID, 'sp_role' );
|
||||
if ( $roles ):
|
||||
$term = array_shift( $roles );
|
||||
$role = $term->term_id;
|
||||
else:
|
||||
$role = null;
|
||||
endif;
|
||||
$role_ids = wp_list_pluck( $roles, 'term_id' );
|
||||
|
||||
$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( 'Job', 'sportspress' ); ?></strong></p>
|
||||
<p><strong><?php _e( 'Jobs', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_role',
|
||||
'name' => 'sp_role',
|
||||
'selected' => $role,
|
||||
'name' => 'tax_input[sp_role][]',
|
||||
'selected' => $role_ids,
|
||||
'values' => 'term_id',
|
||||
'show_option_blank' => true,
|
||||
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Job', 'sportspress' ) ),
|
||||
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Jobs', 'sportspress' ) ),
|
||||
'class' => 'widefat',
|
||||
'property' => 'multiple',
|
||||
'chosen' => true,
|
||||
);
|
||||
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;
|
||||
?></p>
|
||||
|
||||
@@ -155,8 +150,6 @@ class SP_Meta_Box_Staff_Details {
|
||||
* Save meta box data
|
||||
*/
|
||||
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_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() ) );
|
||||
|
||||
@@ -56,4 +56,19 @@ class SP_Staff extends SP_Custom_Post {
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,9 +44,10 @@ function sportspress_the_title( $title, $id = null ) {
|
||||
endif;
|
||||
elseif ( is_singular( 'sp_staff' ) ):
|
||||
$staff = new SP_Staff( $id );
|
||||
$role = $staff->role();
|
||||
if ( $role ):
|
||||
$title = '<strong class="sp-staff-role">' . $role->name . '</strong> ' . $title;
|
||||
$roles = $staff->roles();
|
||||
if ( ! empty( $roles ) ):
|
||||
$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;
|
||||
|
||||
@@ -36,12 +36,13 @@ extract( $defaults, EXTR_SKIP );
|
||||
|
||||
$staff = new SP_Staff( $staff_id );
|
||||
|
||||
$role = $staff->role();
|
||||
|
||||
if ( $role )
|
||||
echo $role->name;
|
||||
else
|
||||
$roles = $staff->roles();
|
||||
if ( ! empty( $roles ) ):
|
||||
$roles = wp_list_pluck( $roles, 'name' );
|
||||
echo implode( '<span class="sp-staff-role-delimiter">/</span>', $roles );
|
||||
else:
|
||||
_e( 'Staff', 'sportspress' );
|
||||
endif;
|
||||
|
||||
echo ': ';
|
||||
|
||||
|
||||
@@ -20,10 +20,12 @@ foreach ( $members as $staff ):
|
||||
$name = $staff->post_title;
|
||||
|
||||
$staff = new SP_Staff( $id );
|
||||
$role = $staff->role();
|
||||
|
||||
if ( $role )
|
||||
$name = '<span class="sp-staff-role">' . $role->name . '</span> ' . $name;
|
||||
$roles = $staff->roles();
|
||||
|
||||
if ( ! empty( $roles ) ):
|
||||
$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>
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user