Add automatic player statistic column setting

This commit is contained in:
Brian Miyaji
2016-04-01 01:22:01 +11:00
parent 8029293d30
commit fdb780aa28
5 changed files with 64 additions and 30 deletions

View File

@@ -24,6 +24,7 @@ class SP_Admin_Post_Types {
add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
add_action( 'save_post', array( $this, 'unflag_post' ) );
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) );
}
/**
@@ -105,6 +106,16 @@ class SP_Admin_Post_Types {
return $messages;
}
/**
* Remove meta boxes as needed
*/
public static function meta_boxes( $meta_boxes ) {
if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) {
unset( $meta_boxes['sp_player']['columns'] );
}
return $meta_boxes;
}
}
endif;

View File

@@ -43,17 +43,6 @@ class SP_Meta_Box_Player_Statistics {
} else {
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
}
// Get labels by section
$args = array(
'post_type' => 'sp_performance',
'numberposts' => 100,
'posts_per_page' => 100,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$columns = get_posts( $args );
$s = 0;
foreach ( $section_order as $section_id => $section_label ) {

View File

@@ -25,10 +25,15 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$precision = get_post_meta( $post->ID, 'sp_precision', true );
$section = get_post_meta( $post->ID, 'sp_section', true );
$visibility = get_post_meta( $post->ID, 'sp_visibility', true );
// Options
$visibility_options = apply_filters( 'sportspress_statistic_visibility_options', array( 'sp_event', 'sp_player', 'sp_list' ) );
// Defaults
if ( '' === $precision ) $precision = 0;
if ( '' === $section ) $section = -1;
if ( ! is_array( $visibility ) ) $visibility = $visibility_options;
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p>
@@ -50,6 +55,17 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
?>
</select>
</p>
<p><strong><?php _e( 'Visibility', 'sportspress' ); ?></strong></p>
<ul class="categorychecklist form-no-clear">
<?php foreach ( $visibility_options as $option ) { $object = get_post_type_object( $option ); ?>
<li>
<label class="selectit">
<input name="sp_visibility[]" id="sp_visibility_<?php echo $option; ?>" type="checkbox" value="<?php echo $option; ?>" <?php checked( in_array( $option, $visibility ) ); ?>>
<?php echo $object->labels->singular_name; ?>
</label>
</li>
<?php } ?>
</ul>
<?php
}
@@ -60,6 +76,7 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
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_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
update_post_meta( $post_id, 'sp_visibility', (array) sp_array_value( $_POST, 'sp_visibility', array() ) );
}
}

View File

@@ -133,6 +133,17 @@ class SP_Settings_Players extends SP_Settings_Page {
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Columns', 'sportspress' ),
'id' => 'sportspress_player_columns',
'default' => 'auto',
'type' => 'radio',
'options' => array(
'auto' => __( 'Auto', 'sportspress' ),
'manual' => __( 'Manual', 'sportspress' ),
),
),
array(
'title' => __( 'Statistics', 'sportspress' ),
'id' => 'sportspress_player_performance_sections',