From 331634a65fd09c66bae4f67834bbfb45182956fa Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 29 Dec 2015 15:49:01 +1100 Subject: [PATCH] Add ability to display staff members in team page --- .../post-types/class-sp-admin-meta-boxes.php | 7 ++ .../class-sp-meta-box-team-staff.php | 116 ++++++++++++++++++ includes/class-sp-team.php | 34 +++++ includes/sp-template-functions.php | 13 ++ includes/sp-template-hooks.php | 2 + templates/team-staff.php | 32 +++++ 6 files changed, 204 insertions(+) create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-team-staff.php create mode 100644 templates/team-staff.php diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index a796e73c..6cce6da2 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -165,6 +165,13 @@ class SP_Admin_Meta_Boxes { 'context' => 'normal', 'priority' => 'low', ), + 'staff' => array( + 'title' => __( 'Staff', 'sportspress' ), + 'save' => 'SP_Meta_Box_Team_Staff::save', + 'output' => 'SP_Meta_Box_Team_Staff::output', + 'context' => 'normal', + 'priority' => 'high', + ), ), 'sp_player' => array( 'shortcode' => array( diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-staff.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-staff.php new file mode 100644 index 00000000..0f42b999 --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-staff.php @@ -0,0 +1,116 @@ +staff( true ); + self::table( $data, $checked ); + + else: + + printf( __( 'No results found.', 'sportspress' ) ); + + endif; + } + + /** + * Save meta box data + */ + public static function save( $post_id, $post ) { + sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) ); + } + + /** + * Admin edit table + */ + public static function table( $data = array(), $checked = array() ) { + ?> +
+ + + + + + + + + + + + 0 ): + $i = 0; + foreach ( $data as $staff ): + $role = get_post_meta( $staff->ID, 'sp_role', true ); + ?> + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ ID, $checked ) ); ?>> + + + post_title; ?> + + ID, 'sp_role' ) ? the_terms( $staff->ID, 'sp_role' ) : '—'; ?>ID, 'sp_league' ) ? the_terms( $staff->ID, 'sp_league' ) : '—'; ?>ID, 'sp_season' ) ? the_terms( $staff->ID, 'sp_season' ) : '—'; ?>
+ +
+ +
+
+ ID ) return null; + + $args = array( + 'post_type' => 'sp_staff', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'meta_key' => 'sp_team', + 'meta_value' => $this->ID, + ); + $members = get_posts( $args ); + + $checked = (array) get_post_meta( $this->ID, 'sp_staff' ); + + if ( $admin ): + return array( $members, $checked ); + else: + foreach ( $members as $key => $member ): + if ( ! in_array( $member->ID, $checked ) ): + unset( $members[ $key ] ); + endif; + endforeach; + return $members; + endif; + } + /** * Returns player lists * diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 62d825a3..e23b0f72 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -259,6 +259,19 @@ if ( ! function_exists( 'sportspress_output_team_details' ) ) { sp_get_template( 'team-details.php' ); } } +if ( ! function_exists( 'sportspress_output_team_staff' ) ) { + + /** + * Output the team staff. + * + * @access public + * @subpackage Team/Staff + * @return void + */ + function sportspress_output_team_staff() { + sp_get_template( 'team-staff.php' ); + } +} if ( ! function_exists( 'sportspress_output_team_tables' ) ) { /** diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index 9fd97eeb..e57054a1 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -72,11 +72,13 @@ add_action( 'sportspress_before_single_team', 'sportspress_output_post_excerpt', * * @see sportspress_output_team_link() * @see sportspress_output_team_details() + * @see sportspress_output_team_staff() * @see sportspress_output_team_lists() * @see sportspress_output_team_tables() */ add_action( 'sportspress_single_team_content', 'sportspress_output_team_link', 0 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_details', 10 ); +add_action( 'sportspress_single_team_content', 'sportspress_output_team_staff', 15 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_lists', 20 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_tables', 30 ); diff --git a/templates/team-staff.php b/templates/team-staff.php new file mode 100644 index 00000000..767ba247 --- /dev/null +++ b/templates/team-staff.php @@ -0,0 +1,32 @@ +staff(); + +foreach ( $members as $staff ): + $id = $staff->ID; + $name = $staff->post_title; + + $staff = new SP_Staff( $id ); + $role = $staff->role(); + + if ( $role ) + $name = '' . $role->name . ' ' . $name; + ?> +

+ $id ) ); + sp_get_template( 'staff-details.php', array( 'id' => $id ) ); +endforeach;