Add option to choose individual/team mode per event

This commit is contained in:
Brian Miyaji
2017-03-16 13:49:51 +11:00
parent 6078dcd534
commit b6f79cec13
25 changed files with 253 additions and 326 deletions

View File

@@ -15,10 +15,15 @@
content: "\f328";
}
.post-state-format.post-format-player:before, .post-format-icon.post-format-player:before, a.post-state-format.format-player:before,
.post-state-format.post-format-roster:before, .post-format-icon.post-format-roster:before, a.post-state-format.format-roster:before {
content: "\f307";
}
.post-state-format.post-format-team:before, .post-format-icon.post-format-team:before, a.post-state-format.format-team:before {
content: "\f334";
}
.post-state-format.post-format-list:before, .post-format-icon.post-format-list:before, a.post-state-format.format-list:before {
content: "\f163";
}

View File

@@ -185,7 +185,8 @@
#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_staff .menu-icon-sp_staff 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 {
font-family: sportspress, dashicons;
width: 20px;
text-align: center;

View File

@@ -123,6 +123,13 @@ class SP_Admin_Meta_Boxes {
'context' => 'side',
'priority' => 'default',
),
'mode' => array(
'title' => __( 'Mode', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Mode::save',
'output' => 'SP_Meta_Box_Event_Mode::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Details::save',

View File

@@ -0,0 +1,38 @@
<?php
/**
* Event Mode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.2.11
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Event_Mode
*/
class SP_Meta_Box_Event_Mode {
/**
* Output the metabox
*/
public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID );
?>
<div id="post-formats-select">
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $mode; ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team' ) );
}
}

View File

@@ -53,17 +53,14 @@ class SP_Meta_Box_Event_Performance {
$positions = get_terms( 'sp_position', $args );
endif;
// Get status option
if ( 'yes' == get_option( 'sportspress_event_show_status', 'yes' ) )
$status = true;
else
$status = false;
// Apply filters to labels
$labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels );
// Check if individual mode
$is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false;
$is_individual = 'player' === sp_get_post_mode( $post->ID );
// Get status option
$status = ! $is_individual;
self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline, $timed );
}

View File

