Get player data only when needed
This commit is contained in:
@@ -31,69 +31,82 @@ $countries = SP()->countries->countries;
|
||||
|
||||
$player = new SP_Player( $id );
|
||||
|
||||
$nationalities = $player->nationalities();
|
||||
$positions = $player->positions();
|
||||
$current_teams = $player->current_teams();
|
||||
$past_teams = $player->past_teams();
|
||||
$leagues = $player->leagues();
|
||||
$seasons = $player->seasons();
|
||||
$metrics_before = $player->metrics( true );
|
||||
$metrics_after = $player->metrics( false );
|
||||
|
||||
$common = array();
|
||||
if ( $show_nationality && $nationalities && is_array( $nationalities ) ):
|
||||
$values = array();
|
||||
foreach ( $nationalities as $nationality ):
|
||||
$country_name = sp_array_value( $countries, $nationality, null );
|
||||
$values[] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
||||
endforeach;
|
||||
$common[ __( 'Nationality', 'sportspress' ) ] = implode( '<br>', $values );
|
||||
|
||||
if ( $show_nationality ):
|
||||
$nationalities = $player->nationalities();
|
||||
if ( $nationalities && is_array( $nationalities ) ):
|
||||
$values = array();
|
||||
foreach ( $nationalities as $nationality ):
|
||||
$country_name = sp_array_value( $countries, $nationality, null );
|
||||
$values[] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
||||
endforeach;
|
||||
$common[ __( 'Nationality', 'sportspress' ) ] = implode( '<br>', $values );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $show_positions && $positions && is_array( $positions ) ):
|
||||
$position_names = array();
|
||||
foreach ( $positions as $position ):
|
||||
$position_names[] = $position->name;
|
||||
endforeach;
|
||||
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
|
||||
if ( $show_positions ):
|
||||
$positions = $player->positions();
|
||||
if ( $positions && is_array( $positions ) ):
|
||||
$position_names = array();
|
||||
foreach ( $positions as $position ):
|
||||
$position_names[] = $position->name;
|
||||
endforeach;
|
||||
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
$data = array_merge( $metrics_before, $common, $metrics_after );
|
||||
|
||||
if ( $show_current_teams && $current_teams ):
|
||||
$teams = array();
|
||||
foreach ( $current_teams as $team ):
|
||||
$team_name = sp_get_team_name( $team, $abbreviate_teams );
|
||||
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
|
||||
$teams[] = $team_name;
|
||||
endforeach;
|
||||
$data[ __( 'Current Team', 'sportspress' ) ] = implode( ', ', $teams );
|
||||
if ( $show_current_teams ):
|
||||
$current_teams = $player->current_teams();
|
||||
if ( $current_teams ):
|
||||
$teams = array();
|
||||
foreach ( $current_teams as $team ):
|
||||
$team_name = sp_get_team_name( $team, $abbreviate_teams );
|
||||
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
|
||||
$teams[] = $team_name;
|
||||
endforeach;
|
||||
$data[ __( 'Current Team', 'sportspress' ) ] = implode( ', ', $teams );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $show_past_teams && $past_teams ):
|
||||
$teams = array();
|
||||
foreach ( $past_teams as $team ):
|
||||
$team_name = sp_get_team_name( $team, $abbreviate_teams );
|
||||
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
|
||||
$teams[] = $team_name;
|
||||
endforeach;
|
||||
$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
|
||||
if ( $show_past_teams ):
|
||||
$past_teams = $player->past_teams();
|
||||
if ( $past_teams ):
|
||||
$teams = array();
|
||||
foreach ( $past_teams as $team ):
|
||||
$team_name = sp_get_team_name( $team, $abbreviate_teams );
|
||||
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
|
||||
$teams[] = $team_name;
|
||||
endforeach;
|
||||
$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $show_leagues && $leagues && ! is_wp_error( $leagues ) ):
|
||||
$terms = array();
|
||||
foreach ( $leagues as $league ) {
|
||||
$terms[] = $league->name;
|
||||
}
|
||||
$data[ __( 'Competitions', 'sportspress' ) ] = implode( ', ', $terms );
|
||||
if ( $show_leagues ):
|
||||
$leagues = $player->leagues();
|
||||
if ( $leagues && ! is_wp_error( $leagues ) ):
|
||||
$terms = array();
|
||||
foreach ( $leagues as $league ) {
|
||||
$terms[] = $league->name;
|
||||
}
|
||||
$data[ __( 'Competitions', 'sportspress' ) ] = implode( ', ', $terms );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $show_seasons && $seasons && ! is_wp_error( $seasons ) ):
|
||||
$terms = array();
|
||||
foreach ( $seasons as $season ) {
|
||||
$terms[] = $season->name;
|
||||
}
|
||||
$data[ __( 'Seasons', 'sportspress' ) ] = implode( ', ', $terms );
|
||||
if ( $show_seasons ):
|
||||
$seasons = $player->seasons();
|
||||
if ( $seasons && ! is_wp_error( $seasons ) ):
|
||||
$terms = array();
|
||||
foreach ( $seasons as $season ) {
|
||||
$terms[] = $season->name;
|
||||
}
|
||||
$data[ __( 'Seasons', 'sportspress' ) ] = implode( ', ', $terms );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
$data = apply_filters( 'sportspress_player_details', $data, $id );
|
||||
|
||||
Reference in New Issue
Block a user