From 6ba028f2cf871dc12245a30c865c73504ec4d374 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 13 Apr 2016 23:59:21 +1000 Subject: [PATCH] Abbreviate team names independently --- includes/class-sp-league-table.php | 3 ++- includes/class-sp-player.php | 3 ++- includes/sp-api-functions.php | 10 +++++++++- includes/sp-template-hooks.php | 12 ------------ templates/event-list.php | 3 ++- templates/event-logos.php | 5 +++-- templates/event-performance.php | 5 +++-- templates/event-results.php | 3 ++- templates/player-details.php | 5 +++-- templates/player-list.php | 3 ++- templates/staff-details.php | 5 +++-- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index b7fc58a1..a53b5a74 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -35,6 +35,7 @@ class SP_League_Table extends SP_Custom_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; // Get labels from result variables $result_labels = (array)sp_get_var_labels( 'sp_result' ); @@ -537,7 +538,7 @@ class SP_League_Table extends SP_Custom_Post{ // Add team name to row $merged[ $team_id ] = array(); - $team_data['name'] = get_the_title( $team_id ); + $team_data['name'] = sp_get_team_name( $team_id, $abbreviate_teams ); foreach ( $team_data as $key => $value ): diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index c062e448..574082cc 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -115,6 +115,7 @@ 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; $args = array( 'post_type' => array( 'sp_performance', 'sp_statistic' ), @@ -498,7 +499,7 @@ class SP_Player extends SP_Custom_Post { $season_name = sp_array_value( $season_names, $season_id, ' ' ); if ( $team_id ): - $team_name = get_the_title( $team_id ); + $team_name = sp_get_team_name( $team_id, $abbreviate_teams ); if ( get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false ): $team_permalink = get_permalink( $team_id ); diff --git a/includes/sp-api-functions.php b/includes/sp-api-functions.php index 974ead21..4dafec60 100644 --- a/includes/sp-api-functions.php +++ b/includes/sp-api-functions.php @@ -231,7 +231,7 @@ function sp_get_logo_url( $post = 0, $size = 'icon' ) { } function sp_get_abbreviation( $post = 0 ) { - return get_post_meta ( $post, 'sp_abbreviation', true ); + return get_post_meta( $post, 'sp_abbreviation', true ); } function sp_get_venues( $post = 0, $ids = true ) { @@ -286,6 +286,14 @@ function sp_short_name( $post = 0 ) { echo sp_get_short_name( $post ); } +function sp_get_team_name( $post = 0, $short = true ) { + if ( $short ) { + return sp_get_short_name( $post ); + } else { + return get_the_title( $post ); + } +} + function sp_team_details( $post = 0 ) { sp_get_template( 'team-details.php', array( 'id' => $post ) ); } diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index cdd75def..7c4616e9 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -268,18 +268,6 @@ function sportspress_team_permalink( $permalink, $post ) { } add_filter( 'post_type_link', 'sportspress_team_permalink', 10, 2 ); -function sportspress_abbreviate_team( $title, $id = null ) { - if ( ! is_admin() && 'sp_team' == get_post_type( $id ) && get_option( 'sportspress_abbreviate_teams', 'yes' ) == 'yes' ): - if ( in_the_loop() && get_the_ID() == $id ) return $title; - $abbreviation = get_post_meta( $id, 'sp_abbreviation', true ); - if ( ! empty( $abbreviation ) ): - return $abbreviation; - endif; - endif; - return $title; -} -add_filter( 'the_title', 'sportspress_abbreviate_team', 10, 2 ); - function sportspress_no_terms_links( $term_list, $taxonomy ) { if ( in_array( $taxonomy, array( 'sp_league', 'sp_season', 'sp_position', 'sp_role' ) ) ) diff --git a/templates/event-list.php b/templates/event-list.php index efe8a522..93330587 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -24,6 +24,7 @@ $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, 'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false, 'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_event_list_paginated', 'yes' ) == 'yes' ? true : false, @@ -166,7 +167,7 @@ endif; if ( $teams ): foreach ( $teams as $team ): - $name = get_the_title( $team ); + $name = sp_get_team_name( $team, $abbreviate_teams ); if ( $name ): if ( $show_team_logo ): diff --git a/templates/event-logos.php b/templates/event-logos.php index 3b16a5be..0cd70eea 100644 --- a/templates/event-logos.php +++ b/templates/event-logos.php @@ -13,6 +13,7 @@ if ( get_option( 'sportspress_event_show_logos', 'yes' ) === 'no' ) return; $show_team_names = get_option( 'sportspress_event_logos_show_team_names', 'no' ) === '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; if ( ! isset( $id ) ) $id = get_the_ID(); @@ -43,9 +44,9 @@ if ( $teams ): // Add team name if ( $show_team_names ) { if ( $alt ) { - $logo .= ' ' . get_the_title( $team ) . ''; + $logo .= ' ' . sp_get_team_name( $team, $abbreviate_teams ) . ''; } else { - $logo = '' . get_the_title( $team ) . ' ' . $logo; + $logo = '' . sp_get_team_name( $team, $abbreviate_teams ) . ' ' . $logo; } } diff --git a/templates/event-performance.php b/templates/event-performance.php index 6cbb36f7..b0be1e95 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -15,6 +15,7 @@ $show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? tr $show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false; $show_numbers = get_option( 'sportspress_event_show_player_numbers', 'yes' ) === '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_performance_reverse_teams', 'no' ) === 'yes' ? true : false; $primary = sp_get_main_performance_option(); $total = get_option( 'sportspress_event_total_performance', 'all'); @@ -212,7 +213,7 @@ if ( is_array( $teams ) ): 'show_players' => $show_team_players, 'show_numbers' => $show_numbers, 'show_total' => $show_total, - 'caption' => 0 == $s && $team_id ? get_the_title( $team_id ) : null, + 'caption' => 0 == $s && $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null, 'labels' => $labels[ $section_id ], 'formats' => $formats, 'mode' => $mode, @@ -247,7 +248,7 @@ if ( is_array( $teams ) ): 'show_players' => $show_team_players, 'show_numbers' => $show_numbers, 'show_total' => $show_total, - 'caption' => $team_id ? get_the_title( $team_id ) : null, + 'caption' => $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null, 'labels' => $labels, 'formats' => $formats, 'mode' => $mode, diff --git a/templates/event-results.php b/templates/event-results.php index ea8774c4..506aa27b 100644 --- a/templates/event-results.php +++ b/templates/event-results.php @@ -36,6 +36,7 @@ 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 @@ -63,7 +64,7 @@ foreach( $data as $team_id => $result ): $table_rows .= ''; - $team_name = get_the_title( $team_id ); + $team_name = sp_get_team_name( $team_id, $abbreviate_teams ); if ( $link_teams ): $team_name = '' . $team_name . ''; diff --git a/templates/player-details.php b/templates/player-details.php index 3b6a134b..2f4955c6 100644 --- a/templates/player-details.php +++ b/templates/player-details.php @@ -21,6 +21,7 @@ $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, ); @@ -62,7 +63,7 @@ $data = array_merge( $metrics_before, $common, $metrics_after ); if ( $show_current_teams && $current_teams ): $teams = array(); foreach ( $current_teams as $team ): - $team_name = get_the_title( $team ); + $team_name = sp_get_team_name( $team, $abbreviate_teams ); if ( $link_teams ) $team_name = '' . $team_name . ''; $teams[] = $team_name; endforeach; @@ -72,7 +73,7 @@ endif; if ( $show_past_teams && $past_teams ): $teams = array(); foreach ( $past_teams as $team ): - $team_name = get_the_title( $team ); + $team_name = sp_get_team_name( $team, $abbreviate_teams ); if ( $link_teams ) $team_name = '' . $team_name . ''; $teams[] = $team_name; endforeach; diff --git a/templates/player-list.php b/templates/player-list.php index 980e2376..ccd41353 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -24,6 +24,7 @@ $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, 'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false, 'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_list_paginated', 'yes' ) == 'yes' ? true : false, @@ -170,7 +171,7 @@ foreach ( $groups as $group ): if ( array_key_exists( 'team', $labels ) ): $team = sp_array_value( $row, 'team', get_post_meta( $id, 'sp_team', true ) ); - $team_name = get_the_title( $team ); + $team_name = sp_get_team_name( $team, $abbreviate_teams ); if ( $link_teams ): $team_name = '' . $team_name . ''; endif; diff --git a/templates/staff-details.php b/templates/staff-details.php index 3096d247..af956b38 100644 --- a/templates/staff-details.php +++ b/templates/staff-details.php @@ -19,6 +19,7 @@ $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 ); @@ -49,7 +50,7 @@ endif; if ( $show_current_teams && $current_teams ): $teams = array(); foreach ( $current_teams as $team ): - $team_name = get_the_title( $team ); + $team_name = sp_get_team_name( $team, $abbreviate_teams ); if ( $link_teams ) $team_name = '' . $team_name . ''; $teams[] = $team_name; endforeach; @@ -59,7 +60,7 @@ endif; if ( $show_past_teams && $past_teams ): $teams = array(); foreach ( $past_teams as $team ): - $team_name = get_the_title( $team ); + $team_name = sp_get_team_name( $team, $abbreviate_teams ); if ( $link_teams ) $team_name = '' . $team_name . ''; $teams[] = $team_name; endforeach;