Add option to redirect team pages to site url

This commit is contained in:
Brian Miyaji
2017-01-05 16:52:28 +11:00
parent 2ca603e7e6
commit 1b805f7bb8
2 changed files with 17 additions and 9 deletions

View File

@@ -52,6 +52,7 @@ class SP_Meta_Box_Team_Details {
endif;
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$redirect = get_post_meta( $post->ID, 'sp_redirect', true );
$url = get_post_meta( $post->ID, 'sp_url', true );
?>
@@ -108,9 +109,7 @@ class SP_Meta_Box_Team_Details {
<p><strong><?php _e( 'Site URL', 'sportspress' ); ?></strong></p>
<p><input type="text" class="widefat" id="sp_url" name="sp_url" value="<?php echo esc_url( $url ); ?>"></p>
<?php if ( $url ): ?>
<p><a class="sp-link" title="<?php _e( 'Visit Site', 'sportspress' ); ?>" href="<?php echo $url; ?>" target="_blank"><?php _e( 'Visit Site', 'sportspress' ); ?></a></p>
<?php endif; ?>
<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( 'Abbreviation', 'sportspress' ); ?></strong></p>
<p><input type="text" id="sp_abbreviation" name="sp_abbreviation" value="<?php echo esc_attr( $abbreviation ); ?>"></p>
@@ -122,6 +121,7 @@ class SP_Meta_Box_Team_Details {
*/
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_redirect', sp_array_value( $_POST, 'sp_redirect', 0 ) );
update_post_meta( $post_id, 'sp_abbreviation', esc_attr( sp_array_value( $_POST, 'sp_abbreviation', '' ) ) );
}
}

View File

@@ -211,12 +211,20 @@ add_filter( 'gettext', 'sportspress_gettext', 20, 3 );
function sportspress_team_permalink( $permalink, $post ) {
if ( ! is_admin() && 'sp_team' == get_post_type( $post ) ):
if ( empty( $post->post_content ) ):
$url = get_post_meta( $post->ID, 'sp_url', true );
if ( ! empty( $url ) ):
return $url;
endif;
endif;
$url = get_post_meta( $post->ID, 'sp_url', true );
if ( ! empty( $url ) ):
$redirect = get_post_meta( $post->ID, 'sp_redirect', true );
if ( $redirect === '' ):
$redirect = ( empty( $post->post_content ) ) ? 1 : 0;
endif;
if ( $redirect ):
return $url;
endif;
endif;
endif;
return $permalink;
}