Add offense and defense option to player performance
This commit is contained in:
@@ -166,6 +166,7 @@ class SP_Admin_Sports {
|
||||
}
|
||||
update_post_meta( $id, 'sp_icon', sp_array_value( $performance, 'icon', null ) );
|
||||
update_post_meta( $id, 'sp_color', sp_array_value( $performance, 'color', null ) );
|
||||
update_post_meta( $id, 'sp_section', sp_array_value( $performance, 'section', -1 ) );
|
||||
$i ++;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,19 +62,58 @@ class SP_Meta_Box_Event_Teams {
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
<?php $tabs = apply_filters( 'sportspress_event_team_tabs', array( 'sp_player', 'sp_staff' ) ); ?>
|
||||
<?php
|
||||
$tabs = array();
|
||||
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||
if ( 0 == $sections ) {
|
||||
$tabs['sp_offense'] = array(
|
||||
'label' => __( 'Offense', 'sportspress' ),
|
||||
'post_type' => 'sp_player',
|
||||
);
|
||||
$tabs['sp_defense'] = array(
|
||||
'label' => __( 'Defense', 'sportspress' ),
|
||||
'post_type' => 'sp_player',
|
||||
);
|
||||
} elseif ( 1 == $sections ) {
|
||||
$tabs['sp_defense'] = array(
|
||||
'label' => __( 'Defense', 'sportspress' ),
|
||||
'post_type' => 'sp_player',
|
||||
);
|
||||
$tabs['sp_offense'] = array(
|
||||
'label' => __( 'Offense', 'sportspress' ),
|
||||
'post_type' => 'sp_player',
|
||||
);
|
||||
} else {
|
||||
$tabs['sp_player'] = array(
|
||||
'label' => __( 'Players', 'sportspress' ),
|
||||
'post_type' => 'sp_player',
|
||||
);
|
||||
}
|
||||
$tabs['sp_staff'] = array(
|
||||
'label' => __( 'Staff', 'sportspress' ),
|
||||
'post_type' => 'sp_staff',
|
||||
);
|
||||
?>
|
||||
<?php if ( $tabs ) { ?>
|
||||
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
|
||||
<?php foreach ( $tabs as $index => $post_type ) { $object = get_post_type_object( $post_type ); ?>
|
||||
<li class="wp-tab<?php if ( 0 == $index ) { ?>-active<?php } ?>"><a href="#<?php echo $post_type; ?>-all"><?php echo $object->labels->name; ?></a></li>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$j = 0;
|
||||
foreach ( $tabs as $slug => $tab ) {
|
||||
?>
|
||||
<li class="wp-tab<?php if ( 0 == $j ) { ?>-active<?php } ?>"><a href="#<?php echo $slug; ?>-all"><?php echo $tab['label']; ?></a></li>
|
||||
<?php
|
||||
$j++;
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
foreach ( $tabs as $index => $post_type ) {
|
||||
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), $team, $i );
|
||||
$j = 0;
|
||||
foreach ( $tabs as $slug => $tab ) {
|
||||
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), $team, $i, $slug );
|
||||
if ( apply_filters( 'sportspress_event_teams_meta_box_default_checklist', true ) ) {
|
||||
sp_post_checklist( $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), array( 'sp_league', 'sp_season', 'sp_current_team' ), $i );
|
||||
sp_post_checklist( $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), array( 'sp_league', 'sp_season', 'sp_current_team' ), $i, $slug );
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
@@ -107,11 +146,16 @@ class SP_Meta_Box_Event_Teams {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||
$tabs = apply_filters( 'sportspress_event_team_tabs', array( 'sp_player', 'sp_staff' ) );
|
||||
if ( $tabs ) {
|
||||
foreach ( $tabs as $post_type ) {
|
||||
sp_update_post_meta_recursive( $post_id, $post_type, sp_array_value( $_POST, $post_type, 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() ) );
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,51 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
|
||||
} else {
|
||||
$readonly = false;
|
||||
}
|
||||
$section = get_post_meta( $post->ID, 'sp_section', true );
|
||||
if ( '' === $section ) {
|
||||
$section = -1;
|
||||
}
|
||||
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
if ( '' === $format ) {
|
||||
$format = 'number';
|
||||
}
|
||||
?>
|
||||
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
||||
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Category', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-section-selector">
|
||||
<select name="sp_section">
|
||||
<?php
|
||||
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
|
||||
foreach ( $options as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section ), $value );
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Format', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-format-selector">
|
||||
<select name="sp_format">
|
||||
<?php
|
||||
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ) ) );
|
||||
foreach ( $options as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format ), $value );
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
self::delete_duplicate( $_POST );
|
||||
update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) );
|
||||
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) );
|
||||
}
|
||||
}
|
||||
@@ -371,19 +371,15 @@ class SP_Settings_Events extends SP_Settings_Page {
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Split players by team', 'sportspress' ),
|
||||
'id' => 'sportspress_event_split_players_by_team',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Split players by position', 'sportspress' ),
|
||||
'id' => 'sportspress_event_split_players_by_position',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'title' => __( 'Performance', 'sportspress' ),
|
||||
'id' => 'sportspress_event_performance_sections',
|
||||
'default' => -1,
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
-1 => __( 'Combined', 'sportspress' ),
|
||||
0 => __( 'Offense', 'sportspress' ) . ' → ' . __( 'Defense', 'sportspress' ),
|
||||
1 => __( 'Defense', 'sportspress' ) . ' → ' . __( 'Offense', 'sportspress' ),
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user