Add short name setting to teams and automate display

This commit is contained in:
Brian Miyaji
2018-05-02 12:52:01 +10:00
parent 4b6d23895b
commit bc57f39eba
18 changed files with 44 additions and 50 deletions

View File

@@ -97,7 +97,7 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
while ( is_array( $team ) ) {
$team = array_shift( array_filter( $team ) );
}
if ( $team > 0 ) $team_names[] = sp_get_short_name( $team );
if ( $team > 0 ) $team_names[] = sp_team_short_name( $team );
endforeach;
$team_names = array_unique( $team_names );

View File

@@ -62,7 +62,7 @@ class SP_Admin_CPT_Team extends SP_Admin_CPT {
'cb' => '<input type="checkbox" />',
'sp_icon' => '<span class="dashicons sp-icon-shield sp-tip" title="' . __( 'Logo', 'sportspress' ) . '"></span>',
'title' => null,
'sp_url' => __( 'URL', 'sportspress' ),
'sp_short_name' => __( 'Short Name', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
@@ -81,8 +81,9 @@ class SP_Admin_CPT_Team extends SP_Admin_CPT {
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_url':
echo strip_tags( sp_get_url( $post_id ), '<a>' );
case 'sp_short_name':
$short_name = get_post_meta ( $post_id, 'sp_short_name', true );
echo $short_name ? esc_html( $short_name ) : '&mdash;';
break;
case 'sp_abbreviation':
$abbreviation = get_post_meta ( $post_id, 'sp_abbreviation', true );

View File

@@ -58,13 +58,13 @@ class SP_Settings_Teams extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Link', 'sportspress' ),
'desc' => __( 'Link teams', 'sportspress' ),
'id' => 'sportspress_link_teams',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Link', 'sportspress' ),
'desc' => __( 'Link teams', 'sportspress' ),
'id' => 'sportspress_link_teams',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Venue', 'sportspress' ),
@@ -74,14 +74,6 @@ class SP_Settings_Teams extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Abbreviation', 'sportspress' ),
'desc' => __( 'Abbreviate team names', 'sportspress' ),
'id' => 'sportspress_abbreviate_teams',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Visit Site', 'sportspress' ),
'desc' => __( 'Open link in a new window/tab', 'sportspress' ),

View File

@@ -393,7 +393,7 @@ class SP_Event extends SP_Custom_Post{
$stats[ $index ]['number'] = sp_array_value( $player_numbers, $details['id'] );
if ( 'team' === $details['key'] ) {
$name = sp_get_team_name( $details['team'] );
$name = sp_team_short_name( $details['team'] );
$stats[ $index ]['name'] = $name;
$stats[ $index ]['label'] = $name;
$stats[ $index ]['icon'] = sp_get_logo( $details['team'] );

View File

@@ -38,7 +38,6 @@ class SP_League_Table extends SP_Secondary_Post {
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
$select = get_post_meta( $this->ID, 'sp_select', true );
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
$link_events = get_option( 'sportspress_link_events', 'yes' ) === 'yes' ? true : false;
$form_limit = (int) get_option( 'sportspress_form_limit', 5 );
@@ -702,7 +701,7 @@ class SP_League_Table extends SP_Secondary_Post {
// Add team name to row
$merged[ $team_id ] = array();
$team_data['name'] = sp_get_team_name( $team_id, $abbreviate_teams );
$team_data['name'] = sp_team_short_name( $team_id );
foreach ( $team_data as $key => $value ):

View File

@@ -115,7 +115,6 @@ class SP_Player extends SP_Custom_Post {
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
$stats = (array)get_post_meta( $this->ID, 'sp_statistics', true );
$leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
$manual_columns = 'manual' == get_option( 'sportspress_player_columns', 'auto' ) ? true : false;
// Get performance labels
@@ -581,7 +580,7 @@ class SP_Player extends SP_Custom_Post {
$season_name = sp_array_value( $season_names, $season_id, '&nbsp;' );
if ( $team_id ):
$team_name = sp_get_team_name( $team_id, $abbreviate_teams );
$team_name = sp_team_short_name( $team_id );
if ( get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false ):
$team_permalink = get_permalink( $team_id );

View File

@@ -317,9 +317,11 @@ function sp_the_short_name( $post = 0 ) {
echo sp_team_short_name( $post );
}
function sp_get_team_name( $post = 0, $short = true ) {
if ( $short ) {
function sp_team_name( $post = 0, $length = 'full' ) {
if ( 'abbreviation' == $length ) {
return sp_team_abbreviation( $post );
} elseif ( 'short' == $length ) {
return sp_team_short_name( $post );
} else {
return get_the_title( $post );
}

View File

@@ -220,3 +220,13 @@ if ( !function_exists( 'sp_short_name' ) ) {
echo sp_get_short_name( $post );
}
}
if ( !function_exists( 'sp_get_team_name' ) ) {
function sp_get_team_name( $post = 0, $short = true ) {
if ( $short ) {
return sp_team_abbreviation( $post );
} else {
return get_the_title( $post );
}
}
}

View File

@@ -30,7 +30,6 @@ $defaults = array(
'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'link_venues' => get_option( 'sportspress_link_venues', 'yes' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'no' ) == 'yes' ? true : false,
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
@@ -199,7 +198,7 @@ $identifier = uniqid( 'eventlist_' );
if ( $teams ):
foreach ( $teams as $t => $team ):
$name = sp_get_team_name( $team, $abbreviate_teams );
$name = sp_team_short_name( $team );
if ( $name ):
$name = '<meta itemprop="name" content="' . $name . '">' . $name;

View File

@@ -27,9 +27,9 @@
if ( $show_team_names ) {
if ( $j % 2 ) {
$logo .= ' <strong class="sp-team-name">' . sp_get_team_name( $team, $abbreviate_teams ) . '</strong>';
$logo .= ' <strong class="sp-team-name">' . sp_team_short_name( $team ) . '</strong>';
} else {
$logo = '<strong class="sp-team-name">' . sp_get_team_name( $team, $abbreviate_teams ) . '</strong> ' . $logo;
$logo = '<strong class="sp-team-name">' . sp_team_short_name( $team ) . '</strong> ' . $logo;
}
}

View File

@@ -21,9 +21,9 @@ foreach ( $teams as $team ):
// Add team name
if ( $show_team_names ) {
if ( $alt ) {
$logo .= ' <strong class="sp-team-name">' . sp_get_team_name( $team, $abbreviate_teams ) . '</strong>';
$logo .= ' <strong class="sp-team-name">' . sp_team_short_name( $team ) . '</strong>';
} else {
$logo = '<strong class="sp-team-name">' . sp_get_team_name( $team, $abbreviate_teams ) . '</strong> ' . $logo;
$logo = '<strong class="sp-team-name">' . sp_team_short_name( $team ) . '</strong> ' . $logo;
}
}

View File

@@ -23,7 +23,6 @@ $layout = get_option( 'sportspress_event_logos_format', 'inline' );
$show_team_names = get_option( 'sportspress_event_logos_show_team_names', 'yes' ) === 'yes' ? true : false;
$show_time = get_option( 'sportspress_event_logos_show_time', 'no' ) === 'yes' ? true : false;
$show_results = get_option( 'sportspress_event_logos_show_results', 'no' ) === 'yes' ? true : false;
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
$link_teams = get_option( 'sportspress_link_teams', 'no' ) === 'yes' ? true : false;
if ( $show_results ) {
@@ -44,7 +43,6 @@ sp_get_template( 'event-logos-' . $layout . '.php', array(
'show_team_names' => $show_team_names,
'show_time' => $show_time,
'show_results' => $show_results,
'abbreviate_teams' => $abbreviate_teams,
'link_teams' => $link_teams,
) );

View File

@@ -16,7 +16,6 @@ $show_numbers = get_option( 'sportspress_event_show_player_numbers', 'yes' ) ===
$show_position = get_option( 'sportspress_event_show_position', 'yes' ) === 'yes' ? true : false;
$show_minutes = get_option( 'sportspress_event_performance_show_minutes', 'no' ) === 'yes' ? true : false;
$sections = get_option( 'sportspress_event_performance_sections', -1 );
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
$primary = sp_get_main_performance_option();
$total = get_option( 'sportspress_event_total_performance', 'all');
@@ -226,7 +225,7 @@ if ( is_array( $teams ) ):
'show_numbers' => $show_numbers,
'show_minutes' => $show_minutes,
'show_total' => $show_total,
'caption' => 0 == $s && $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
'caption' => 0 == $s && $team_id ? sp_team_short_name( $team_id ) : null,
'labels' => $labels[ $section_id ],
'formats' => $formats,
'mode' => $mode,
@@ -263,7 +262,7 @@ if ( is_array( $teams ) ):
'show_numbers' => $show_numbers,
'show_minutes' => $show_minutes,
'show_total' => $show_total,
'caption' => $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
'caption' => $team_id ? sp_team_short_name( $team_id ) : null,
'labels' => $labels,
'formats' => $formats,
'mode' => $mode,

View File

@@ -36,7 +36,6 @@ if ( empty( $data ) )
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
$link_teams = get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false;
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
$show_outcomes = array_key_exists( 'outcome', $labels );
// Initialize
@@ -64,7 +63,7 @@ foreach( $data as $team_id => $result ):
$table_rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$team_name = sp_get_team_name( $team_id, $abbreviate_teams );
$team_name = sp_team_short_name( $team_id );
if ( $link_teams && sp_post_exists( $team_id ) ):
$team_name = '<a href="' . get_post_permalink( $team_id ) . '">' . $team_name . '</a>';

View File

@@ -23,7 +23,6 @@ $defaults = array(
'show_leagues' => get_option( 'sportspress_official_show_leagues', 'no' ) == 'yes' ? true : false,
'show_seasons' => get_option( 'sportspress_official_show_seasons', 'no' ) == 'yes' ? true : false,
'show_nationality_flags' => get_option( 'sportspress_official_show_flags', 'yes' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
);
@@ -76,7 +75,7 @@ if ( $show_current_teams ):
if ( $current_teams ):
$teams = array();
foreach ( $current_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
@@ -89,7 +88,7 @@ if ( $show_past_teams ):
if ( $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;

View File

@@ -23,7 +23,6 @@ $defaults = array(
'show_leagues' => get_option( 'sportspress_player_show_leagues', 'no' ) == 'yes' ? true : false,
'show_seasons' => get_option( 'sportspress_player_show_seasons', 'no' ) == 'yes' ? true : false,
'show_nationality_flags' => get_option( 'sportspress_player_show_flags', 'yes' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
);
@@ -76,7 +75,7 @@ if ( $show_current_teams ):
if ( $current_teams ):
$teams = array();
foreach ( $current_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
@@ -89,7 +88,7 @@ if ( $show_past_teams ):
if ( $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;

View File

@@ -24,7 +24,6 @@ $defaults = array(
'show_player_flag' => get_option( 'sportspress_list_show_flags', 'no' ) == 'yes' ? true : false,
'link_posts' => get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'no' ) == 'yes' ? true : false,
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
@@ -173,7 +172,7 @@ foreach ( $groups as $group ):
if ( array_key_exists( 'team', $labels ) ):
$team = sp_array_value( $row, 'team', get_post_meta( $id, 'sp_current_team', true ) );
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams && false !== get_post_status( $team ) ):
$team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
endif;

View File

@@ -19,7 +19,6 @@ $defaults = array(
'show_past_teams' => get_option( 'sportspress_staff_show_past_teams', 'yes' ) == 'yes' ? true : false,
'show_nationality_flags' => get_option( 'sportspress_staff_show_flags', 'yes' ) == 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
@@ -50,7 +49,7 @@ endif;
if ( $show_current_teams && $current_teams ):
$teams = array();
foreach ( $current_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
@@ -60,7 +59,7 @@ endif;
if ( $show_past_teams && $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
$team_name = sp_team_short_name( $team );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;