From 5f150971f18b1d0285d3fbcdaeb6298742a81f56 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sat, 18 Nov 2017 19:29:42 +1100 Subject: [PATCH] Add custom order to staff jobs --- includes/admin/class-sp-admin-taxonomies.php | 10 ++++++- includes/admin/sp-admin-functions.php | 3 +- includes/class-sp-staff.php | 30 ++++++++++++++++++-- includes/sp-template-hooks.php | 8 ++---- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/includes/admin/class-sp-admin-taxonomies.php b/includes/admin/class-sp-admin-taxonomies.php index c9bc766c..bf7387ff 100644 --- a/includes/admin/class-sp-admin-taxonomies.php +++ b/includes/admin/class-sp-admin-taxonomies.php @@ -39,11 +39,15 @@ class SP_Admin_Taxonomies { add_action( 'edited_sp_position', array( $this, 'save_fields' ), 10, 1 ); add_action( 'create_sp_position', array( $this, 'save_fields' ), 10, 1 ); + // Add job field + add_action( 'sp_role_edit_form_fields', array( $this, 'edit_taxonomy_fields' ), 10, 1 ); + add_action( 'edited_sp_role', array( $this, 'save_fields' ), 10, 1 ); + // Change league columns add_filter( 'manage_edit-sp_league_columns', array( $this, 'taxonomy_columns' ) ); add_filter( 'manage_sp_league_custom_column', array( $this, 'column_value' ), 10, 3 ); - // Change league columns + // Change season columns add_filter( 'manage_edit-sp_season_columns', array( $this, 'taxonomy_columns' ) ); add_filter( 'manage_sp_season_custom_column', array( $this, 'column_value' ), 10, 3 ); @@ -54,6 +58,10 @@ class SP_Admin_Taxonomies { // Change position columns add_filter( 'manage_edit-sp_position_columns', array( $this, 'position_columns' ) ); add_filter( 'manage_sp_position_custom_column', array( $this, 'column_value' ), 10, 3 ); + + // Change job columns + add_filter( 'manage_edit-sp_role_columns', array( $this, 'taxonomy_columns' ) ); + add_filter( 'manage_sp_role_custom_column', array( $this, 'column_value' ), 10, 3 ); } /** diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index b142cf44..3aa59831 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -53,6 +53,7 @@ function sp_get_screen_ids() { 'edit-sp_venue', 'edit-sp_league', 'edit-sp_season', - 'edit-sp_position', + 'edit-sp_position', + 'edit-sp_role', ) ); } diff --git a/includes/class-sp-staff.php b/includes/class-sp-staff.php index a0615f65..f7611ee8 100644 --- a/includes/class-sp-staff.php +++ b/includes/class-sp-staff.php @@ -49,7 +49,7 @@ class SP_Staff extends SP_Custom_Post { * @return array */ public function role() { - $roles = get_the_terms( $this->ID, 'sp_role' ); + $roles = $this->get_roles(); if ( $roles && ! is_wp_error( $roles ) ): return array_shift( $roles ); else: @@ -64,11 +64,37 @@ class SP_Staff extends SP_Custom_Post { * @return array */ public function roles() { - $roles = get_the_terms( $this->ID, 'sp_role' ); + $roles = $this->get_roles(); if ( $roles && ! is_wp_error( $roles ) ): return (array) $roles; else: return array(); endif; } + + public function get_roles() { + $roles = get_the_terms( $this->ID, 'sp_role' ); + + if ( ! is_array( $roles ) || ! sizeof( $roles ) ) return array(); + + $include = wp_list_pluck( $roles, 'term_id' ); + + return get_terms( array( + 'taxonomy' => 'sp_role', + 'hide_empty' => false, + 'orderby' => 'meta_value_num', + 'include' => $include, + 'meta_query' => array( + 'relation' => 'OR', + array( + 'key' => 'sp_order', + 'compare' => 'NOT EXISTS' + ), + array( + 'key' => 'sp_order', + 'compare' => 'EXISTS' + ), + ), + ) ); + } } diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index b0ff363f..b92c2bb1 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -44,11 +44,9 @@ function sportspress_the_title( $title, $id = null ) { endif; elseif ( is_singular( 'sp_staff' ) ): $staff = new SP_Staff( $id ); - $roles = $staff->roles(); - if ( ! empty( $roles ) ): - $roles = wp_list_pluck( $roles, 'name' ); - $title = '' . implode( '/', $roles ) . ' ' . $title; - endif; + $role = $staff->role(); + if ( $role ) + $title = '' . $role->name . ' ' . $title; endif; endif;