Add main league and current season options to secondary post types
This commit is contained in:
@@ -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_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_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) );
|
||||||
update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null ) );
|
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_orderby', sp_array_value( $_POST, 'sp_orderby', null ) );
|
||||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 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() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||||
|
|||||||
@@ -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_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_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 ) );
|
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_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_era', sp_array_value( $_POST, 'sp_era', array() ) );
|
||||||
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
|
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
|
||||||
|
|||||||
@@ -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_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_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 ) );
|
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() ) );
|
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() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,19 +225,23 @@ class SP_Calendar extends SP_Secondary_Post {
|
|||||||
$teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) );
|
$teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) );
|
||||||
$table = get_post_meta( $this->ID, 'sp_table', true );
|
$table = get_post_meta( $this->ID, 'sp_table', true );
|
||||||
|
|
||||||
if ( ! isset( $league_ids ) && $leagues ):
|
if ( ! isset( $league_ids ) ) $league_ids = array();
|
||||||
$league_ids = array();
|
if ( empty( $league_ids ) && $leagues ):
|
||||||
foreach( $leagues as $league ):
|
foreach( $leagues as $league ):
|
||||||
$league_ids[] = $league->term_id;
|
$league_ids[] = $league->term_id;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
|
$league_ids = sp_add_auto_term( $league_ids, $this->ID, 'sp_league' );
|
||||||
|
if ( empty( $league_ids ) ) unset( $league_ids );
|
||||||
|
|
||||||
if ( ! isset( $season_ids ) && $seasons ):
|
if ( ! isset( $season_ids ) ) $season_ids = array();
|
||||||
$season_ids = array();
|
if ( empty( $season_ids ) && $seasons ):
|
||||||
foreach( $seasons as $season ):
|
foreach( $seasons as $season ):
|
||||||
$season_ids[] = $season->term_id;
|
$season_ids[] = $season->term_id;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
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 ):
|
if ( ! isset( $venue_ids ) && $venues ):
|
||||||
$venue_ids = array();
|
$venue_ids = array();
|
||||||
|
|||||||
@@ -356,11 +356,15 @@ if ( !function_exists( 'sp_get_the_term_id' ) ) {
|
|||||||
if ( !function_exists( 'sp_get_the_term_ids' ) ) {
|
if ( !function_exists( 'sp_get_the_term_ids' ) ) {
|
||||||
function sp_get_the_term_ids( $post_id, $taxonomy ) {
|
function sp_get_the_term_ids( $post_id, $taxonomy ) {
|
||||||
$terms = get_the_terms( $post_id, $taxonomy );
|
$terms = get_the_terms( $post_id, $taxonomy );
|
||||||
if ( is_array( $terms ) && sizeof( $terms ) > 0 ):
|
$term_ids = array();
|
||||||
return wp_list_pluck( $terms, 'term_id' );
|
|
||||||
else:
|
if ( is_array( $terms ) && sizeof( $terms ) > 0 ) {
|
||||||
return array();
|
$term_ids = wp_list_pluck( $terms, 'term_id' );
|
||||||
endif;
|
}
|
||||||
|
|
||||||
|
$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' ) ) {
|
if ( !function_exists( 'sp_get_url' ) ) {
|
||||||
function sp_get_url( $post_id ) {
|
function sp_get_url( $post_id ) {
|
||||||
$url = get_post_meta( $post_id, 'sp_url', true );
|
$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_blank' => false,
|
||||||
'show_option_all' => false,
|
'show_option_all' => false,
|
||||||
'show_option_none' => false,
|
'show_option_none' => false,
|
||||||
|
'show_option_auto' => false,
|
||||||
'taxonomy' => null,
|
'taxonomy' => null,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'id' => null,
|
'id' => null,
|
||||||
@@ -721,6 +747,15 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
|||||||
endif;
|
endif;
|
||||||
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( '<option value="auto" ' . $selected_prop . '>%s</option>', $args['show_option_auto'] . ' ' . __( '(Auto)', 'sportspress' ) );
|
||||||
|
endif;
|
||||||
|
|
||||||
foreach ( $terms as $term ):
|
foreach ( $terms as $term ):
|
||||||
|
|
||||||
if ( $args['values'] == 'term_id' ):
|
if ( $args['values'] == 'term_id' ):
|
||||||
@@ -1437,7 +1472,24 @@ if ( !function_exists( 'sp_taxonomy_field' ) ) {
|
|||||||
$term_ids[] = $term->term_id;
|
$term_ids[] = $term->term_id;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
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(
|
$args = array(
|
||||||
|
'show_option_auto' => $auto,
|
||||||
'taxonomy' => $taxonomy,
|
'taxonomy' => $taxonomy,
|
||||||
'name' => 'tax_input[' . $taxonomy . '][]',
|
'name' => 'tax_input[' . $taxonomy . '][]',
|
||||||
'selected' => $term_ids,
|
'selected' => $term_ids,
|
||||||
|
|||||||
Reference in New Issue
Block a user