Refactor officials as custom post type

This commit is contained in:
Brian Miyaji
2017-11-01 16:44:28 +11:00
parent 80cdb3c228
commit 70dd825ba7
14 changed files with 1020 additions and 120 deletions

View File

@@ -194,6 +194,7 @@
#adminmenu #menu-posts-sp_team .menu-icon-sp_team div.wp-menu-image:before, #adminmenu #menu-posts-sp_team .menu-icon-sp_team div.wp-menu-image:before,
#adminmenu #menu-posts-sp_player .menu-icon-sp_player div.wp-menu-image:before, #adminmenu #menu-posts-sp_player .menu-icon-sp_player div.wp-menu-image:before,
#adminmenu #menu-posts-sp_staff .menu-icon-sp_staff div.wp-menu-image:before, #adminmenu #menu-posts-sp_staff .menu-icon-sp_staff div.wp-menu-image:before,
#adminmenu #menu-posts-sp_official .menu-icon-sp_official div.wp-menu-image:before,
#sp_formatdiv #post-formats-select .post-format-icon:before, #sp_formatdiv #post-formats-select .post-format-icon:before,
#sp_modediv #post-formats-select .post-format-icon:before { #sp_modediv #post-formats-select .post-format-icon:before {
font-family: sportspress, dashicons; font-family: sportspress, dashicons;

View File

@@ -26,7 +26,6 @@ class SP_Admin_Menus {
add_action( 'admin_menu', array( $this, 'config_menu' ), 7 ); add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 ); add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 ); 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_highlight' ) );
add_action( 'admin_head', array( $this, 'menu_rename' ) ); add_action( 'admin_head', array( $this, 'menu_rename' ) );
@@ -69,13 +68,6 @@ class SP_Admin_Menus {
add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season'); 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. * Highlights the correct top level admin menu item for post type add screens.
* *
@@ -228,11 +220,6 @@ class SP_Admin_Menus {
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) ); $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
endif; 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_roles = $current_user->roles;
$user_role = array_shift($user_roles); $user_role = array_shift($user_roles);

View File

