Changing the player information sections

Intermediate
Players
Plugin

Player page information section

So the first section that we’ll change is the player information section on the player page. If you’re using the Sports Bench theme or the player page shortcode, this is the section at the top of the page, usually with the player’s photo, name and other information. This section uses the sports_bench_player_information filter hook. Here’s the default filter for this section which you can use to help you customize the section.
function sports_bench_do_player_information( $html, $player, $team ) {
 $html .= '<div class="large-4 medium-4 small-12 columns">';
 if ( $player->get_player_photo() ) {
 $html .= '<div class="player-photo">';
 $html .= $player->get_player_photo();
 $html .= '</div>';
 } else {
 $html .= '<div class="player-photo">';
 $html .= '<img src="' . plugins_url( '../images/mystery-person.jpg', __FILE__ ) . '" alt="mystery-person" />';
 $html .= '</div>';
 }
 $html .= '</div>';

 $html .= '<div class="large-8 medium-8 small-12 columns">';
 $html .= '<h2 class="player-name">' . $player->player_first_name . ' ' . $player->player_last_name . '</h2>';
 $html .= '<h4 class="player-details">' . $player->player_position . '</h4>';
 $html .= '<h4 class="player-details">' . $team->team_name . '</h4>';
 if ( '' !== $player->player_home_city && '' !== $player->player_home_state ) {
 $html .= '<h4 class="player-details">' . $player->player_home_city . ', ' . $player->player_home_state . '</h4>';
 } elseif ( '' !== $player->player_home_city ) {
 $html .= '<h4 class="player-details">' . $player->player_home_city . '</h4>';
 } elseif ( '' !== $player->player_home_state ) {
 $html .= '<h4 class="player-details">' . $player->player_home_state . '</h4>';
 }
 if ( '' !== $player->get_age() ) {
 $html .= '<h4 class="player-details">' . __( 'Age: ', 'sports-bench' ) . $player->get_age() . '</h4>';
 }
 if ( '' !== $player->player_height && 0 < $player->player_weight ) {
 $html .= '<h4 class="player-details">' . stripslashes( $player->player_height ) . ' | ' . $player->player_weight . '</h4>';
 } elseif ( '' !== $player->player_height ) {
 $html .= '<h4 class="player-details">' . stripslashes( $player->player_height ) . '</h4>';
 } elseif ( 0 < $player->player_weight ) {
 $html .= '<h4 class="player-details">' . $player->player_weight . '</h4>';
 }
 $html .= '<h4 class="player-seasons-played">' . __( 'Seasons Played: ', 'sports-bench' ) . $player->get_seasons_played() . '</h4>';
 $html .= '<div id="sports-bench-player-id" class="hide">' . $player->player_id . '</div>';
 $html .= '</div>';

 return $html;
}
add_filter( 'sports_bench_player_information', 'sports_bench_do_player_information', 10, 3 );
You can remove this default filter so you can add your own by calling remove_action(‘sports_bench_player_information’, ‘sports_bench_do_player_information’);.

Player listing page information section

The other player information section is on the player listing page. This is the page that shows where you can select the player to view. This also has the player’s photo, name and other items. To change this, you’ll need to use the sports_bench_player_listing_information filter hook. Here’s the default usage to help you customize the player listing information section on your site.
function sports_bench_do_player_listing_information( $html, $player, $team, $num_players, $count ) {
 if ( $count % 2 == 0 ) {
 $html .= '<div class="row sports-bench-row">';
 }
 $html .= apply_filters( 'sports_bench_before_player_info', '', $team );
 $html .= '<div class="large-6 medium-6 small-12 columns">';
 $html .= '<a href="' . $player[ 'player_page' ] . '">';
 $html .= '<aside class="player-info clearfix" style="border-top: 2px solid ' . $team->team_primary_color .'">';
 $html .= '<h4 class="playername">' . $player[ 'first_name' ] . ' ' . $player[ 'last_name' ] . '</h4>';
 $html .= '<div class="right">';
 $html .= $player[ 'photo' ];
 $html .= '</div>';
 $html .= '<p>';
 $html .= $player[ 'position' ] . '<br />';
 if ( '' !== $player[ 'age' ] ) {
 $html .= $player['age'] . '<br />';
 }
 if ( '' !== $player[ 'home_city' ] && '' !== $player[ 'home_state' ] ) {
 $html .= '<h4 class="player-details">' . $player[ 'home_city' ] . ', ' . $player[ 'home_state' ] . '</h4>';
 } elseif ( '' !== $player[ 'home_city' ] ) {
 $html .= '<h4 class="player-details">' . $player[ 'home_city' ] . '</h4>';
 } elseif ( '' !== $player[ 'home_state' ] ) {
 $html .= '<h4 class="player-details">' . $player[ 'home_state' ] . '</h4>';
 }
 $html .= '</p>';
 $html .= '</aside>';
 $html .= '</a>';
 $html .= '</div>';
 $html .= apply_filters( 'sports_bench_after_player_info', '', $team );
 if ( ( $count % 2 == 1 ) or ( $count == $num_players ) ) {
 $html .= '</div>';
 }

 return $html;
}
add_filter( 'sports_bench_player_listing_information', 'sports_bench_do_player_listing_information', 10, 5 );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.