From becec8b7bcf386a1be1dcef3ece68b30254c86de Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 16 Mar 2014 18:07:06 +1100 Subject: [PATCH] Add checkboxes to each player list column --- admin/hooks/save-post.php | 3 +++ admin/post-types/list.php | 10 +++------- functions.php | 21 +++++++++++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index e8170457..996f7633 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -150,6 +150,9 @@ function sportspress_save_post( $post_id ) { case ( 'sp_list' ): + // Update statistics array + update_post_meta( $post_id, 'sp_statistics', sportspress_array_value( $_POST, 'sp_statistics', array() ) ); + // Update players array update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) ); diff --git a/admin/post-types/list.php b/admin/post-types/list.php index 80c805db..e01f7752 100644 --- a/admin/post-types/list.php +++ b/admin/post-types/list.php @@ -49,11 +49,7 @@ function sportspress_list_meta_init( $post ) { remove_meta_box( 'sp_leaguediv', 'sp_list', 'side' ); add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'sportspress_list_format_meta', 'sp_list', 'side', 'high' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_list_details_meta', 'sp_list', 'side', 'high' ); - - if ( $players && $players != array(0) ): - add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sportspress_list_stats_meta', 'sp_list', 'normal', 'high' ); - endif; - + add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sportspress_list_stats_meta', 'sp_list', 'normal', 'high' ); add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'sportspress_list_description_meta', 'sp_list', 'normal', 'high' ); } @@ -158,9 +154,9 @@ function sportspress_list_details_meta( $post ) { function sportspress_list_stats_meta( $post ) { - list( $columns, $data, $placeholders, $merged ) = sportspress_get_player_list_data( $post->ID, true ); + list( $columns, $usecolumns, $data, $placeholders, $merged ) = sportspress_get_player_list_data( $post->ID, true ); - sportspress_edit_player_list_table( $columns, $data, $placeholders ); + sportspress_edit_player_list_table( $columns, $usecolumns, $data, $placeholders ); sportspress_nonce(); } diff --git a/functions.php b/functions.php index 65b38c9e..e49dbc11 100644 --- a/functions.php +++ b/functions.php @@ -828,7 +828,9 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) { } if ( !function_exists( 'sportspress_edit_player_list_table' ) ) { - function sportspress_edit_player_list_table( $columns = array(), $data = array(), $placeholders = array() ) { + function sportspress_edit_player_list_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) { + if ( is_array( $usecolumns ) ) + $usecolumns = array_filter( $usecolumns ); ?>
@@ -836,8 +838,11 @@ if ( !function_exists( 'sportspress_edit_player_list_table' ) ) { - - + $label ): ?> + @@ -1979,6 +1984,7 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { $stats = (array)get_post_meta( $post_id, 'sp_players', true ); $orderby = get_post_meta( $post_id, 'sp_orderby', true ); $order = get_post_meta( $post_id, 'sp_order', true ); + $usecolumns = get_post_meta( $post_id, 'sp_statistics', true ); // Get labels from result variables $columns = (array)sportspress_get_var_labels( 'sp_statistic' ); @@ -2214,8 +2220,15 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { endforeach; if ( $admin ): - return array( $columns, $data, $placeholders, $merged ); + return array( $columns, $usecolumns, $data, $placeholders, $merged ); 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' => __( 'Player', 'sportspress' ) ), $columns ); $merged[0] = $labels; return $merged;
#