Check if taxonomies exist in player and team edit screen

This commit is contained in:
Brian Miyaji
2015-09-17 17:09:44 +10:00
parent e7c010a959
commit 286e1c50d4
2 changed files with 76 additions and 50 deletions

View File

@@ -33,28 +33,34 @@ class SP_Meta_Box_Player_Details {
endif; endif;
endforeach; endforeach;
$leagues = get_the_terms( $post->ID, 'sp_league' ); if ( taxonomy_exists( 'sp_league' ) ):
$league_ids = array(); $leagues = get_the_terms( $post->ID, 'sp_league' );
if ( $leagues ): $league_ids = array();
foreach ( $leagues as $league ): if ( $leagues ):
$league_ids[] = $league->term_id; foreach ( $leagues as $league ):
endforeach; $league_ids[] = $league->term_id;
endforeach;
endif;
endif; endif;
$seasons = get_the_terms( $post->ID, 'sp_season' ); if ( taxonomy_exists( 'sp_season' ) ):
$season_ids = array(); $seasons = get_the_terms( $post->ID, 'sp_season' );
if ( $seasons ): $season_ids = array();
foreach ( $seasons as $season ): if ( $seasons ):
$season_ids[] = $season->term_id; foreach ( $seasons as $season ):
endforeach; $season_ids[] = $season->term_id;
endforeach;
endif;
endif; endif;
$positions = get_the_terms( $post->ID, 'sp_position' ); if ( taxonomy_exists( 'sp_position' ) ):
$position_ids = array(); $positions = get_the_terms( $post->ID, 'sp_position' );
if ( $positions ): $position_ids = array();
foreach ( $positions as $position ): if ( $positions ):
$position_ids[] = $position->term_id; foreach ( $positions as $position ):
endforeach; $position_ids[] = $position->term_id;
endforeach;
endif;
endif; endif;
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) ); $teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
@@ -76,20 +82,22 @@ class SP_Meta_Box_Player_Details {
<?php endforeach; ?> <?php endforeach; ?>
</select></p> </select></p>
<p><strong><?php _e( 'Positions', 'sportspress' ); ?></strong></p> <?php if ( taxonomy_exists( 'sp_position' ) ) { ?>
<p><?php <p><strong><?php _e( 'Positions', 'sportspress' ); ?></strong></p>
$args = array( <p><?php
'taxonomy' => 'sp_position', $args = array(
'name' => 'tax_input[sp_position][]', 'taxonomy' => 'sp_position',
'selected' => $position_ids, 'name' => 'tax_input[sp_position][]',
'values' => 'term_id', 'selected' => $position_ids,
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ), 'values' => 'term_id',
'class' => 'widefat', 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ),
'property' => 'multiple', 'class' => 'widefat',
'chosen' => true, 'property' => 'multiple',
); 'chosen' => true,
sp_dropdown_taxonomies( $args ); );
?></p> sp_dropdown_taxonomies( $args );
?></p>
<?php } ?>
<?php if ( apply_filters( 'sportspress_player_teams', true ) ) { ?> <?php if ( apply_filters( 'sportspress_player_teams', true ) ) { ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
@@ -123,6 +131,7 @@ class SP_Meta_Box_Player_Details {
?></p> ?></p>
<?php } ?> <?php } ?>
<?php if ( taxonomy_exists( 'sp_league' ) ) { ?>
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
<p><?php <p><?php
$args = array( $args = array(
@@ -137,7 +146,9 @@ class SP_Meta_Box_Player_Details {
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?></p> ?></p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_season' ) ) { ?>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php <p><?php
$args = array( $args = array(
@@ -152,6 +163,7 @@ class SP_Meta_Box_Player_Details {
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?></p> ?></p>
<?php } ?>
<?php <?php
} }

View File

@@ -20,33 +20,42 @@ class SP_Meta_Box_Team_Details {
*/ */
public static function output( $post ) { public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_ids = array(); if ( taxonomy_exists( 'sp_league' ) ):
if ( $leagues ): $leagues = get_the_terms( $post->ID, 'sp_league' );
foreach ( $leagues as $league ): $league_ids = array();
$league_ids[] = $league->term_id; if ( $leagues ):
endforeach; foreach ( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
endif;
endif; endif;
$seasons = get_the_terms( $post->ID, 'sp_season' ); if ( taxonomy_exists( 'sp_season' ) ):
$season_ids = array(); $seasons = get_the_terms( $post->ID, 'sp_season' );
if ( $seasons ): $season_ids = array();
foreach ( $seasons as $season ): if ( $seasons ):
$season_ids[] = $season->term_id; foreach ( $seasons as $season ):
endforeach; $season_ids[] = $season->term_id;
endforeach;
endif;
endif; endif;
$venues = get_the_terms( $post->ID, 'sp_venue' ); if ( taxonomy_exists( 'sp_venue' ) ):
$venue_ids = array(); $venues = get_the_terms( $post->ID, 'sp_venue' );
if ( $venues ): $venue_ids = array();
foreach ( $venues as $venue ): if ( $venues ):
$venue_ids[] = $venue->term_id; foreach ( $venues as $venue ):
endforeach; $venue_ids[] = $venue->term_id;
endforeach;
endif;
endif; endif;
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$url = get_post_meta( $post->ID, 'sp_url', true ); $url = get_post_meta( $post->ID, 'sp_url', true );
?> ?>
<?php if ( taxonomy_exists( 'sp_league' ) ) { ?>
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
<p><?php <p><?php
$args = array( $args = array(
@@ -61,7 +70,9 @@ class SP_Meta_Box_Team_Details {
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?></p> ?></p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_season' ) ) { ?>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php <p><?php
$args = array( $args = array(
@@ -76,7 +87,9 @@ class SP_Meta_Box_Team_Details {
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?></p> ?></p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_venue' ) ) { ?>
<p><strong><?php _e( 'Home', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Home', 'sportspress' ); ?></strong></p>
<p><?php <p><?php
$args = array( $args = array(
@@ -91,6 +104,7 @@ class SP_Meta_Box_Team_Details {
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?></p> ?></p>
<?php } ?>
<p><strong><?php _e( 'Site URL', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Site URL', 'sportspress' ); ?></strong></p>
<p><input type="text" class="widefat" id="sp_url" name="sp_url" value="<?php echo $url; ?>"></p> <p><input type="text" class="widefat" id="sp_url" name="sp_url" value="<?php echo $url; ?>"></p>