@@ -0,0 +1,299 @@
<?php
/**
* Admin functions for the officials post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_CPT' ) )
include( 'class-sp-admin-cpt.php' );
if ( ! class_exists( 'SP_Admin_CPT_Official' ) ) :
/**
* SP_Admin_CPT_Official Class
*/
class SP_Admin_CPT_Official extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_official';
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Admin columns
add_filter( 'manage_edit-sp_official_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_official_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Quick edit
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_teams' ), 10, 2 );
add_action( 'save_post', array( $this, 'quick_save' ) );
// Bulk edit
add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit_teams' ), 10, 2 );
add_action( 'wp_ajax_save_bulk_edit_sp_official', array( $this, 'bulk_save' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change title boxes in admin.
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_official' )
return __( 'Name', 'sportspress' );
return $text;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => null,
'sp_duty' => __( 'Duties', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Name', 'sportspress' )
) );
return apply_filters( 'sportspress_official_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_duty':
echo get_the_terms( $post_id, 'sp_duty' ) ? the_terms( $post_id, 'sp_duty' ) : '&mdash;';
break;
case 'sp_team':
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
$past_teams = get_post_meta( $post_id, 'sp_past_team', false );
$current_teams = array_filter( $current_teams );
$past_teams = array_filter( $past_teams );
echo '<span class="hidden sp-official-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
if ( empty( $teams ) ):
echo '&mdash;';
else:
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
echo $team->post_title;
if ( in_array( $team_id, $current_teams ) ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif;
endforeach;
endif;
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_official' )
return;
if ( taxonomy_exists( 'sp_duty' ) ):
$selected = isset( $_REQUEST['sp_duty'] ) ? $_REQUEST['sp_duty'] : null;
$args = array(
'show_option_all' => __( 'Show all duties', 'sportspress' ),
'taxonomy' => 'sp_duty',
'name' => 'sp_duty',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
$selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_official' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = $_GET['team'];
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
/**
* Quick edit teams
*
* @param string $column_name
* @param string $post_type
*/
public function quick_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return;
if ( 'sp_team' !== $column_name ) return;
$teams = get_posts( array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
) );
if ( ! $teams ) return;
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
<input type="hidden" name="sp_current_team[]" value="0">
<ul class="cat-checklist">
<?php foreach ( $teams as $team ) { ?>
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_current_team[]"> <?php echo $team->post_title; ?></label></li>
<?php } ?>
</ul>
<span class="title inline-edit-categories-label"><?php _e( 'Past Teams', 'sportspress' ); ?></span>
<input type="hidden" name="sp_past_team[]" value="0">
<ul class="cat-checklist">
<?php foreach ( $teams as $team ) { ?>
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_past_team[]"> <?php echo $team->post_title; ?></label></li>
<?php } ?>
</ul>
</div>
</fieldset>
<?php
}
/**
* Save quick edit boxes
*
* @param int $post_id
*/
public function quick_save( $post_id ) {
if ( empty( $_POST ) ) return $post_id;
if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id;;
$_POST += array( "{$this->type}_edit_nonce" => '' );
if ( ! wp_verify_nonce( $_POST["{$this->type}_edit_nonce"], plugin_basename( __FILE__ ) ) ) return $post_id;;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) return $post_id;
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() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
/**
* Bulk edit teams
*
* @param string $column_name
* @param string $post_type
*/
public function bulk_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return;
if ( 'sp_team' !== $column_name ) return;
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_official_edit_nonce' );
}
$teams = get_posts( array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
) );
if ( ! $teams ) return;
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
<input type="hidden" name="sp_current_team[]" value="0">
<ul class="cat-checklist">
<?php foreach ( $teams as $team ) { ?>
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_current_team[]"> <?php echo $team->post_title; ?></label></li>
<?php } ?>
</ul>
<span class="title inline-edit-categories-label"><?php _e( 'Past Teams', 'sportspress' ); ?></span>
<input type="hidden" name="sp_past_team[]" value="0">
<ul class="cat-checklist">
<?php foreach ( $teams as $team ) { ?>
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_past_team[]"> <?php echo $team->post_title; ?></label></li>
<?php } ?>
</ul>
</div>
</fieldset>
<?php
}
/**
* Save bulk edit boxes
*/
public function bulk_save() {
$_POST += array( "nonce" => '' );
if ( ! wp_verify_nonce( $_POST["nonce"], plugin_basename( __FILE__ ) ) ) return;
$post_ids = ( ! empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array();
$current_teams = sp_array_value( $_POST, 'current_teams', array() );
$past_teams = sp_array_value( $_POST, 'past_teams', array() );
$teams = array_merge( $current_teams, $past_teams );
if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
if ( ! current_user_can( 'edit_post', $post_id ) ) continue;
sp_add_post_meta_recursive( $post_id, 'sp_current_team', $current_teams );
sp_add_post_meta_recursive( $post_id, 'sp_past_team', $past_teams );
sp_add_post_meta_recursive( $post_id, 'sp_team', $teams );
}
}
die();
}
}
endif;
return new SP_Admin_CPT_Official();

View File

