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 );
}
}
}