From d5098b0ef7fed68e27005d48f48c902be60963a3 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 14 Nov 2017 22:34:43 +1100 Subject: [PATCH] Allow multiple staff roles and display with delimiter --- assets/css/sportspress.css | 5 +++++ .../class-sp-meta-box-staff-details.php | 21 +++++++------------ includes/class-sp-staff.php | 15 +++++++++++++ includes/sp-template-hooks.php | 7 ++++--- templates/event-staff.php | 11 +++++----- templates/team-staff.php | 10 +++++---- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index eb1837b9..c8ba8c37 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -217,6 +217,11 @@ max-height: 2em; } +/* Staff */ +.sp-staff-role-delimiter { + margin: 0 0.125em; +} + /* Button */ .sp-button { border: none; 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 8829cdd9..a989fae0 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 @@ -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 ) ); ?> -

+

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

@@ -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() ) ); diff --git a/includes/class-sp-staff.php b/includes/class-sp-staff.php index 1489746d..daebd760 100644 --- a/includes/class-sp-staff.php +++ b/includes/class-sp-staff.php @@ -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; + } } diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index 91638bae..bdc70936 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -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 = '' . $role->name . ' ' . $title; + $roles = $staff->roles(); + if ( ! empty( $roles ) ): + $roles = wp_list_pluck( $roles, 'name' ); + $title = '' . implode( '/', $roles ) . ' ' . $title; endif; endif; endif; diff --git a/templates/event-staff.php b/templates/event-staff.php index 267b85d9..20b7c6ab 100644 --- a/templates/event-staff.php +++ b/templates/event-staff.php @@ -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( '/', $roles ); + else: _e( 'Staff', 'sportspress' ); + endif; echo ': '; diff --git a/templates/team-staff.php b/templates/team-staff.php index a9c31875..8d6bb096 100644 --- a/templates/team-staff.php +++ b/templates/team-staff.php @@ -20,10 +20,12 @@ foreach ( $members as $staff ): $name = $staff->post_title; $staff = new SP_Staff( $id ); - $role = $staff->role(); - - if ( $role ) - $name = '' . $role->name . ' ' . $name; + $roles = $staff->roles(); + + if ( ! empty( $roles ) ): + $roles = wp_list_pluck( $roles, 'name' ); + $name = '' . implode( '/', $roles ) . ' ' . $name; + endif; ?>