@@ -2,10 +2,11 @@
/** /**
* Event Officials * Event Officials
* *
* @author Rob Tucker <rtucker-scs> * @author Rob Tucker <rtucker-scs>
* @category Admin * @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.3 * @version 2.5
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -19,43 +20,37 @@ class SP_Meta_Box_Event_Officials {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); $duties = get_terms( array(
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); 'taxonomy' => 'sp_duty',
$redirect = get_post_meta( $post->ID, 'sp_redirect', true ); 'hide_empty' => false,
$url = get_post_meta( $post->ID, 'sp_url', true ); ) );
if ( taxonomy_exists( 'sp_officials' ) ):
$officials = get_the_terms( $post->ID, 'sp_officials' ); $officials = (array) get_post_meta( $post->ID, 'sp_officials', true );
$official_ids = array();
if ( $officials ): foreach ( $duties as $duty ) {
foreach ( $officials as $official ): ?>
$official_ids[] = $official->term_id; <p><strong><?php echo $duty->name; ?></strong></p>
endforeach; <p><?php
endif; $args = array(
endif; 'post_type' => 'sp_official',
?> 'name' => 'sp_officials[' . $duty->term_id . '][]',
<?php if ( taxonomy_exists( 'sp_officials' ) ) { ?> 'selected' => sp_array_value( $officials, $duty->term_id, array() ),
<p><strong><?php _e( 'Officials', 'sportspress' ); ?></strong></p> 'values' => 'ID',
<p><?php 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ),
$args = array( 'class' => 'widefat',
'taxonomy' => 'sp_officials', 'property' => 'multiple',
'name' => 'tax_input[sp_officials][]', 'chosen' => true,
'selected' => $official_ids, );
'values' => 'term_id', sp_dropdown_pages( $args );
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ), ?></p>
'class' => 'widefat', <?php
'property' => 'multiple', }
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<?php } ?>
<?php
} }
/** /**
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', 'official' ) ); update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', array() ) );
} }
} }

View File

@@ -0,0 +1,120 @@
<?php
/**
* Official Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Official_Details
*/
class SP_Meta_Box_Official_Details {
/**
* Output the metabox
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$continents = SP()->countries->continents;
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
foreach ( $nationalities as $index => $nationality ):
if ( 2 == strlen( $nationality ) ):
$legacy = SP()->countries->legacy;
$nationality = strtolower( $nationality );
$nationality = sp_array_value( $legacy, $nationality, null );
$nationalities[ $index ] = $nationality;
endif;
endforeach;
if ( taxonomy_exists( 'sp_duty' ) ):
$positions = get_the_terms( $post->ID, 'sp_duty' );
$position_ids = array();
if ( $positions ):
foreach ( $positions as $position ):
$position_ids[] = $position->term_id;
endforeach;
endif;
endif;
$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( 'Nationality', 'sportspress' ); ?></strong></p>
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<optgroup label="<?php echo $continent; ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo $code; ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo $country; ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select></p>
<?php if ( taxonomy_exists( 'sp_duty' ) ) { ?>
<p><strong><?php _e( 'Duties', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_duty',
'name' => 'tax_input[sp_duty][]',
'selected' => $position_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Duties', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<?php } ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => '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 );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
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() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
}

View File

@@ -255,7 +255,7 @@ class SP_Settings_Modules extends SP_Settings_Page {
</td></tr> </td></tr>
<?php } else { ?> <?php } else { ?>
<tr><td> <tr><td>
<input type="checkbox" name="sportspress_load_<?php echo $id; ?>_module" id="sportspress_load_<?php echo $id; ?>_module" <?php checked( 'yes' == get_option( 'sportspress_load_' . $id . '_module', 'yes' ) ); ?>> <input type="checkbox" name="sportspress_load_<?php echo $id; ?>_module" id="sportspress_load_<?php echo $id; ?>_module" <?php checked( 'yes' == get_option( 'sportspress_load_' . $id . '_module', sp_array_value( $module, 'default', 'yes' ) ) ); ?>>
<label for="sportspress_load_<?php echo $id; ?>_module"> <label for="sportspress_load_<?php echo $id; ?>_module">
<i class="<?php echo sp_array_value( $module, 'icon', 'dashicons dashicons-admin-generic' ); ?>"></i> <i class="<?php echo sp_array_value( $module, 'icon', 'dashicons dashicons-admin-generic' ); ?>"></i>
<?php echo sp_array_value( $module, 'label', $id ); ?> <?php echo sp_array_value( $module, 'label', $id ); ?>

View File

@@ -106,6 +106,12 @@ class SP_Modules {
'link' => 'https://www.themeboy.com/sportspress-extensions/directories/', 'link' => 'https://www.themeboy.com/sportspress-extensions/directories/',
'desc' => __( 'Organize and display staff in list and gallery layouts.', 'sportspress' ), 'desc' => __( 'Organize and display staff in list and gallery layouts.', 'sportspress' ),
), ),
'officials' => array(
'label' => __( 'Officials', 'sportspress' ),
'icon' => 'sp-icon-whistle',
'desc' => __( 'Manage referees, umpires, judges, timekeepers, and other officials.', 'sportspress' ),
'default' => 'no',
),
), ),
'admin' => array( 'admin' => array(
'tutorials' => array( 'tutorials' => array(

View File

@@ -178,43 +178,6 @@ class SP_Post_types {
endforeach; endforeach;
endif; endif;
if ( apply_filters( 'sportspress_has_officials', true ) ):
$labels = array(
'name' => __( '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 ) ): if ( apply_filters( 'sportspress_has_roles', true ) ):
$labels = array( $labels = array(
'name' => __( 'Jobs', 'sportspress' ), 'name' => __( 'Jobs', 'sportspress' ),

View File

@@ -202,6 +202,19 @@ if ( ! function_exists( 'sportspress_output_event_performance' ) ) {
sp_get_template( 'event-performance.php' ); sp_get_template( 'event-performance.php' );
} }
} }
if ( ! function_exists( 'sportspress_output_event_officials' ) ) {
/**
* Output the event officials.
*
* @access public
* @subpackage Event/Officials
* @return void
*/
function sportspress_output_event_officials() {
sp_get_template( 'event-officials.php' );
}
}
/** Single Calendar ********************************************************/ /** Single Calendar ********************************************************/

