Skip to content

Commit

Permalink
Enable multiple seasons and competitions to be selected for events, c…
Browse files Browse the repository at this point in the history
…alendars, lists, and tables.
  • Loading branch information
brianmiyaji committed Feb 16, 2015
1 parent 2b3a720 commit ed982d2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 176 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

.post-state-format.post-format-league:before, .post-format-icon.post-format-league:before, a.post-state-format.format-league:before {
content: "\f313";
content: "\f481";
}

.post-state-format.post-format-friendly:before, .post-format-icon.post-format-friendly:before, a.post-state-format.format-friendly:before {
Expand Down
2 changes: 1 addition & 1 deletion assets/css/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
content: "\f182";
}
.sp-icon-league:before {
content: "\f313";
content: "\f481";
}
.sp-icon-friendly:before {
content: "\f328";
Expand Down
16 changes: 4 additions & 12 deletions assets/js/admin/sportspress-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ jQuery(document).ready(function($){
// Activate self-cloning
$(".sp-clone:last").find("select").change();

// Dummy controller
$(".sp-has-dummy").change(function() {
val = $(this).val();
if ( val == -1 ) val = 0;
name = $(this).attr("name");
$(".sp-dummy."+name+"-dummy").val(val).trigger("change");
});

// Custom value editor
$(".sp-data-table .sp-default-value").click(function() {
$(this).hide().siblings(".sp-custom-value").show().find(".sp-custom-value-input").focus();
Expand Down Expand Up @@ -422,11 +414,11 @@ jQuery(document).ready(function($){
$(".post-type-sp_event #post-formats-select input.post-format").change(function() {
layout = $(".post-type-sp_event #post-formats-select input:checked").val();
if ( layout == "friendly" ) {
$(".sp-event-sp_league-field").hide().find("select").prop("disabled", true);
$(".sp-event-sp_season-field").show().find("select").prop("disabled", false);
$(".sp_event-sp_league-field").hide().find("select").prop("disabled", true);
$(".sp_event-sp_season-field").show().find("select").prop("disabled", false);
} else {
$(".sp-event-sp_league-field").show().find("select").prop("disabled", false);
$(".sp-event-sp_season-field").show().find("select").prop("disabled", false);
$(".sp_event-sp_league-field").show().find("select").prop("disabled", false);
$(".sp_event-sp_season-field").show().find("select").prop("disabled", false);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6
* @version 1.6.2
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
Expand All @@ -19,13 +19,11 @@ class SP_Meta_Box_Calendar_Details {
* Output the metabox
*/
public static function output( $post ) {
$taxonomies = get_object_taxonomies( 'sp_calendar' );
$status = get_post_meta( $post->ID, 'sp_status', true );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', 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 );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
?>
Expand Down Expand Up @@ -59,51 +57,11 @@ public static function output( $post ) {
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" size="10">
</p>
</div>
<p><strong><?php _e( 'Competition', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'show_option_all' => __( 'All', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $league_id,
'values' => 'term_id'
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'show_option_all' => __( 'All', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $season_id,
'values' => 'term_id'
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><strong><?php _e( 'Venue', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'show_option_all' => __( 'All', 'sportspress' ),
'taxonomy' => 'sp_venue',
'name' => 'sp_venue',
'selected' => $venue_id,
'values' => 'term_id'
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php
foreach ( $taxonomies as $taxonomy ) {
sp_taxonomy_field( $taxonomy, $post, true );
}
?>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p>
<?php
Expand Down Expand Up @@ -134,9 +92,6 @@ public static function output( $post ) {
* Save meta box data
*/
public static function save( $post_id, $post ) {
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' );
update_post_meta( $post_id, 'sp_status', sp_array_value( $_POST, 'sp_status', 0 ) );
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6
* @version 1.6.2
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
Expand All @@ -19,8 +19,8 @@ class SP_Meta_Box_Event_Details {
* Output the metabox
*/
public static function output( $post ) {
$taxonomies = get_object_taxonomies( 'sp_event' );
$minutes = get_post_meta( $post->ID, 'sp_minutes', true );
$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>
Expand All @@ -30,51 +30,48 @@ public static function output( $post ) {
</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_or_meta( $post->ID, $taxonomy ),
'values' => 'term_id',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
'chosen' => true,
);
if ( in_array( $taxonomy, apply_filters( 'sportspress_event_auto_taxonomies', array( 'sp_venue' ) ) ) ) {
$args['show_option_all'] = __( '(Auto)', 'sportspress' );
}
if ( ! sp_dropdown_taxonomies( $args ) ) {
sp_taxonomy_adder( $taxonomy, $post_type, $obj->labels->add_new_item );
}
?>
</p>
</div>
<?php
}
foreach ( $taxonomies as $taxonomy ) {
if ( 'sp_venue' == $taxonomy ) continue;
sp_taxonomy_field( $taxonomy, $post, true );
}
?>
<div class="sp-event-sp_venue-field">
<p><strong><?php _e( 'Venue', 'sportspress' ); ?></strong></p>
<p>
<?php
$terms = get_the_terms( $post->ID, 'sp_venue' );
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]',
'class' => 'sp-has-dummy',
'selected' => sp_get_the_term_id_or_meta( $post->ID, 'sp_venue' ),
'values' => 'term_id',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
'chosen' => true,
);
if ( in_array( 'sp_venue', apply_filters( 'sportspress_event_auto_taxonomies', array( 'sp_venue' ) ) ) ) {
$args['show_option_all'] = __( '(Auto)', 'sportspress' );
}
if ( ! sp_dropdown_taxonomies( $args ) ) {
sp_taxonomy_adder( 'sp_venue', 'sp_event', __( 'Add New', 'sportspress' ) );
}
?>
</p>
</div>
<?php
}

/**
* Save meta box data
*/
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 ) ) );
$taxonomies = apply_filters( 'sportspress_event_taxonomies', array( 'sp_league' => null, 'sp_season' => null, 'sp_venue' => 'sp_event' ) );
foreach ( $taxonomies as $taxonomy => $post_type ) {
$value = sp_array_value( $_POST, $taxonomy, -1 );
if ( 0 == $value) {
$teams = sp_array_value( $_POST, 'sp_team', array() );
$team = reset( $teams );
$value = sp_get_the_term_id( $team, $taxonomy );
}
wp_set_post_terms( $post_id, $value, $taxonomy );
update_post_meta( $post_id, $taxonomy, $value );
$venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) );
if ( empty( $venues ) ) {
$teams = sp_array_value( $_POST, 'sp_team', array() );
$team = reset( $teams );
$venue = sp_get_the_term_id( $team, 'sp_venue' );
wp_set_post_terms( $post_id, $venue, 'sp_venue' );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6
* @version 1.6.2
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
Expand All @@ -19,8 +19,7 @@ class SP_Meta_Box_List_Details {
* Output the metabox
*/
public static function output( $post ) {
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
$taxonomies = get_object_taxonomies( 'sp_list' );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
Expand All @@ -32,36 +31,11 @@ public static function output( $post ) {
}
?>
<div>
<p><strong><?php _e( 'Competition', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $league_id,
'values' => 'term_id',
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $season_id,
'values' => 'term_id',
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php
foreach ( $taxonomies as $taxonomy ) {
sp_taxonomy_field( $taxonomy, $post, true );
}
?>
<?php if ( apply_filters( 'sportspress_list_team_selector', true ) ) { ?>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
Expand Down Expand Up @@ -129,8 +103,6 @@ public static function output( $post ) {
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
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' );
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', array() ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6
* @version 1.6.2
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
Expand All @@ -20,45 +20,19 @@ class SP_Meta_Box_Table_Details {
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
$taxonomies = get_object_taxonomies( 'sp_table' );
$select = get_post_meta( $post->ID, 'sp_select', true );
if ( ! $select ) {
global $pagenow;
$select = ( 'post-new.php' ? 'auto' : 'manual' );
}
?>
<div>
<p><strong><?php _e( 'Competition', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $league_id,
'values' => 'term_id',
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $season_id,
'values' => 'term_id',
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php
foreach ( $taxonomies as $taxonomy ) {
sp_taxonomy_field( $taxonomy, $post, true );
}
?>
<p><strong>
<?php _e( 'Teams', 'sportspress' ); ?>
</strong></p>
Expand All @@ -80,8 +54,6 @@ public static function output( $post ) {
* Save meta box data
*/
public static function save( $post_id, $post ) {
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' );
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() ) );
}
Expand Down
Loading

0 comments on commit ed982d2

Please sign in to comment.