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