View File

@@ -60,7 +60,7 @@ class SportsPress_Birthdays {
global $typenow; global $typenow;
if ( 'default' == $domain && in_array( $typenow, array( 'sp_player', 'sp_staff' ) ) ): if ( 'default' == $domain && in_array( $typenow, array( 'sp_player', 'sp_staff', 'sp_official' ) ) ):
switch ( $untranslated_text ): switch ( $untranslated_text ):
case 'Scheduled for: <b>%1$s</b>': case 'Scheduled for: <b>%1$s</b>':
case 'Published on: <b>%1$s</b>': case 'Published on: <b>%1$s</b>':

View File

@@ -0,0 +1,342 @@
<?php
/*
Plugin Name: SportsPress Officials
Plugin URI: http://themeboy.com/
Description: Add officials to SportsPress.
Author: ThemeBoy
Author URI: http://themeboy.com/
Version: 2.5
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'SportsPress_Officials' ) ) :
/**
* Main SportsPress Officials Class
*
* @class SportsPress_Officials
* @version 2.5
*/
class SportsPress_Officials {
/**
* Constructor
*/
public function __construct() {
// Define constants
$this->define_constants();
// Actions
add_action( 'sportspress_after_register_taxonomy', array( $this, 'register_taxonomy' ) );
add_action( 'sportspress_after_register_post_type', array( $this, 'register_post_type' ) );
add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) );
add_action( 'sportspress_create_rest_routes', array( $this, 'create_rest_routes' ) );
add_action( 'sportspress_register_rest_fields', array( $this, 'register_rest_fields' ) );
// Filters
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_filter( 'sportspress_after_event_template', array( $this, 'add_event_template' ), 30 );
add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) );
add_filter( 'sportspress_post_types', array( $this, 'add_post_type' ) );
add_filter( 'sportspress_primary_post_types', array( $this, 'add_post_type' ) );
add_filter( 'sportspress_post_type_hierarchy', array( $this, 'add_to_hierarchy' ) );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_OFFICIALS_VERSION' ) )
define( 'SP_OFFICIALS_VERSION', '2.5' );
if ( !defined( 'SP_OFFICIALS_URL' ) )
define( 'SP_OFFICIALS_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_OFFICIALS_DIR' ) )
define( 'SP_OFFICIALS_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Register officials taxonomy
*/
public static function register_taxonomy() {
$labels = array(
'name' => __( 'Duties', 'sportspress' ),
'singular_name' => __( 'Duty', 'sportspress' ),
'all_items' => __( 'All', 'sportspress' ),
'edit_item' => __( 'Edit Duty', '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_duty', array(
'label' => __( 'Duties', 'sportspress' ),
'labels' => $labels,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => get_option( 'sportspress_duty_slug', 'duty' ) ),
'show_in_rest' => true,
'rest_controller_class' => 'SP_REST_Terms_Controller',
'rest_base' => 'duties',
) );
$object_types = apply_filters( 'sportspress_duty_object_types', array( 'sp_official' ) );
register_taxonomy( 'sp_duty', $object_types, $args );
foreach ( $object_types as $object_type ):
register_taxonomy_for_object_type( 'sp_duty', $object_type );
endforeach;
}
/**
* Register officials post type
*/
public static function register_post_type() {
register_post_type( 'sp_official',
apply_filters( 'sportspress_register_post_type_official',
array(
'labels' => array(
'name' => __( 'Officials', 'sportspress' ),
'singular_name' => __( 'Official', 'sportspress' ),
'add_new_item' => __( 'Add New Official', 'sportspress' ),
'edit_item' => __( 'Edit Official', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
'view_item' => __( 'View Official', 'sportspress' ),
'search_items' => __( 'Search', 'sportspress' ),
'not_found' => __( 'No results found.', 'sportspress' ),
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
'featured_image' => __( 'Photo', 'sportspress' ),
'set_featured_image' => __( 'Select Photo', 'sportspress' ),
'remove_featured_image' => __( 'Remove Photo', 'sportspress' ),
'use_featured_image' => __( 'Select Photo', 'sportspress' ),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'sp_staff',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'rewrite' => array( 'slug' => get_option( 'sportspress_official_slug', 'official' ) ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'menu_icon' => 'dashicons-flag',
'show_in_rest' => true,
'rest_controller_class' => 'SP_REST_Posts_Controller',
'rest_base' => 'officials',
)
)
);
}
/**
* Remove meta boxes.
*/
public function remove_meta_boxes() {
remove_meta_box( 'sp_dutydiv', 'sp_official', 'side' );
}
/**
* Conditonally load the class and functions only needed when viewing this post type.
*/
public function include_post_type_handler() {
include_once( SP()->plugin_path() . '/includes/admin/post-types/class-sp-admin-cpt-official.php' );
}
/**
* Create REST API routes.
*/
public function create_rest_routes() {
$controller = new SP_REST_Posts_Controller( 'sp_official' );
$controller->register_routes();
}
/**
* Register REST API fields.
*/
public function register_rest_fields() {
register_rest_field( 'sp_official',
'data',
array(
'get_callback' => 'SP_REST_API::get_post_data',
'update_callback' => 'SP_REST_API::update_post_meta_arrays',
'schema' => array(
'description' => __( 'Official', 'sportspress' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'arg_options' => array(
'sanitize_callback' => 'rest_sanitize_request_arg',
),
),
)
);
}
/**
* Add meta boxes.
*
* @return array
*/
public function add_meta_boxes( $meta_boxes ) {
$meta_boxes['sp_event']['officials'] = array(
'title' => __( 'Officials', 'sportspress' ),
'output' => 'SP_Meta_Box_Event_Officials::output',
'save' => 'SP_Meta_Box_Event_Officials::save',
'context' => 'side',
'priority' => 'default',
);
$meta_boxes['sp_official'] = array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Official_Details::save',
'output' => 'SP_Meta_Box_Official_Details::output',
'context' => 'side',
'priority' => 'default',
),
);
return $meta_boxes;
}
/**
* Add settings.
*
* @return array
*/
public function add_settings( $settings ) {
return array_merge( $settings,
array(
array( 'title' => __( 'Officials', 'sportspress' ), 'type' => 'title', 'id' => 'table_options' ),
),
apply_filters( 'sportspress_table_options', array(
array(
'title' => __( 'Duty', 'sportspress' ),
'desc' => __( 'Display title', 'sportspress' ),
'id' => 'sportspress_table_show_title',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Teams', 'sportspress' ),
'desc' => __( 'Display logos', 'sportspress' ),
'id' => 'sportspress_table_show_logos',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Pagination', 'sportspress' ),
'desc' => __( 'Paginate', 'sportspress' ),
'id' => 'sportspress_table_paginated',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Limit', 'sportspress' ),
'id' => 'sportspress_table_rows',
'class' => 'small-text',
'default' => '10',
'desc' => __( 'teams', 'sportspress' ),
'type' => 'number',
'custom_attributes' => array(
'min' => 1,
'step' => 1
),
),
array(
'title' => __( 'Form', 'sportspress' ),
'id' => 'sportspress_form_limit',
'class' => 'small-text',
'default' => '5',
'desc' => __( 'events', 'sportspress' ),
'type' => 'number',
'custom_attributes' => array(
'min' => 1,
'step' => 1
),
),
array(
'title' => __( 'Pos', 'sportspress' ),
'desc' => __( 'Always increment', 'sportspress' ),
'id' => 'sportspress_table_increment',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Tiebreaker', 'sportspress' ),
'id' => 'sportspress_table_tiebreaker',
'default' => 'none',
'type' => 'select',
'options' => array(
'none' => __( 'None', 'sportspress' ),
'h2h' => __( 'Head to head', 'sportspress' ),
),
),
) ),
array(
array( 'type' => 'sectionend', 'id' => 'table_options' ),
)
);
}
/**
* Add event template.
*
* @return array
*/
public function add_event_template( $templates ) {
return array_merge( $templates, array(
'officials' => array(
'title' => __( 'Officials', 'sportspress' ),
'option' => 'sportspress_event_show_officials',
'action' => 'sportspress_output_event_officials',
'default' => 'yes',
),
) );
}
/**
* Add screen ids.
*
* @return array
*/
public function screen_ids( $ids ) {
return array_merge( $ids, array(
'sp_official',
'edit-sp_official',
) );
}
public static function add_post_type( $post_types = array() ) {
$post_types[] = 'sp_official';
return $post_types;
}
public static function add_to_hierarchy( $hierarchy = array() ) {
$hierarchy['sp_official'] = array();
return $hierarchy;
}
}
endif;
if ( get_option( 'sportspress_load_officials_module', 'no' ) == 'yes' ) {
new SportsPress_Officials();
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Event Officials
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$officials = (array) get_post_meta( $id, 'sp_officials', true );
$officials = array_filter( $officials );
if ( empty( $officials ) ) return;
$duties = get_terms( array(
'taxonomy' => 'sp_duty',
'hide_empty' => false,
) );
if ( empty( $duties ) ) return;
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
$link_officials = get_option( 'sportspress_link_officials', 'no' ) == 'yes' ? true : false;
$rows = '';
$i = 0;
foreach ( $duties as $duty ) {
$officials_on_duty = sp_array_value( $officials, $duty->term_id, array() );
if ( empty( $officials_on_duty ) ) continue;
foreach ( $officials_on_duty as $official ) {
$rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$name = get_the_title( $official );
if ( $link_officials && sp_post_exists( $official ) ) {
$name = '<a href="' . get_post_permalink( $official ) . '">' . $name . '</a>';
}
$rows .= '<th class="data-name">' . $name . '</th>';
$rows .= '<td class="data-duty">' . $duty->name . '</td>';
$rows .= '</tr>';
$i++;
}
}
if ( empty( $rows ) ) return;
?>
<div class="sp-template sp-template-event-officials">
<h4 class="sp-table-caption"><?php _e( 'Officials', 'sportspress' ); ?></h4>
<div class="sp-table-wrapper">
<table class="sp-event-officials sp-data-table<?php echo $scrollable ? ' sp-scrollable-table' : ''; ?>">
<tbody>
<?php echo $rows; ?>
</tbody>
</table>
</div>
</div>

View File

@@ -115,36 +115,3 @@ endif;
<div class="sp-template sp-template-event-results"> <div class="sp-template sp-template-event-results">
<?php echo $output; ?> <?php echo $output; ?>
</div> </div>
<?php
$officials = get_the_terms( $post->ID, 'sp_officials' );
$official_ids = array();
if ( $officials ):
foreach ( $officials as $official ):
$official_ids[] = $official->term_id;
endforeach;
endif;
if(sizeof($official_ids) > 0 ){
?>
<h4 class="sp-table-caption">Umpires</h4>
<div class="sp-template sp-template-event-results">
<?php
$i=0;
echo '<table class="sp-event-results sp-data-table sp-scrollable-table">';
echo '<thead><th class="data-name"></th></thead>';
echo '<tbody>';
foreach($officials as $official) {
echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
echo '<td class="data-name">' . $official->name . '</td>';
echo '</tr>';
$i++;
}
echo '</tbody>';
echo '</table>';
?>
</div>
<?php
}
?>
</div>

View File

@@ -0,0 +1,137 @@
<?php
/**
* Official Details
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( get_option( 'sportspress_official_show_details', 'yes' ) === 'no' ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
$defaults = array(
'show_number' => get_option( 'sportspress_official_show_number', 'no' ) == 'yes' ? true : false,
'show_name' => get_option( 'sportspress_official_show_name', 'no' ) == 'yes' ? true : false,
'show_nationality' => get_option( 'sportspress_official_show_nationality', 'yes' ) == 'yes' ? true : false,
'show_positions' => get_option( 'sportspress_official_show_positions', 'yes' ) == 'yes' ? true : false,
'show_current_teams' => get_option( 'sportspress_official_show_current_teams', 'yes' ) == 'yes' ? true : false,
'show_past_teams' => get_option( 'sportspress_official_show_past_teams', 'yes' ) == 'yes' ? true : false,
'show_leagues' => get_option( 'sportspress_official_show_leagues', 'no' ) == 'yes' ? true : false,
'show_seasons' => get_option( 'sportspress_official_show_seasons', 'no' ) == 'yes' ? true : false,
'show_nationality_flags' => get_option( 'sportspress_official_show_flags', 'yes' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
$countries = SP()->countries->countries;
$official = new SP_Official( $id );
$metrics_before = $official->metrics( true );
$metrics_after = $official->metrics( false );
$common = array();
if ( $show_number ):
$common[ '#' ] = $official->number;
endif;
if ( $show_name ):
$common[ __( 'Name', 'sportspress' ) ] = $official->post->post_title;
endif;
if ( $show_nationality ):
$nationalities = $official->nationalities();
if ( $nationalities && is_array( $nationalities ) ):
$values = array();
foreach ( $nationalities as $nationality ):
$country_name = sp_array_value( $countries, $nationality, null );
$values[] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '&mdash;';
endforeach;
$common[ __( 'Nationality', 'sportspress' ) ] = implode( '<br>', $values );
endif;
endif;
if ( $show_positions ):
$positions = $official->positions();
if ( $positions && is_array( $positions ) ):
$position_names = array();
foreach ( $positions as $position ):
$position_names[] = $position->name;
endforeach;
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
endif;
endif;
$data = array_merge( $metrics_before, $common, $metrics_after );
if ( $show_current_teams ):
$current_teams = $official->current_teams();
if ( $current_teams ):
$teams = array();
foreach ( $current_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
$data[ __( 'Current Team', 'sportspress' ) ] = implode( ', ', $teams );
endif;
endif;
if ( $show_past_teams ):
$past_teams = $official->past_teams();
if ( $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
endif;
endif;
if ( $show_leagues ):
$leagues = $official->leagues();
if ( $leagues && ! is_wp_error( $leagues ) ):
$terms = array();
foreach ( $leagues as $league ) {
$terms[] = $league->name;
}
$data[ __( 'Competitions', 'sportspress' ) ] = implode( ', ', $terms );
endif;
endif;
if ( $show_seasons ):
$seasons = $official->seasons();
if ( $seasons && ! is_wp_error( $seasons ) ):
$terms = array();
foreach ( $seasons as $season ) {
$terms[] = $season->name;
}
$data[ __( 'Seasons', 'sportspress' ) ] = implode( ', ', $terms );
endif;
endif;
$data = apply_filters( 'sportspress_official_details', $data, $id );
if ( empty( $data ) )
return;
$output = '<div class="sp-template sp-template-official-details sp-template-details"><div class="sp-list-wrapper"><dl class="sp-official-details">';
foreach( $data as $label => $value ):
$output .= '<dt>' . $label . '</dt><dd>' . $value . '</dd>';
endforeach;
$output .= '</dl></div></div>';
echo $output;