From d7509b8614c5b0c3cb55003dc466a21d733f4f66 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 22 Jan 2014 21:01:58 +1100 Subject: [PATCH] Better way of getting ID --- admin/templates/event-details.php | 6 ++---- admin/templates/event-players.php | 6 ++---- admin/templates/event-results.php | 6 ++---- admin/templates/event-staff.php | 7 ++----- admin/templates/event-venue.php | 3 +++ admin/templates/events-calendar.php | 6 ++---- admin/templates/league-table.php | 10 ++++------ admin/templates/player-league-statistics.php | 17 +++++++++++------ admin/templates/player-list.php | 6 ++---- admin/templates/player-metrics.php | 6 ++---- admin/templates/player-statistics.php | 6 ++---- admin/templates/team-columns.php | 15 +++++++-------- 12 files changed, 41 insertions(+), 53 deletions(-) diff --git a/admin/templates/event-details.php b/admin/templates/event-details.php index a49736b3..1acb3f6d 100644 --- a/admin/templates/event-details.php +++ b/admin/templates/event-details.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_event_details' ) ) { function sportspress_event_details( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $date = get_the_time( get_option('date_format'), $id ); $time = get_the_time( get_option('time_format'), $id ); diff --git a/admin/templates/event-players.php b/admin/templates/event-players.php index b6f86220..999dd732 100644 --- a/admin/templates/event-players.php +++ b/admin/templates/event-players.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_event_players' ) ) { function sportspress_event_players( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $teams = (array)get_post_meta( $id, 'sp_team', false ); $staff = (array)get_post_meta( $id, 'sp_staff', false ); diff --git a/admin/templates/event-results.php b/admin/templates/event-results.php index a81dafd1..ab430259 100644 --- a/admin/templates/event-results.php +++ b/admin/templates/event-results.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_event_results' ) ) { function sportspress_event_results( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $teams = (array)get_post_meta( $id, 'sp_team', false ); $results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) ); diff --git a/admin/templates/event-staff.php b/admin/templates/event-staff.php index 252557fc..be2a0fdb 100644 --- a/admin/templates/event-staff.php +++ b/admin/templates/event-staff.php @@ -2,11 +2,8 @@ if ( !function_exists( 'sportspress_event_staff' ) ) { function sportspress_event_staff( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; - + if ( ! $id ) + $id = get_the_ID(); $staff = (array)get_post_meta( $id, 'sp_staff', false ); $output = ''; diff --git a/admin/templates/event-venue.php b/admin/templates/event-venue.php index 98cf1715..9a132673 100644 --- a/admin/templates/event-venue.php +++ b/admin/templates/event-venue.php @@ -2,6 +2,9 @@ if ( !function_exists( 'sportspress_event_venue' ) ) { function sportspress_event_venue( $id ) { + if ( ! $id ) + $id = get_the_ID(); + $venues = get_the_terms( $id, 'sp_venue' ); $output = ''; diff --git a/admin/templates/events-calendar.php b/admin/templates/events-calendar.php index d79f7c53..4a652b81 100644 --- a/admin/templates/events-calendar.php +++ b/admin/templates/events-calendar.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { function sportspress_events_calendar( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; $initial = false; diff --git a/admin/templates/league-table.php b/admin/templates/league-table.php index 32b27595..ca06a60e 100644 --- a/admin/templates/league-table.php +++ b/admin/templates/league-table.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_league_table' ) ) { function sportspress_league_table( $id = null, $args = '' ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $defaults = array( 'number_label' => __( 'Pos', 'sportspress' ), @@ -26,8 +24,8 @@ if ( !function_exists( 'sportspress_league_table' ) ) { $title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id ); - $output = '' . - '' . '' . ''; + $output = '

' . $title . '

' . + '
' . $title . '
' . '' . ''; $data = sportspress_get_league_table_data( $id ); diff --git a/admin/templates/player-league-statistics.php b/admin/templates/player-league-statistics.php index 2fc4b8b4..6b2b52f4 100644 --- a/admin/templates/player-league-statistics.php +++ b/admin/templates/player-league-statistics.php @@ -2,10 +2,11 @@ if ( !function_exists( 'sportspress_player_league_statistics' ) ) { function sportspress_player_league_statistics( $league, $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $league ) + return false; + + if ( ! $id ) + $id = get_the_ID(); $data = sportspress_get_player_statistics_data( $id, $league->term_id ); @@ -15,8 +16,12 @@ if ( !function_exists( 'sportspress_player_league_statistics' ) ) { // Remove the first row to leave us with the actual data unset( $data[0] ); - $output = '
' . - '' . '' . ''; + // Skip if there are no rows in the table + if ( empty( $data ) ) + return false; + + $output = '

' . $league->name . '

' . + '
' . $league->name . '
' . '' . ''; foreach( $labels as $key => $label ): $output .= ''; diff --git a/admin/templates/player-list.php b/admin/templates/player-list.php index 4429b8ce..af945f98 100644 --- a/admin/templates/player-list.php +++ b/admin/templates/player-list.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_player_list' ) ) { function sportspress_player_list( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $data = sportspress_get_player_list_data( $id ); diff --git a/admin/templates/player-metrics.php b/admin/templates/player-metrics.php index 3af5a821..e978596e 100644 --- a/admin/templates/player-metrics.php +++ b/admin/templates/player-metrics.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) { function sportspress_player_metrics( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); global $sportspress_countries; diff --git a/admin/templates/player-statistics.php b/admin/templates/player-statistics.php index 2717c910..7f10e76d 100644 --- a/admin/templates/player-statistics.php +++ b/admin/templates/player-statistics.php @@ -2,10 +2,8 @@ if ( !function_exists( 'sportspress_player_statistics' ) ) { function sportspress_player_statistics( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $leagues = get_the_terms( $id, 'sp_league' ); diff --git a/admin/templates/team-columns.php b/admin/templates/team-columns.php index 961037eb..f94097ee 100644 --- a/admin/templates/team-columns.php +++ b/admin/templates/team-columns.php @@ -2,13 +2,14 @@ if ( !function_exists( 'sportspress_team_columns' ) ) { function sportspress_team_columns( $id = null ) { - if ( ! $id ): - global $post; - $id = $post->ID; - endif; + if ( ! $id ) + $id = get_the_ID(); $leagues = get_the_terms( $id, 'sp_league' ); + if ( ! $leagues ) + return false; + $output = ''; // Loop through data for each league @@ -19,16 +20,14 @@ if ( !function_exists( 'sportspress_team_columns' ) ) { if ( sizeof( $data ) <= 1 ) continue; - if ( sizeof( $leagues ) > 1 ) - $output .= '

' . $league->name . '

'; - // The first row should be column labels $labels = $data[0]; // Remove the first row to leave us with the actual data unset( $data[0] ); - $output .= '
' . $label . '
' . '' . ''; + $output .= '

' . $league->name . '

' . + '
' . '' . ''; foreach( $labels as $key => $label ): $output .= '';
' . $label . '