diff --git a/includes/admin/class-sp-admin-post-types.php b/includes/admin/class-sp-admin-post-types.php index d533c403..41ea4d3d 100644 --- a/includes/admin/class-sp-admin-post-types.php +++ b/includes/admin/class-sp-admin-post-types.php @@ -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; diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php index ed4bc68b..a4b4988c 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php @@ -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 ) { diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-statistic-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-statistic-details.php index b3542c1c..21963045 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-statistic-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-statistic-details.php @@ -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; ?>

@@ -50,6 +55,17 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config { ?>

+

+ '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', diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 3eb17542..c5004bec 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -115,11 +115,9 @@ class SP_Player extends SP_Custom_Post { $metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true ); $stats = (array)get_post_meta( $this->ID, 'sp_statistics', true ); $leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() ); - $usecolumns = get_post_meta( $this->ID, 'sp_columns', true ); - - // Get labels by section + $args = array( - 'post_type' => 'sp_performance', + 'post_type' => array( 'sp_performance', 'sp_statistic' ), 'numberposts' => 100, 'posts_per_page' => 100, 'orderby' => 'menu_order', @@ -128,6 +126,22 @@ class SP_Player extends SP_Custom_Post { $posts = get_posts( $args ); + if ( 'manual' == get_option( 'sportspress_player_columns', 'auto' ) ) { + $usecolumns = get_post_meta( $this->ID, 'sp_columns', true ); + } else { + $usecolumns = array(); + if ( is_array( $posts ) ) { + foreach ( $posts as $post ) { + // Get visibility + $visibility = get_post_meta( $post->ID, 'sp_visibility', true ); + if ( ! is_array( $visibility ) || in_array( 'sp_player', $visibility ) ) { + $usecolumns[] = $post->post_name; + } + } + } + } + + // Get labels by section $performance_labels = array(); foreach ( $posts as $post ): @@ -144,7 +158,6 @@ class SP_Player extends SP_Custom_Post { $performance_labels[ $post->post_name ] = $post->post_title; } } - endforeach; // Get labels from outcome variables @@ -525,20 +538,13 @@ class SP_Player extends SP_Custom_Post { endforeach; endif; return array( $labels, $data, $placeholders, $merged, $leagues ); else: - if ( ! is_array( $this->columns ) ) - $this->columns = array(); - foreach ( $columns as $key => $label ): - if ( ! in_array( $key, $this->columns ) ): - unset( $columns[ $key ] ); - endif; - endforeach; - if ( ! is_array( $usecolumns ) ) - $usecolumns = array(); - foreach ( $columns as $key => $label ): - if ( ! in_array( $key, $usecolumns ) ): - unset( $columns[ $key ] ); - endif; - endforeach; + if ( is_array( $usecolumns ) ): + foreach ( $columns as $key => $label ): + if ( ! in_array( $key, $usecolumns ) ): + unset( $columns[ $key ] ); + endif; + endforeach; + endif; $labels = array();