Add home venue option to teams

This commit is contained in:
Brian Miyaji
2014-06-26 17:59:16 +10:00
parent 2f6c8a6b8d
commit 2fccc4ec04
4 changed files with 79 additions and 1 deletions

View File

@@ -186,6 +186,11 @@ class SP_Admin_Meta_Boxes {
remove_meta_box( 'sp_leaguediv', 'sp_calendar', 'side' );
remove_meta_box( 'sp_venuediv', 'sp_calendar', 'side' );
// Teams
remove_meta_box( 'sp_leaguediv', 'sp_team', 'side' );
remove_meta_box( 'sp_seasondiv', 'sp_team', 'side' );
remove_meta_box( 'sp_venuediv', 'sp_team', 'side' );
// Tables
remove_meta_box( 'sp_seasondiv', 'sp_table', 'side' );
remove_meta_box( 'sp_leaguediv', 'sp_table', 'side' );

View File

@@ -19,9 +19,78 @@ class SP_Meta_Box_Team_Details {
* Output the metabox
*/
public static function output( $post ) {
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_ids = array();
if ( $leagues ):
foreach ( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
endif;
$seasons = get_the_terms( $post->ID, 'sp_season' );
$season_ids = array();
if ( $seasons ):
foreach ( $seasons as $season ):
$season_ids[] = $season->term_id;
endforeach;
endif;
$venues = get_the_terms( $post->ID, 'sp_venue' );
$venue_ids = array();
if ( $venues ):
foreach ( $venues as $venue ):
$venue_ids[] = $venue->term_id;
endforeach;
endif;
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$url = get_post_meta( $post->ID, 'sp_url', true );
?>
<p><strong><?php _e( 'Leagues', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Home', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]',
'selected' => $venue_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Venue', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></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>
<?php if ( $url ): ?>

View File

@@ -112,7 +112,7 @@ class SP_Post_types {
'hierarchical' => true,
'rewrite' => array( 'slug' => get_option( 'sportspress_venue_slug', 'venue' ) ),
);
$object_types = apply_filters( 'sportspress_event_object_types', array( 'sp_event', 'sp_calendar' ) );
$object_types = apply_filters( 'sportspress_event_object_types', array( 'sp_event', 'sp_calendar', 'sp_team' ) );
register_taxonomy( 'sp_venue', $object_types, $args );
foreach ( $object_types as $object_type ):
register_taxonomy_for_object_type( 'sp_venue', $object_type );

View File

@@ -457,6 +457,8 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
'chosen' => false,
);
$args = array_merge( $defaults, $args );
if ( ! $args['taxonomy'] ) return false;
$terms = get_terms( $args['taxonomy'], $args );
$name = ( $args['name'] ) ? $args['name'] : $args['taxonomy'];
$id = ( $args['id'] ) ? $args['id'] : $name;
@@ -479,6 +481,8 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
$chosen = $args['chosen'];
unset( $args['chosen'] );
printf( '<input type="hidden" name="tax_input[%s][]" value="0">', $args['taxonomy'] );
if ( $terms ):
printf( '<select name="%s" class="postform %s" %s>', $name, $class . ( $chosen ? ' chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ) : '' ), ( $placeholder != null ? 'data-placeholder="' . $placeholder . '" ' : '' ) . $property );