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 0777c789..132efcef 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 @@ -20,9 +20,10 @@ class SP_Meta_Box_Player_Statistics { */ public static function output( $post ) { $leagues = get_the_terms( $post->ID, 'sp_league' ); - $league_num = sizeof( $leagues ); + $usecolumns = get_post_meta( $post->ID, 'sp_columns', true ); + // Loop through statistics for each league if ( $leagues ): foreach ( $leagues as $league ): @@ -34,8 +35,7 @@ class SP_Meta_Box_Player_Statistics { $player = new SP_Player( $post ); list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true ); - - self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) ); + self::table( $post->ID, $league->term_id, $columns, $usecolumns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) ); endforeach; else: @@ -48,6 +48,7 @@ class SP_Meta_Box_Player_Statistics { * Save meta box data */ public static function save( $post_id, $post ) { + update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) ); update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) ); if ( current_user_can( 'edit_sp_player_statistics' ) ) update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) ); @@ -56,8 +57,10 @@ class SP_Meta_Box_Player_Statistics { /** * Admin edit table */ - public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) { + public static function table( $id = null, $league_id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) { $teams = array_filter( get_post_meta( $id, 'sp_team', false ) ); + if ( is_array( $usecolumns ) ) + $usecolumns = array_filter( $usecolumns ); ?>
@@ -65,8 +68,11 @@ class SP_Meta_Box_Player_Statistics { - - + $label ): ?> + diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 56e55758..ac1735f8 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -55,6 +55,7 @@ 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 from performance variables $performance_labels = (array)sp_get_var_labels( 'sp_performance' ); @@ -298,6 +299,13 @@ class SP_Player extends SP_Custom_Post { if ( $admin ): return array( $columns, $data, $placeholders, $merged, $leagues ); else: + if ( ! is_array( $usecolumns ) ) + $usecolumns = array(); + foreach ( $columns as $key => $label ): + if ( ! in_array( $key, $usecolumns ) ): + unset( $columns[ $key ] ); + endif; + endforeach; $labels = array_merge( array( 'name' => SP()->text->string('Season'), 'team' => SP()->text->string('Team') ), $columns ); $merged[0] = $labels; return $merged;