diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php index a3eaee87..b4cccfcf 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php @@ -146,6 +146,9 @@ class SP_Meta_Box_Calendar_Details { update_post_meta( $post_id, 'sp_date_future', sp_array_value( $_POST, 'sp_date_future', 0 ) ); update_post_meta( $post_id, 'sp_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) ); update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null ) ); + $tax_input = sp_array_value( $_POST, 'tax_input', array() ); + update_post_meta( $post_id, 'sp_main_league', in_array( 'auto', sp_array_value( $tax_input, 'sp_league' ) ) ); + update_post_meta( $post_id, 'sp_current_season', in_array( 'auto', sp_array_value( $tax_input, 'sp_season' ) ) ); update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', null ) ); update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', null ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php index ff19b6a6..ce11cdc3 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php @@ -166,6 +166,9 @@ class SP_Meta_Box_List_Details { update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) ); update_post_meta( $post_id, 'sp_date_past', sp_array_value( $_POST, 'sp_date_past', 0 ) ); update_post_meta( $post_id, 'sp_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) ); + $tax_input = sp_array_value( $_POST, 'tax_input', array() ); + update_post_meta( $post_id, 'sp_main_league', in_array( 'auto', sp_array_value( $tax_input, 'sp_league' ) ) ); + update_post_meta( $post_id, 'sp_current_season', in_array( 'auto', sp_array_value( $tax_input, 'sp_season' ) ) ); update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); update_post_meta( $post_id, 'sp_era', sp_array_value( $_POST, 'sp_era', array() ) ); update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) ); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php index 6e11ffe2..c24070e0 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php @@ -103,6 +103,9 @@ class SP_Meta_Box_Table_Details { update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) ); update_post_meta( $post_id, 'sp_date_past', sp_array_value( $_POST, 'sp_date_past', 0 ) ); update_post_meta( $post_id, 'sp_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) ); + $tax_input = sp_array_value( $_POST, 'tax_input', array() ); + update_post_meta( $post_id, 'sp_main_league', in_array( 'auto', sp_array_value( $tax_input, 'sp_league' ) ) ); + update_post_meta( $post_id, 'sp_current_season', in_array( 'auto', sp_array_value( $tax_input, 'sp_season' ) ) ); update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); } diff --git a/includes/class-sp-calendar.php b/includes/class-sp-calendar.php index a4824e73..b675cb76 100644 --- a/includes/class-sp-calendar.php +++ b/includes/class-sp-calendar.php @@ -225,19 +225,23 @@ class SP_Calendar extends SP_Secondary_Post { $teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) ); $table = get_post_meta( $this->ID, 'sp_table', true ); - if ( ! isset( $league_ids ) && $leagues ): - $league_ids = array(); + if ( ! isset( $league_ids ) ) $league_ids = array(); + if ( empty( $league_ids ) && $leagues ): foreach( $leagues as $league ): $league_ids[] = $league->term_id; endforeach; endif; - - if ( ! isset( $season_ids ) && $seasons ): - $season_ids = array(); + $league_ids = sp_add_auto_term( $league_ids, $this->ID, 'sp_league' ); + if ( empty( $league_ids ) ) unset( $league_ids ); + + if ( ! isset( $season_ids ) ) $season_ids = array(); + if ( empty( $season_ids ) && $seasons ): foreach( $seasons as $season ): $season_ids[] = $season->term_id; endforeach; endif; + $season_ids = sp_add_auto_term( $season_ids, $this->ID, 'sp_season' ); + if ( empty( $season_ids ) ) unset( $season_ids ); if ( ! isset( $venue_ids ) && $venues ): $venue_ids = array(); diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index e7ca9987..1a2b688b 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -356,11 +356,15 @@ if ( !function_exists( 'sp_get_the_term_id' ) ) { if ( !function_exists( 'sp_get_the_term_ids' ) ) { function sp_get_the_term_ids( $post_id, $taxonomy ) { $terms = get_the_terms( $post_id, $taxonomy ); - if ( is_array( $terms ) && sizeof( $terms ) > 0 ): - return wp_list_pluck( $terms, 'term_id' ); - else: - return array(); - endif; + $term_ids = array(); + + if ( is_array( $terms ) && sizeof( $terms ) > 0 ) { + $term_ids = wp_list_pluck( $terms, 'term_id' ); + } + + $term_ids = sp_add_auto_term( $term_ids, $post_id, $taxonomy ); + + return $term_ids; } } @@ -379,6 +383,27 @@ if ( !function_exists( 'sp_get_the_term_id_or_meta' ) ) { } } +if ( !function_exists( 'sp_add_auto_term' ) ) { + function sp_add_auto_term( $term_ids, $post_id, $taxonomy ) { + switch ( $taxonomy ) { + case 'sp_league': + if ( get_post_meta( $post_id, 'sp_main_league', true ) ) { + $term_id = get_option( 'sportspress_league', false ); + if ( $term_id ) $term_ids[] = $term_id; + } + break; + case 'sp_season': + if ( get_post_meta( $post_id, 'sp_current_season', true ) ) { + $term_id = get_option( 'sportspress_season', false ); + if ( $term_id ) $term_ids[] = $term_id; + } + break; + } + + return $term_ids; + } +} + if ( !function_exists( 'sp_get_url' ) ) { function sp_get_url( $post_id ) { $url = get_post_meta( $post_id, 'sp_url', true ); @@ -665,6 +690,7 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) { 'show_option_blank' => false, 'show_option_all' => false, 'show_option_none' => false, + 'show_option_auto' => false, 'taxonomy' => null, 'name' => null, 'id' => null, @@ -721,6 +747,15 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) { endif; endif; + if ( $args['show_option_auto'] ): + if ( strpos( $property, 'multiple' ) !== false ): + $selected_prop = in_array( 'auto', $selected ) ? 'selected' : ''; + else: + $selected_prop = selected( 'auto', $selected, false ); + endif; + printf( '', $args['show_option_auto'] . ' ' . __( '(Auto)', 'sportspress' ) ); + endif; + foreach ( $terms as $term ): if ( $args['values'] == 'term_id' ): @@ -1437,7 +1472,24 @@ if ( !function_exists( 'sp_taxonomy_field' ) ) { $term_ids[] = $term->term_id; endforeach; endif; + + // Set auto option + $auto = false; + if ( in_array( $post_type, sp_secondary_post_types() ) ) { + switch ( $taxonomy ) { + case 'sp_league': + $auto = __( 'Main League', 'sportspress' ); + if ( get_post_meta( $post->ID, 'sp_main_league', true ) ) $term_ids[] = 'auto'; + break; + case 'sp_season': + $auto = __( 'Current Season', 'sportspress' ); + if ( get_post_meta( $post->ID, 'sp_current_season', true ) ) $term_ids[] = 'auto'; + break; + } + } + $args = array( + 'show_option_auto' => $auto, 'taxonomy' => $taxonomy, 'name' => 'tax_input[' . $taxonomy . '][]', 'selected' => $term_ids,