Better way of getting ID

This commit is contained in:
Brian Miyaji
2014-01-22 21:01:58 +11:00
parent 7555d78739
commit d7509b8614
12 changed files with 41 additions and 53 deletions

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_event_details' ) ) { if ( !function_exists( 'sportspress_event_details' ) ) {
function sportspress_event_details( $id = null ) { function sportspress_event_details( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$date = get_the_time( get_option('date_format'), $id ); $date = get_the_time( get_option('date_format'), $id );
$time = get_the_time( get_option('time_format'), $id ); $time = get_the_time( get_option('time_format'), $id );

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_event_players' ) ) { if ( !function_exists( 'sportspress_event_players' ) ) {
function sportspress_event_players( $id = null ) { function sportspress_event_players( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$teams = (array)get_post_meta( $id, 'sp_team', false ); $teams = (array)get_post_meta( $id, 'sp_team', false );
$staff = (array)get_post_meta( $id, 'sp_staff', false ); $staff = (array)get_post_meta( $id, 'sp_staff', false );

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_event_results' ) ) { if ( !function_exists( 'sportspress_event_results' ) ) {
function sportspress_event_results( $id = null ) { function sportspress_event_results( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$teams = (array)get_post_meta( $id, 'sp_team', false ); $teams = (array)get_post_meta( $id, 'sp_team', false );
$results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) ); $results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) );

View File

@@ -2,11 +2,8 @@
if ( !function_exists( 'sportspress_event_staff' ) ) { if ( !function_exists( 'sportspress_event_staff' ) ) {
function sportspress_event_staff( $id = null ) { function sportspress_event_staff( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$staff = (array)get_post_meta( $id, 'sp_staff', false ); $staff = (array)get_post_meta( $id, 'sp_staff', false );
$output = ''; $output = '';

View File

@@ -2,6 +2,9 @@
if ( !function_exists( 'sportspress_event_venue' ) ) { if ( !function_exists( 'sportspress_event_venue' ) ) {
function sportspress_event_venue( $id ) { function sportspress_event_venue( $id ) {
if ( ! $id )
$id = get_the_ID();
$venues = get_the_terms( $id, 'sp_venue' ); $venues = get_the_terms( $id, 'sp_venue' );
$output = ''; $output = '';

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_events_calendar' ) ) { if ( !function_exists( 'sportspress_events_calendar' ) ) {
function sportspress_events_calendar( $id = null ) { function sportspress_events_calendar( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
$initial = false; $initial = false;

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_league_table' ) ) { if ( !function_exists( 'sportspress_league_table' ) ) {
function sportspress_league_table( $id = null, $args = '' ) { function sportspress_league_table( $id = null, $args = '' ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$defaults = array( $defaults = array(
'number_label' => __( 'Pos', 'sportspress' ), 'number_label' => __( 'Pos', 'sportspress' ),
@@ -26,8 +24,8 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id ); $title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id );
$output = '<table class="sp-league-table sp-data-table">' . $output = '<h4 class="sp-table-caption">' . $title . '</h4>' .
'<caption>' . $title . '</caption>' . '<thead>' . '<tr>'; '<table class="sp-league-table sp-data-table">' . '<thead>' . '<tr>';
$data = sportspress_get_league_table_data( $id ); $data = sportspress_get_league_table_data( $id );

View File

@@ -2,10 +2,11 @@
if ( !function_exists( 'sportspress_player_league_statistics' ) ) { if ( !function_exists( 'sportspress_player_league_statistics' ) ) {
function sportspress_player_league_statistics( $league, $id = null ) { function sportspress_player_league_statistics( $league, $id = null ) {
if ( ! $id ): if ( ! $league )
global $post; return false;
$id = $post->ID;
endif; if ( ! $id )
$id = get_the_ID();
$data = sportspress_get_player_statistics_data( $id, $league->term_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 // Remove the first row to leave us with the actual data
unset( $data[0] ); unset( $data[0] );
$output = '<table class="sp-player-statistics sp-data-table">' . // Skip if there are no rows in the table
'<caption>' . $league->name . '</caption>' . '<thead>' . '<tr>'; if ( empty( $data ) )
return false;
$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
'<table class="sp-player-statistics sp-data-table">' . '<thead>' . '<tr>';
foreach( $labels as $key => $label ): foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>'; $output .= '<th class="data-' . $key . '">' . $label . '</th>';

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_player_list' ) ) { if ( !function_exists( 'sportspress_player_list' ) ) {
function sportspress_player_list( $id = null ) { function sportspress_player_list( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$data = sportspress_get_player_list_data( $id ); $data = sportspress_get_player_list_data( $id );

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_player_metrics' ) ) { if ( !function_exists( 'sportspress_player_metrics' ) ) {
function sportspress_player_metrics( $id = null ) { function sportspress_player_metrics( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
global $sportspress_countries; global $sportspress_countries;

View File

@@ -2,10 +2,8 @@
if ( !function_exists( 'sportspress_player_statistics' ) ) { if ( !function_exists( 'sportspress_player_statistics' ) ) {
function sportspress_player_statistics( $id = null ) { function sportspress_player_statistics( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$leagues = get_the_terms( $id, 'sp_league' ); $leagues = get_the_terms( $id, 'sp_league' );

View File

@@ -2,13 +2,14 @@
if ( !function_exists( 'sportspress_team_columns' ) ) { if ( !function_exists( 'sportspress_team_columns' ) ) {
function sportspress_team_columns( $id = null ) { function sportspress_team_columns( $id = null ) {
if ( ! $id ): if ( ! $id )
global $post; $id = get_the_ID();
$id = $post->ID;
endif;
$leagues = get_the_terms( $id, 'sp_league' ); $leagues = get_the_terms( $id, 'sp_league' );
if ( ! $leagues )
return false;
$output = ''; $output = '';
// Loop through data for each league // Loop through data for each league
@@ -19,16 +20,14 @@ if ( !function_exists( 'sportspress_team_columns' ) ) {
if ( sizeof( $data ) <= 1 ) if ( sizeof( $data ) <= 1 )
continue; continue;
if ( sizeof( $leagues ) > 1 )
$output .= '<h4 class="sp-team-league-name">' . $league->name . '</h4>';
// The first row should be column labels // The first row should be column labels
$labels = $data[0]; $labels = $data[0];
// Remove the first row to leave us with the actual data // Remove the first row to leave us with the actual data
unset( $data[0] ); unset( $data[0] );
$output .= '<table class="sp-team-columns sp-data-table">' . '<thead>' . '<tr>'; $output .= '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
'<table class="sp-team-columns sp-data-table">' . '<thead>' . '<tr>';
foreach( $labels as $key => $label ): foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>'; $output .= '<th class="data-' . $key . '">' . $label . '</th>';