From f839dfe76b44f5dddbaae415df69c1b886010326 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 11 Mar 2014 10:28:47 +1100 Subject: [PATCH] Fix PHP warning when no columns are selected in table --- admin/post-types/table.php | 6 +-- functions.php | 83 ++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/admin/post-types/table.php b/admin/post-types/table.php index cb6039a5..22f75928 100644 --- a/admin/post-types/table.php +++ b/admin/post-types/table.php @@ -47,11 +47,7 @@ function sportspress_table_meta_init( $post ) { remove_meta_box( 'sp_seasondiv', 'sp_table', 'side' ); remove_meta_box( 'sp_leaguediv', 'sp_table', 'side' ); add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_table_team_meta', 'sp_table', 'side', 'default' ); - - if ( $teams && $teams != array(0) ): - add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sportspress_table_columns_meta', 'sp_table', 'normal', 'high' ); - endif; - + add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sportspress_table_columns_meta', 'sp_table', 'normal', 'high' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_table_details_meta', 'sp_table', 'normal', 'high' ); } diff --git a/functions.php b/functions.php index ea15babf..e285ec58 100644 --- a/functions.php +++ b/functions.php @@ -772,8 +772,9 @@ if ( !function_exists( 'sportspress_get_var_calculates' ) ) { } if ( !function_exists( 'sportspress_edit_league_table' ) ) { - function sportspress_edit_league_table( $columns = array(), $usecolumns = array(), $data = array(), $placeholders = array() ) { - $usecolumns = array_filter( $usecolumns ); + function sportspress_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) { + if ( is_array( $usecolumns ) ) + $usecolumns = array_filter( $usecolumns ); ?>
@@ -782,7 +783,7 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) { $label ): ?> @@ -790,38 +791,48 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) { $team_stats ): - if ( !$team_id ) - continue; + if ( is_array( $data ) && sizeof( $data ) > 0 ): + $i = 0; + foreach ( $data as $team_id => $team_stats ): + if ( !$team_id ) + continue; - $div = get_term( $team_id, 'sp_season' ); - $default_name = sportspress_array_value( $team_stats, 'name', '' ); - if ( $default_name == null ) - $default_name = get_the_title( $team_id ); - ?> - - - $label ): - $value = sportspress_array_value( $team_stats, $column, '' ); - $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $team_id, array() ), $column, 0 ); - ?> - - - - + + + $label ): + $value = sportspress_array_value( $team_stats, $column, '' ); + $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $team_id, array() ), $column, 0 ); + ?> + + + + + + + +
- - - - - -
+ + + + + +
+ +
@@ -1897,7 +1908,9 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) { if ( $breakdown ): return array( $columns, $usecolumns, $data, $placeholders, $merged ); else: - foreach( $columns as $key => $label ): + if ( ! is_array( $usecolumns ) ) + $usecolumns = array(); + foreach ( $columns as $key => $label ): if ( ! in_array( $key, $usecolumns ) ): unset( $columns[ $key ] ); endif;