Automate event details dropdowns

This commit is contained in:
Brian Miyaji
2014-09-05 17:40:50 +10:00
parent 5f543949a9
commit b50855798d

View File

@@ -20,9 +20,7 @@ class SP_Meta_Box_Event_Details {
*/ */
public static function output( $post ) { public static function output( $post ) {
$minutes = get_post_meta( $post->ID, 'sp_minutes', true ); $minutes = get_post_meta( $post->ID, 'sp_minutes', true );
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 ); $taxonomies = apply_filters( 'sportspress_event_taxonomies', array( 'sp_league' => null, 'sp_season' => null, 'sp_venue' => 'sp_event' ) );
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
$venue_id = sp_get_the_term_id( $post->ID, 'sp_venue', 0 );
?> ?>
<div class="sp-event-minutes-field"> <div class="sp-event-minutes-field">
<p><strong><?php _e( 'Full Time', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Full Time', 'sportspress' ); ?></strong></p>
@@ -31,59 +29,26 @@ class SP_Meta_Box_Event_Details {
<?php _e( 'mins', 'sportspress' ); ?> <?php _e( 'mins', 'sportspress' ); ?>
</p> </p>
</div> </div>
<div class="sp-event-league-field"> <?php foreach ( $taxonomies as $taxonomy => $post_type ): $obj = get_taxonomy( $taxonomy ); if ( $obj ): ?>
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p> <div class="sp-event-<?php echo $taxonomy; ?>-field">
<p> <p><strong><?php echo $obj->labels->singular_name; ?></strong></p>
<?php <p>
$args = array( <?php
'taxonomy' => 'sp_league', $args = array(
'name' => 'sp_league', 'taxonomy' => $taxonomy,
'class' => 'sp-has-dummy', 'name' => $taxonomy,
'selected' => $league_id, 'class' => 'sp-has-dummy',
'values' => 'term_id', 'selected' => sp_get_the_term_id( $post->ID, $taxonomy, 0 ),
'show_option_none' => __( '-- Not set --', 'sportspress' ), 'values' => 'term_id',
); 'show_option_none' => __( '-- Not set --', 'sportspress' ),
if ( ! sp_dropdown_taxonomies( $args ) ): );
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) ); if ( ! sp_dropdown_taxonomies( $args ) ):
endif; sp_taxonomy_adder( $taxonomy, $post_type, $obj->labels->add_new_item );
?> endif;
</p> ?>
</div> </p>
<div class="sp-event-season-field"> </div>
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p> <?php endif; endforeach; ?>
<p>
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'class' => 'sp-has-dummy',
'selected' => $season_id,
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
</div>
<div class="sp-event-venue-field">
<p><strong><?php _e( 'Venue', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'sp_venue',
'selected' => $venue_id,
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_venue', 'sp_event', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
</div>
<?php <?php
} }
@@ -92,12 +57,9 @@ class SP_Meta_Box_Event_Details {
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ) ) ); update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ) ) );
$format = get_post_meta( $post_id, 'sp_format', true ); $taxonomies = apply_filters( 'sportspress_event_taxonomies', array( 'sp_league' => null, 'sp_season' => null, 'sp_venue' => 'sp_event' ) );
if ( $format == 'friendly' ) foreach ( $taxonomies as $taxonomy => $post_type ):
wp_set_post_terms( $post_id, -1, 'sp_league' ); wp_set_post_terms( $post_id, sp_array_value( $_POST, $taxonomy, -1 ), $taxonomy );
else endforeach;
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' );
} }
} }