@@ -21,7 +21,8 @@ class SP_Meta_Box_Event_Teams {
public static function output( $post ) {
$limit = get_option( 'sportspress_event_teams', 2 );
$teams = (array) get_post_meta( $post->ID, 'sp_team', false );
if ( $limit ) {
$post_type = sp_get_post_mode_type( $post->ID );
if ( $limit && 'sp_player' !== $post_type ) {
for ( $i = 0; $i < $limit; $i ++ ):
$team = array_shift( $teams );
?>
@@ -29,7 +30,7 @@ class SP_Meta_Box_Event_Teams {
<p class="sp-tab-select sp-title-generator">
<?php
$args = array(
'post_type' => 'sp_team',
'post_type' => $post_type,
'name' => 'sp_team[]',
'class' => 'sportspress-pages',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
@@ -119,10 +120,10 @@ class SP_Meta_Box_Event_Teams {
endfor;
} else {
?>
<p><strong><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Teams', 'sportspress' ) ); ?></strong></p>
<p><strong><?php printf( __( 'Select %s:', 'sportspress' ), sp_get_post_mode_label( $post->ID ) ); ?></strong></p>
<?php
$args = array(
'post_type' => 'sp_team',
'post_type' => $post_type,
'name' => 'sp_team[]',
'selected' => $teams,
'values' => 'ID',
@@ -132,7 +133,7 @@ class SP_Meta_Box_Event_Teams {
'placeholder' => __( 'None', 'sportspress' ),
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
endif;
}
wp_nonce_field( 'sp-get-players', 'sp-get-players-nonce', false );
@@ -142,17 +143,30 @@ class SP_Meta_Box_Event_Teams {
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
$tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( -1 == $sections ) {
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
} else {
$players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) );
$teams = sp_array_value( $_POST, 'sp_team', array() );
sp_update_post_meta_recursive( $post_id, 'sp_team', $teams );
$post_type = sp_get_post_mode_type( $post->ID );
if ( 'sp_player' === $post_type ) {
$players = array();
foreach ( $teams as $player ) {
$players[] = array( 0, $player );
}
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
} else {
$tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( -1 == $sections ) {
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
} else {
$players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
}
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
}
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
}
}

View File

@@ -51,7 +51,7 @@ class SP_Meta_Box_List_Data {
<th><?php echo in_array( $orderby, array( 'number', 'name' ) ) ? '#' : __( 'Rank', 'sportspress' ); ?></th>
<?php } ?>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php if ( array_key_exists( 'team', $columns ) && apply_filters( 'sportspress_has_teams', true ) ) { ?>
<?php if ( array_key_exists( 'team', $columns ) ) { ?>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php } ?>
<?php if ( array_key_exists( 'position', $columns ) ) { ?>
@@ -103,7 +103,7 @@ class SP_Meta_Box_List_Data {
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
</span>
</td>
<?php if ( array_key_exists( 'team', $columns ) && apply_filters( 'sportspress_has_teams', true ) ) { ?>
<?php if ( array_key_exists( 'team', $columns ) ) { ?>
<td>
<?php
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );

View File

@@ -42,7 +42,6 @@ class SP_Meta_Box_List_Details {
sp_taxonomy_field( $taxonomy, $post, true );
}
?>
<?php if ( apply_filters( 'sportspress_list_team_selector', true ) ) { ?>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select sp-team-era-selector">
<?php
@@ -63,7 +62,6 @@ class SP_Meta_Box_List_Details {
<option value="past" <?php selected( 'past', $era ); ?>><?php _e( 'Past', 'sportspress' ); ?></option>
</select>
</p>
<?php } ?>
<p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_grouping">

View File

@@ -99,7 +99,6 @@ class SP_Meta_Box_Player_Details {
?></p>
<?php } ?>
<?php if ( apply_filters( 'sportspress_player_teams', true ) ) { ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
@@ -129,7 +128,6 @@ class SP_Meta_Box_Player_Details {
);
sp_dropdown_pages( $args );
?></p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_league' ) ) { ?>
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>

View File

@@ -89,7 +89,6 @@ class SP_Meta_Box_Staff_Details {
<?php endforeach; ?>
</select></p>
<?php if ( apply_filters( 'sportspress_staff_teams', true ) ) { ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
@@ -119,7 +118,6 @@ class SP_Meta_Box_Staff_Details {
);
sp_dropdown_pages( $args );
?></p>
<?php } ?>
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
<p><?php

View File

@@ -23,7 +23,7 @@ class SP_Meta_Box_Table_Data {
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $table->data( true );
$adjustments = $table->adjustments;
$highlight = get_post_meta( $table->ID, 'sp_highlight', true );
self::table( $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight );
self::table( $table->ID, $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight );
}
/**
@@ -39,10 +39,19 @@ class SP_Meta_Box_Table_Data {
/**
* Admin edit table
*/
public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) {
public static function table( $id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
$mode = sp_get_post_mode( $id );
if ( 'player' === $mode ) {
$show_team_logo = get_option( 'sportspress_list_show_photos', 'no' ) == 'yes' ? true : false;
$icon_class = 'sp-icon-tshirt';
} else {
$show_team_logo = get_option( 'sportspress_table_show_logos', 'no' ) == 'yes' ? true : false;
$icon_class = 'sp-icon-shield';
}
?>
<input type="hidden" name="sp_highlight" value="0">
<ul class="subsubsub sp-table-bar">
@@ -53,7 +62,7 @@ class SP_Meta_Box_Table_Data {
<table class="widefat sp-data-table sp-league-table">
<thead>
<tr>
<th class="radio"><span class="dashicons sp-icon-shield sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
<th class="radio"><span class="dashicons <?php echo $icon_class; ?> sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<th><label for="sp_columns_<?php echo $key; ?>">

View File

@@ -23,6 +23,7 @@ class SP_Meta_Box_Table_Details {
$taxonomies = get_object_taxonomies( 'sp_table' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$select = get_post_meta( $post->ID, 'sp_select', true );
$post_type = sp_get_post_mode_type( $post->ID );
if ( ! $select ) {
global $pagenow;
$select = ( 'post-new.php' ? 'auto' : 'manual' );
@@ -38,7 +39,7 @@ class SP_Meta_Box_Table_Details {
}
?>
<p><strong>
<?php _e( 'Teams', 'sportspress' ); ?>
<?php echo sp_get_post_mode_label( $post->ID ); ?>
</strong></p>
<p class="sp-select-setting">
<select name="sp_select">
@@ -48,8 +49,8 @@ class SP_Meta_Box_Table_Details {
</p>
<?php
if ( 'manual' == $select ) {
sp_post_checklist( $post->ID, 'sp_team', ( 'auto' == $select ? 'none' : 'block' ), array( 'sp_league', 'sp_season' ) );
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
sp_post_checklist( $post->ID, $post_type, ( 'auto' == $select ? 'none' : 'block' ), array( 'sp_league', 'sp_season' ), null, 'sp_team' );
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
}
?>
</div>

View File

@@ -0,0 +1,38 @@
<?php
/**
* League Table Mode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.2.11
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Table_Mode
*/
class SP_Meta_Box_Table_Mode {
/**
* Output the metabox
*/
public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID );
?>
<div id="post-formats-select">
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $mode; ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team' ) );
}
}

View File

@@ -27,7 +27,6 @@ class SP_Settings_Events extends SP_Settings_Page {
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_current_mode', array( $this, 'current_mode_setting' ) );
add_action( 'sportspress_admin_field_delimiter', array( $this, 'delimiter_setting' ) );
add_action( 'sportspress_admin_field_event_layout', array( $this, 'layout_setting' ) );
add_action( 'sportspress_admin_field_event_tabs', array( $this, 'tabs_setting' ) );
@@ -98,19 +97,17 @@ class SP_Settings_Events extends SP_Settings_Page {
array(
array(
'title' => __( 'Mode', 'sportspress' ),
'id' => 'sportspress_load_individual_mode_module',
'default' => 'no',
'title' => __( 'Default mode', 'sportspress' ),
'id' => 'sportspress_mode',
'default' => 'team',
'type' => 'radio',
'options' => array(
'no' => __( 'Team vs team', 'sportspress' ),
'yes' => __( 'Player vs player', 'sportspress' ),
'team' => __( 'Team vs team', 'sportspress' ),
'player' => __( 'Player vs player', 'sportspress' ),
),
'desc_tip' => _x( 'Who competes in events?', 'mode setting description', 'sportspress' ),
),
array( 'type' => 'current_mode' ),
array(
'title' => __( 'Limit', 'sportspress' ),
'id' => 'sportspress_event_teams',
@@ -476,21 +473,6 @@ class SP_Settings_Events extends SP_Settings_Page {
</tr>
<?php
}
/**
* Output script to refresh page when mode is changed.
*/
function current_mode_setting() {
?>
<input type="hidden" name="sportspress_individual_mode_module_loaded" value="<?php echo get_option( 'sportspress_load_individual_mode_module', 'no' ); ?>">
<?php if ( sp_array_value( $_POST, 'sportspress_load_individual_mode_module', 'no' ) !== sp_array_value( $_POST, 'sportspress_individual_mode_module_loaded', 'no' ) ) { ?>
<script type="text/javascript">
window.onload = function() {
window.location = window.location.href;
}
</script>
<?php }
}
}
endif;

View File

@@ -424,6 +424,13 @@ class SP_Install {
update_option( 'sportspress_completed_setup', 1 );
update_option( 'sportspress_registration_name_inputs', 'no' );
update_option( 'sportspress_registration_add_player', 'no' );
$individual_mode = get_option( 'sportspress_load_individual_mode_module', 'no' );
if ( 'yes' === $individual_mode ) {
update_option( 'sportspress_mode', 'player' );
} else {
update_option( 'sportspress_mode', 'team' );
}
}
}

View File

@@ -48,6 +48,9 @@ class SP_League_Table extends SP_Custom_Post{
// Get labels from outcome variables
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
// Get post type
$post_type = sp_get_post_mode_type( $this->ID );
// Determine if main loop
if ( $team_ids ) {
@@ -60,7 +63,7 @@ class SP_League_Table extends SP_Custom_Post{
$team_ids = array();
$args = array(
'post_type' => 'sp_team',
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'order' => 'ASC',

View File

@@ -96,23 +96,21 @@ class SP_Player_List extends SP_Custom_Post {
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$team_key = 'sp_team';
switch ( $era ):
case 'current':
$team_key = 'sp_current_team';
break;
case 'past':
$team_key = 'sp_past_team';
break;
endswitch;
$args['meta_query'] = array(
array(
'key' => $team_key,
'value' => $team
),
);
endif;
$team_key = 'sp_team';
switch ( $era ):
case 'current':
$team_key = 'sp_current_team';
break;
case 'past':
$team_key = 'sp_past_team';
break;
endswitch;
$args['meta_query'] = array(
array(
'key' => $team_key,
'value' => $team
),
);
$players = get_posts( $args );
@@ -648,7 +646,7 @@ class SP_Player_List extends SP_Custom_Post {
foreach( $this->columns as $key ):
if ( $key == 'number' ):
$labels[ $key ] = '#';
elseif ( $key == 'team' && apply_filters( 'sportspress_has_teams', true ) ):
elseif ( $key == 'team' ):
$labels[ $key ] = __( 'Team', 'sportspress' );
elseif ( $key == 'position' ):
$labels[ $key ] = __( 'Position', 'sportspress' );
@@ -695,7 +693,7 @@ class SP_Player_List extends SP_Custom_Post {
$labels = array();
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
$labels['name'] = __( 'Player', 'sportspress' );
if ( in_array( 'team', $this->columns ) && apply_filters( 'sportspress_has_teams', true ) ) $labels['team'] = __( 'Team', 'sportspress' );
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' );
if ( in_array( 'position', $this->columns ) ) $labels['position'] = __( 'Position', 'sportspress' );
$merged[0] = array_merge( $labels, $columns );

View File

@@ -502,6 +502,63 @@ if ( !function_exists( 'sp_get_term_sections' ) ) {
}
}
if ( !function_exists( 'sp_get_default_mode' ) ) {
function sp_get_default_mode() {
return get_option( 'sportspress_mode', 'team' );
}
}
if ( !function_exists( 'sp_get_post_mode' ) ) {
function sp_get_post_mode( $post_id ) {
$mode = get_post_meta( $post_id, 'sp_mode', true );
if ( empty( $mode ) ) {
$mode = sp_get_default_mode();
}
return $mode;
}
}
if ( !function_exists( 'sp_get_post_mode_type' ) ) {
function sp_get_post_mode_type( $post_id ) {
$mode = sp_get_post_mode( $post_id );
$post_type = "sp_$mode";
if ( ! in_array( $post_type, sp_primary_post_types() ) ) {
$post_type = sp_get_default_mode();
}
return $post_type;
}
}
if ( !function_exists( 'sp_get_post_mode_label' ) ) {
function sp_get_post_mode_label( $post_id, $singular = false ) {
$labels = array(
'team' => array(
__( 'Teams', 'sportspress' ),
__( 'Team', 'sportspress' ),
),
'player' => array(
__( 'Players', 'sportspress' ),
__( 'Player', 'sportspress' ),
),
);
$mode = sp_get_post_mode( $post_id );
if ( ! array_key_exists( $mode, $labels ) ) {
$mode = 'team';
}
$index = boolval( $singular );
return $labels[ $mode ][ $index ];
}
}
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
function sp_dropdown_statuses( $args = array() ) {
$defaults = array(

View File

@@ -29,82 +29,15 @@ class SportsPress_Individual_Mode {
$this->define_constants();
// Actions
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
add_action( 'sportspress_process_sp_event_meta', array( $this, 'save_player_meta' ), 99, 2 );
//add_action( 'admin_head', array( $this, 'menu_highlight' ) );
//add_action( 'sportspress_process_sp_event_meta', array( $this, 'save_player_meta' ), 99, 2 );
// Filters
add_filter( 'gettext', array( $this, 'gettext' ), 99, 3 );
add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
add_filter( 'sportspress_register_post_type_team', array( $this, 'hide_post_type' ), 99 );
add_filter( 'sportspress_register_post_type_table', array( $this, 'move_table_post_type' ), 99 );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'remove_team_settings_tab' ), 99 );
add_filter( 'sportspress_get_settings_pages', array( $this, 'remove_team_settings' ), 99 );
add_filter( 'sportspress_performance_options', array( $this, 'remove_performance_options' ), 99 );
add_filter( 'sportspress_player_options', array( $this, 'add_player_options' ), 99 );
add_filter( 'sportspress_player_settings', array( $this, 'add_player_settings' ), 99 );
add_filter( 'sportspress_next_steps', array( $this, 'remove_team_step' ), 99 );
add_filter( 'sportspress_modules', array( $this, 'rearrange_modules' ), 99 );
add_filter( 'sportspress_glance_items', array( $this, 'remove_glance_item' ), 99 );
add_filter( 'sportspress_player_admin_columns', array( $this, 'remove_team_column' ), 99 );
add_filter( 'sportspress_list_admin_columns', array( $this, 'remove_team_column' ), 99 );
add_filter( 'sportspress_staff_admin_columns', array( $this, 'remove_team_column' ), 99 );
add_filter( 'sportspress_directory_admin_columns', array( $this, 'remove_team_column' ), 99 );
add_filter( 'sportspress_importers', array( $this, 'remove_teams_importer' ), 99 );
add_filter( 'sportspress_permalink_slugs', array( $this, 'remove_team_permalink_slug' ), 99 );
add_filter( 'sportspress_primary_post_types', array( $this, 'primary_post_types' ) );
add_filter( 'sportspress_post_type_hierarchy', array( $this, 'post_type_hierarchy' ) );
add_filter( 'sportspress_event_team_tabs', '__return_false' );
add_filter( 'sportspress_player_team_statistics', '__return_false' );
add_filter( 'sportspress_player_teams', '__return_false' );
add_filter( 'sportspress_staff_teams', '__return_false' );
add_filter( 'sportspress_list_team_selector', '__return_false' );
add_filter( 'pre_option_sportspress_event_split_players_by_team', array( $this, 'no' ) );
add_filter( 'pre_option_sportspress_event_show_status', array( $this, 'no' ) );
add_filter( 'pre_option_sportspress_link_teams', array( $this, 'link_players' ) );
add_filter( 'sportspress_has_teams', '__return_false' );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_INDIVIDUAL_MODE_VERSION' ) )
define( 'SP_INDIVIDUAL_MODE_VERSION', '1.9' );
if ( !defined( 'SP_INDIVIDUAL_MODE_URL' ) )
define( 'SP_INDIVIDUAL_MODE_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_INDIVIDUAL_MODE_DIR' ) )
define( 'SP_INDIVIDUAL_MODE_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Return no.
*/
public function no() {
return 'no';
}
/**
* Return link players instead of teams.
*/
public function link_players() {
return get_option( 'sportspress_link_players', 'yes' );
}
/**
* Save teams as players in events.
*/
public function save_player_meta( $post_id, $post ) {
if ( isset( $_POST['sp_team'] ) && is_array( $_POST['sp_team'] ) ) {
$players = array();
foreach ( $_POST['sp_team'] as $player ) {
$players[] = array( 0, $player );
}
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
}
}
/**
* Modify all team-related strings for players.
*/
@@ -136,175 +69,6 @@ class SportsPress_Individual_Mode {
return $query;
}
/**
* Remove meta boxes.
*/
public function remove_meta_boxes( $meta_boxes ) {
unset( $meta_boxes['sp_event']['performance'] );
return $meta_boxes;
}
/**
* Hide post types.
*/
public function hide_post_type( $args ) {
return array_merge( $args, array(
'public' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'show_in_menu' => false,
'show_in_admin_bar' => false,
'can_export' => false,
) );
}
/**
* Move league table post type under players.
*/
public function move_table_post_type( $args ) {
return array_merge( $args, array(
'show_in_menu' => 'edit.php?post_type=sp_player',
) );
}
/**
* Remove team settings tab.
*/
public function remove_team_settings_tab( $tabs ) {
unset( $tabs['teams'] );
return $tabs;
}
/**
* Remove team settings section.
*/
public function remove_team_settings( $settings ) {
foreach ( $settings as $index => $section ) {
if ( is_a( $section, 'SP_Settings_Teams' ) ) {
unset( $settings[ $index ] );
}
}
return $settings;
}
/**
* Remove option to split players by team.
*/
public function remove_performance_options( $options ) {
foreach ( $options as $index => $option ) {
if ( 'sportspress_event_split_players_by_team' == sp_array_value( $option, 'id' ) ) {
unset( $options[ $index ] );
}
}
return $options;
}
/**
* Add options from teams to players tab.
*/
public function add_player_options( $options ) {
return apply_filters( 'sportspress_team_options', $options );
}
/**
* Add settings from teams to players tab.
*/
public function add_player_settings( $settings ) {
return apply_filters( 'sportspress_team_settings', $settings );
}
/**
* Remove team step from welcome screen.
*/
public function remove_team_step( $steps ) {
unset( $steps['teams'] );
return $steps;
}
/**
* Rearrange modules.
*/
public function rearrange_modules( $modules ) {
$modules['player_staff'] = array_merge(
sp_array_value( $modules, 'team', array() ),
sp_array_value( $modules, 'player_staff', array() )
);
unset( $modules['team'] );
unset( $modules['player_staff']['team_colors'] );
return $modules;
}
/**
* Remove teams glance item.
*/
public function remove_glance_item( $items ) {
if ( ( $index = array_search ( 'sp_team', $items ) ) !== false ) {
unset( $items[ $index ] );
}
return $items;
}
/**
* Remove team column from player list admin.
*/
public function remove_team_column( $columns ) {
unset( $columns['sp_team'] );
return $columns;
}
/**
* Remove the teams csv importer.
*/
public function remove_teams_importer( $importers ) {
unset( $importers['sp_team_csv'] );
return $importers;
}
/**
* Remove the team permalink slug setting.
*/
public function remove_team_permalink_slug( $slugs ) {
if ( ( $index = array_search ( array( 'team', __( 'Teams', 'sportspress' ) ), $slugs ) ) !== false ) {
unset( $slugs[ $index ] );
}
return $slugs;
}
/**
* Remove the team primary post type.
*/
public function primary_post_types( $post_types ) {
if ( ( $key = array_search( 'sp_team', $post_types ) ) !== false ) {
unset( $post_types[ $key ] );
}
return $post_types;
}
/**
* Adjust post type hierarchy.
*/
public function post_type_hierarchy( $hierarchy ) {
$hierarchy['sp_player'] = array_merge( sp_array_value( $hierarchy, 'sp_player', array() ), sp_array_value( $hierarchy, 'sp_team', array() ) );
unset( $hierarchy['sp_team'] );
return $hierarchy;
}
/**
* Highlights the correct top level admin menu item for post type add screens.
*
* @access public
* @return void
*/
public function menu_highlight() {
global $typenow, $parent_file, $submenu_file;
if ( 'sp_table' == $typenow ) {
$parent_file = 'edit.php?post_type=sp_player';
$submenu_file = 'edit.php?post_type=sp_table';
}
}
}
endif;

View File

@@ -172,6 +172,13 @@ class SportsPress_League_Tables {
'priority' => 'high',
);
$meta_boxes['sp_table'] = array(
'mode' => array(
'title' => __( 'Mode', 'sportspress' ),
'save' => 'SP_Meta_Box_Table_Mode::save',
'output' => 'SP_Meta_Box_Table_Mode::output',
'context' => 'side',
'priority' => 'default',
),
'shortcode' => array(
'title' => __( 'Shortcode', 'sportspress' ),
'output' => 'SP_Meta_Box_Table_Shortcode::output',

View File

@@ -73,10 +73,7 @@ class SportsPress_Template_Selector {
* Add option to team post type.
*/
public function team_options( $options ) {
if ( apply_filters( 'sportspress_has_teams', true ) ) {
return $this->options( $options, 'team' );
}
return $options;
return $this->options( $options, 'team' );
}
/**

View File

@@ -9,7 +9,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false;
$is_individual = get_option( 'sportspress_mode', 'team' ) === 'player' ? true : false;
$show_players = get_option( 'sportspress_event_show_players', 'yes' ) === 'yes' ? true : false;
$show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? true : false;
$show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false;

View File

@@ -18,7 +18,7 @@ $defaults = array(
'title' => false,
'show_title' => get_option( 'sportspress_table_show_title', 'yes' ) == 'yes' ? true : false,
'show_team_logo' => get_option( 'sportspress_table_show_logos', 'yes' ) == 'yes' ? true : false,
'link_posts' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'link_posts' => null,
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
'paginated' => get_option( 'sportspress_table_paginated', 'yes' ) == 'yes' ? true : false,
@@ -27,6 +27,14 @@ $defaults = array(
extract( $defaults, EXTR_SKIP );
if ( ! isset( $link_posts ) ) {
if ( 'player' === sp_get_post_mode( $id ) ) {
$link_posts = get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false;
} else {
$link_posts = get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false;
}
}
if ( ! isset( $highlight ) ) $highlight = get_post_meta( $id, 'sp_highlight', true );
$table = new SP_League_Table( $id );

View File

@@ -45,7 +45,7 @@ if ( $season_ids ):
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
if ( $team ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',

View File

@@ -44,7 +44,7 @@ if ( $season_ids ):
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
if ( $team ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',