Add short name setting

This commit is contained in:
Brian Miyaji
2018-05-01 22:11:38 +10:00
parent d680f279f5
commit 2fb3455a53
3 changed files with 40 additions and 9 deletions

View File

@@ -51,6 +51,7 @@ class SP_Meta_Box_Team_Details {
endif; endif;
endif; endif;
$short_name = get_post_meta( $post->ID, 'sp_short_name', true );
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$redirect = get_post_meta( $post->ID, 'sp_redirect', true ); $redirect = get_post_meta( $post->ID, 'sp_redirect', true );
$url = get_post_meta( $post->ID, 'sp_url', true ); $url = get_post_meta( $post->ID, 'sp_url', true );
@@ -111,6 +112,9 @@ class SP_Meta_Box_Team_Details {
<p><input type="text" class="widefat" id="sp_url" name="sp_url" value="<?php echo esc_url( $url ); ?>"></p> <p><input type="text" class="widefat" id="sp_url" name="sp_url" value="<?php echo esc_url( $url ); ?>"></p>
<p><label class="selectit"><input type="checkbox" name="sp_redirect" value="1" <?php checked( $redirect ); ?>> <?php _e( 'Redirect', 'sportspress' ); ?></label></p> <p><label class="selectit"><input type="checkbox" name="sp_redirect" value="1" <?php checked( $redirect ); ?>> <?php _e( 'Redirect', 'sportspress' ); ?></label></p>
<p><strong><?php _e( 'Short Name', 'sportspress' ); ?></strong></p>
<p><input type="text" id="sp_short_name" name="sp_short_name" value="<?php echo esc_attr( $short_name ); ?>"></p>
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
<p><input type="text" id="sp_abbreviation" name="sp_abbreviation" value="<?php echo esc_attr( $abbreviation ); ?>"></p> <p><input type="text" id="sp_abbreviation" name="sp_abbreviation" value="<?php echo esc_attr( $abbreviation ); ?>"></p>
<?php <?php
@@ -122,6 +126,7 @@ class SP_Meta_Box_Team_Details {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_url', esc_url( sp_array_value( $_POST, 'sp_url', '' ) ) ); update_post_meta( $post_id, 'sp_url', esc_url( sp_array_value( $_POST, 'sp_url', '' ) ) );
update_post_meta( $post_id, 'sp_redirect', sp_array_value( $_POST, 'sp_redirect', 0 ) ); update_post_meta( $post_id, 'sp_redirect', sp_array_value( $_POST, 'sp_redirect', 0 ) );
update_post_meta( $post_id, 'sp_short_name', esc_attr( sp_array_value( $_POST, 'sp_short_name', '' ) ) );
update_post_meta( $post_id, 'sp_abbreviation', esc_attr( sp_array_value( $_POST, 'sp_abbreviation', '' ) ) ); update_post_meta( $post_id, 'sp_abbreviation', esc_attr( sp_array_value( $_POST, 'sp_abbreviation', '' ) ) );
} }
} }

View File

@@ -283,10 +283,6 @@ function sp_is_home_venue( $post = 0, $event = 0 ) {
} }
} }
function sp_the_abbreviation( $post = 0 ) {
echo sp_get_abbreviation( $post );
}
function sp_the_logo( $post = 0, $size = 'icon', $attr = array() ) { function sp_the_logo( $post = 0, $size = 'icon', $attr = array() ) {
echo sp_get_logo( $post, $size, $attr ); echo sp_get_logo( $post, $size, $attr );
} }
@@ -295,22 +291,35 @@ function sp_team_logo( $post = 0 ) {
sp_get_template( 'team-logo.php', array( 'id' => $post ) ); sp_get_template( 'team-logo.php', array( 'id' => $post ) );
} }
function sp_get_short_name( $post = 0 ) { function sp_team_abbreviation( $post = 0 ) {
$abbreviation = sp_get_abbreviation( $post, 'sp_abbreviation', true ); $abbreviation = get_post_meta( $post, 'sp_abbreviation', true );
if ( $abbreviation ) { if ( $abbreviation ) {
return $abbreviation; return $abbreviation;
} else {
return sp_team_short_name( $post );
}
}
function sp_the_abbreviation( $post = 0 ) {
echo sp_team_abbreviation( $post );
}
function sp_team_short_name( $post = 0 ) {
$short_name = get_post_meta( $post, 'sp_short_name', true );
if ( $short_name ) {
return $short_name;
} else { } else {
return get_the_title( $post ); return get_the_title( $post );
} }
} }
function sp_short_name( $post = 0 ) { function sp_the_short_name( $post = 0 ) {
echo sp_get_short_name( $post ); echo sp_team_short_name( $post );
} }
function sp_get_team_name( $post = 0, $short = true ) { function sp_get_team_name( $post = 0, $short = true ) {
if ( $short ) { if ( $short ) {
return sp_get_short_name( $post ); return sp_team_abbreviation( $post );
} else { } else {
return get_the_title( $post ); return get_the_title( $post );
} }

View File

@@ -203,3 +203,20 @@ if ( !function_exists( 'sp_get_player_list_data' ) ) {
return $list->data( $admin ); return $list->data( $admin );
} }
} }
if ( !function_exists( 'sp_get_short_name' ) ) {
function sp_get_short_name( $post = 0 ) {
$abbreviation = sp_get_abbreviation( $post, 'sp_abbreviation', true );
if ( $abbreviation ) {
return $abbreviation;
} else {
return get_the_title( $post );
}
}
}
if ( !function_exists( 'sp_short_name' ) ) {
function sp_short_name( $post = 0 ) {
echo sp_get_short_name( $post );
}
}