From dc3e152eadb53d0e065475964c5737f86e72c51b Mon Sep 17 00:00:00 2001
From: Rob Tucker
Date: Sun, 11 Jun 2017 13:13:12 +0000
Subject: [PATCH] Addition of managing officials
Added incorrectly missing includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php
---
includes/admin/class-sp-admin-menus.php | 18 +++++-
.../post-types/class-sp-admin-meta-boxes.php | 7 +++
.../class-sp-meta-box-event-mode.php | 2 +-
.../class-sp-meta-box-event-officials.php | 61 +++++++++++++++++++
.../class-sp-meta-box-player-details.php | 33 +++++-----
.../class-sp-meta-box-team-details.php | 2 +-
includes/class-sp-post-types.php | 37 +++++++++++
templates/event-results.php | 35 ++++++++++-
8 files changed, 176 insertions(+), 19 deletions(-)
create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php
diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php
index 926b036d..d9fbb74a 100755
--- a/includes/admin/class-sp-admin-menus.php
+++ b/includes/admin/class-sp-admin-menus.php
@@ -26,6 +26,7 @@ class SP_Admin_Menus {
add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 );
+ add_action( 'admin_menu', array( $this, 'officials_menu' ), 22 );
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
add_action( 'admin_head', array( $this, 'menu_rename' ) );
@@ -68,6 +69,13 @@ class SP_Admin_Menus {
add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season');
}
+ /**
+ * Add menu item
+ */
+ public function officials_menu() {
+ add_submenu_page( 'sportspress', __( 'Officials', 'sportspress' ), __( 'Officials', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_officials');
+ }
+
/**
* Highlights the correct top level admin menu item for post type add screens.
*
@@ -130,6 +138,7 @@ class SP_Admin_Menus {
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
+ $sportspress_official = array_search( 'edit.php?post_type=sp_official', $menu_order );
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ):
@@ -141,11 +150,13 @@ class SP_Admin_Menus {
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
+ $sportspress_menu_order[] = 'edit.php?post_type=sp_official';
unset( $menu_order[ $sportspress_separator ] );
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
+ unset( $menu_order[ $sportspress_official ] );
// Apply to added menu items
$menu_items = apply_filters( 'sportspress_menu_items', array() );
@@ -217,6 +228,11 @@ class SP_Admin_Menus {
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
endif;
+ if ( isset( $submenu['edit.php?post_type=sp_official'] ) ):
+ $submenu['edit.php?post_type=sp_official'] = array_filter( $submenu['edit.php?post_type=sp_official'], array( $this, 'remove_leagues' ) );
+ $submenu['edit.php?post_type=sp_official'] = array_filter( $submenu['edit.php?post_type=sp_official'], array( $this, 'remove_seasons' ) );
+ endif;
+
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
@@ -281,4 +297,4 @@ class SP_Admin_Menus {
endif;
-return new SP_Admin_Menus();
\ No newline at end of file
+return new SP_Admin_Menus();
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 dfeefc14..d33dde37 100644
--- a/includes/admin/post-types/class-sp-admin-meta-boxes.php
+++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php
@@ -130,6 +130,13 @@ class SP_Admin_Meta_Boxes {
'context' => 'side',
'priority' => 'default',
),
+ 'officials' => array(
+ 'title' => __( 'Officials', 'sportspress' ),
+ 'save' => 'SP_Meta_Box_Event_Officials::save',
+ 'output' => 'SP_Meta_Box_Event_Officials::output',
+ 'context' => 'side',
+ 'priority' => 'default',
+ ),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Details::save',
diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php
index 947f23b9..7e9f569c 100644
--- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php
+++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-mode.php
@@ -35,4 +35,4 @@ class SP_Meta_Box_Event_Mode {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team' ) );
}
-}
\ No newline at end of file
+}
diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php
new file mode 100644
index 00000000..956ac305
--- /dev/null
+++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php
@@ -0,0 +1,61 @@
+
+ * @category Admin
+ * @package SportsPress/Admin/Meta_Boxes
+ * @version 2.3
+ */
+
+if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
+
+/**
+ * SP_Meta_Box_Event_Officials
+ */
+class SP_Meta_Box_Event_Officials {
+
+ /**
+ * Output the metabox
+ */
+ public static function output( $post ) {
+ wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
+ $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
+ $redirect = get_post_meta( $post->ID, 'sp_redirect', true );
+ $url = get_post_meta( $post->ID, 'sp_url', true );
+ if ( taxonomy_exists( 'sp_officials' ) ):
+ $officials = get_the_terms( $post->ID, 'sp_officials' );
+ $official_ids = array();
+ if ( $officials ):
+ foreach ( $officials as $official ):
+ $official_ids[] = $official->term_id;
+ endforeach;
+ endif;
+ endif;
+ ?>
+
+
+ 'sp_officials',
+ 'name' => 'tax_input[sp_officials][]',
+ 'selected' => $official_ids,
+ 'values' => 'term_id',
+ 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ),
+ 'class' => 'widefat',
+ 'property' => 'multiple',
+ 'chosen' => true,
+ );
+ sp_dropdown_taxonomies( $args );
+ ?>
+
+ ID, 'sp_past_team', false ) );
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?>
+
+
+ 'sp_team',
+ 'name' => 'sp_current_team[]',
+ 'selected' => $current_teams,
+ 'values' => 'ID',
+ 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
+ 'class' => 'sp-current-teams widefat',
+ 'property' => 'multiple',
+ 'chosen' => true,
+ );
+ sp_dropdown_pages( $args );
+ ?>
+
+
@@ -99,20 +116,6 @@ class SP_Meta_Box_Player_Details {
?>
-
- 'sp_team',
- 'name' => 'sp_current_team[]',
- 'selected' => $current_teams,
- 'values' => 'ID',
- 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
- 'class' => 'sp-current-teams widefat',
- 'property' => 'multiple',
- 'chosen' => true,
- );
- sp_dropdown_pages( $args );
- ?>
__( 'Officials', 'sportspress' ),
+ 'singular_name' => __( 'Official', 'sportspress' ),
+ 'all_items' => __( 'All', 'sportspress' ),
+ 'edit_item' => __( 'Edit Official', 'sportspress' ),
+ 'view_item' => __( 'View', 'sportspress' ),
+ 'update_item' => __( 'Update', 'sportspress' ),
+ 'add_new_item' => __( 'Add New', 'sportspress' ),
+ 'new_item_name' => __( 'Name', 'sportspress' ),
+ 'parent_item' => __( 'Parent', 'sportspress' ),
+ 'parent_item_colon' => __( 'Parent:', 'sportspress' ),
+ 'search_items' => __( 'Search', 'sportspress' ),
+ 'not_found' => __( 'No results found.', 'sportspress' ),
+ );
+ $args = apply_filters( 'sportspress_register_taxonomy_role', array(
+ 'label' => __( 'Officials', 'sportspress' ),
+ 'labels' => $labels,
+ 'public' => true,
+ 'show_ui' => $show,
+ 'show_in_menu' => $show,
+ 'show_in_nav_menus' => false,
+ 'show_tagcloud' => false,
+ 'hierarchical' => true,
+ 'rewrite' => array( 'slug' => get_option( 'sportspress_official_slug', 'official' ) ),
+ 'show_in_rest' => true,
+ 'rest_controller_class' => 'SP_REST_Terms_Controller',
+ 'rest_base' => 'officials',
+ ) );
+ $object_types = apply_filters( 'sportspress_official_object_types', array( 'sp_officials' ) );
+ register_taxonomy( 'sp_officials', $object_types, $args );
+ foreach ( $object_types as $object_type ):
+ register_taxonomy_for_object_type( 'sp_official', $object_type );
+ endforeach;
+
+
+ endif;
if ( apply_filters( 'sportspress_has_roles', true ) ):
$labels = array(
'name' => __( 'Jobs', 'sportspress' ),
diff --git a/templates/event-results.php b/templates/event-results.php
index c15a4f8c..29919e7d 100644
--- a/templates/event-results.php
+++ b/templates/event-results.php
@@ -114,4 +114,37 @@ endif;
?>
-
\ No newline at end of file
+
+ID, 'sp_officials' );
+ $official_ids = array();
+ if ( $officials ):
+ foreach ( $officials as $official ):
+ $official_ids[] = $official->term_id;
+ endforeach;
+ endif;
+ if(sizeof($official_ids) > 0 ){
+?>
+ Umpires
+
+ ';
+ echo ' | ';
+ echo '
';
+ foreach($officials as $official) {
+ echo '';
+ echo '| ' . $official->name . ' | ';
+ echo '
';
+ $i++;
+ }
+ echo '';
+ echo '';
+ ?>
+
+
+
+