Hide player details section if none available
This commit is contained in:
@@ -12,6 +12,16 @@
|
||||
*/
|
||||
class SP_Player extends SP_Custom_Post {
|
||||
|
||||
/**
|
||||
* Returns positions
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function positions() {
|
||||
return get_the_terms( $this->ID, 'sp_position' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current teams
|
||||
*
|
||||
|
||||
@@ -25,6 +25,7 @@ $countries = SP()->countries->countries;
|
||||
$player = new SP_Player( $id );
|
||||
|
||||
$nationality = $player->nationality;
|
||||
$positions = $player->positions();
|
||||
$current_teams = $player->current_teams();
|
||||
$past_teams = $player->past_teams();
|
||||
$metrics_before = $player->metrics( true );
|
||||
@@ -41,13 +42,13 @@ if ( $nationality ):
|
||||
$common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
||||
endif;
|
||||
|
||||
if ( $positions ):
|
||||
$position_names = array();
|
||||
$positions = get_the_terms( $id, 'sp_position' );
|
||||
if ( $positions ): foreach ( $positions as $position ):
|
||||
foreach ( $positions as $position ):
|
||||
$position_names[] = $position->name;
|
||||
endforeach; endif;
|
||||
|
||||
endforeach;
|
||||
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
|
||||
endif;
|
||||
|
||||
$data = array_merge( $metrics_before, $common, $metrics_after );
|
||||
|
||||
@@ -74,6 +75,7 @@ endif;
|
||||
|
||||
$data = apply_filters( 'sportspress_player_details', $data, $id );
|
||||
|
||||
if ( sizeof( $data ) ) {
|
||||
$output = '<div class="sp-template sp-template-player-details sp-template-details"><div class="sp-list-wrapper"><dl class="sp-player-details">';
|
||||
|
||||
foreach( $data as $label => $value ):
|
||||
@@ -85,3 +87,4 @@ endforeach;
|
||||
$output .= '</dl></div></div>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user