diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 5494603d..d904655a 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -82,6 +82,27 @@ jQuery(document).ready(function($){ // Trigger tab filter $(".sp-tab-panel").siblings(".sp-tab-select").find("select").change(); + // Dropdown filter + $(".sp-dropdown-target").siblings(".sp-dropdown-filter").find("select").change(function() { + var val = $(this).val(); + var filter = ".sp-filter-"+val; + var $filters = $(this).closest(".sp-dropdown-filter").siblings(".sp-dropdown-filter"); + if($filters.length) { + $filters.each(function() { + filterval = $(this).find("select").val(); + if(filterval !== undefined) + filter += ".sp-filter-"+filterval; + }); + } + $target = $(this).closest(".sp-dropdown-filter").siblings(".sp-dropdown-target").find("select"); + $target.find(".sp-post").prop("disabled", true).each(function() { + $(this).filter(filter).prop("disabled", false); + }); + }); + + // Trigger dropdown filter + $(".sp-dropdown-target").siblings(".sp-dropdown-filter").find("select").change(); + // Filter show all action links $(".sp-tab-panel").find(".sp-post input:checked").each(function() { $(this).prop("disabled", false).closest("li").show().siblings(".sp-not-found-container").hide().siblings(".sp-show-all-container").show(); diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index 9203a8dc..b816f713 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -17,6 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly */ function sp_get_screen_ids() { return apply_filters( 'sportspress_screen_ids', array( + 'widgets', 'dashboard', 'dashboard_page_sp-about', 'toplevel_page_sportspress', diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index f811a770..705921a7 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -560,6 +560,7 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) { 'property' => null, 'placeholder' => null, 'chosen' => false, + 'filter' => false, ); $args = array_merge( $defaults, $args ); @@ -586,6 +587,9 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) { $chosen = $args['chosen']; unset( $args['chosen'] ); + + $filter = $args['filter']; + unset( $args['filter'] ); $posts = get_posts( $args ); if ( $posts || $args['prepend_options'] || $args['append_options'] ): @@ -623,7 +627,17 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) { $selected_prop = selected( $this_value, $selected, false ); endif; - printf( '', $this_value, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) ); + if ( $filter !== false ): + $class = 'sp-post sp-filter-0'; + $filter_values = get_post_meta( $post->ID, $filter, false ); + foreach ( $filter_values as $filter_value ): + $class .= ' sp-filter-' . $filter_value; + endforeach; + else: + $class = ''; + endif; + + printf( '', $this_value, $class, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) ); endforeach; wp_reset_postdata(); diff --git a/includes/widgets/class-sp-widget-countdown.php b/includes/widgets/class-sp-widget-countdown.php index c59f9540..32f24723 100644 --- a/includes/widgets/class-sp-widget-countdown.php +++ b/includes/widgets/class-sp-widget-countdown.php @@ -9,19 +9,21 @@ class SP_Widget_Countdown extends WP_Widget { function widget( $args, $instance ) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base); + $team = empty($instance['team']) ? null : $instance['team']; $id = empty($instance['id']) ? null : $instance['id']; $show_venue = empty($instance['show_venue']) ? false : $instance['show_venue']; $show_league = empty($instance['show_league']) ? false : $instance['show_league']; echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; - sp_get_template( 'countdown.php', array( 'id' => $id, 'show_venue' => $show_venue, 'show_league' => $show_league ) ); + sp_get_template( 'countdown.php', array( 'team' => $team, 'id' => $id, 'show_venue' => $show_venue, 'show_league' => $show_league ) ); echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); + $instance['team'] = intval($new_instance['team']); $instance['id'] = intval($new_instance['id']); $instance['show_venue'] = intval($new_instance['show_venue']); $instance['show_league'] = intval($new_instance['show_league']); @@ -30,8 +32,9 @@ class SP_Widget_Countdown extends WP_Widget { } function form( $instance ) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'show_venue' => false, 'show_league' => false ) ); + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'team' => '', 'id' => '', 'show_venue' => false, 'show_league' => false ) ); $title = strip_tags($instance['title']); + $team = intval($instance['team']); $id = intval($instance['id']); $show_venue = intval($instance['show_venue']); $show_league = intval($instance['show_league']); @@ -39,7 +42,24 @@ class SP_Widget_Countdown extends WP_Widget {
-
+
+ 'sp_team', + 'name' => $this->get_field_name('team'), + 'id' => $this->get_field_id('team'), + 'selected' => $team, + 'show_option_all' => __( 'All', 'sportspress' ), + 'values' => 'ID', + 'class' => 'widefat', + ); + if ( ! sp_dropdown_pages( $args ) ): + sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); + endif; + ?> +
+ +'sp_event', @@ -51,6 +71,7 @@ class SP_Widget_Countdown extends WP_Widget { 'class' => 'widefat', 'show_dates' => true, 'post_status' => 'future', + 'filter' => 'sp_team', ); if ( ! sp_dropdown_pages( $args ) ): sp_post_adder( 'sp_event', __( 'Add New', 'sportspress' ) ); diff --git a/templates/countdown.php b/templates/countdown.php index 9e9ac084..a280e67a 100644 --- a/templates/countdown.php +++ b/templates/countdown.php @@ -10,6 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly $defaults = array( + 'team' => null, 'id' => null, 'live' => get_option( 'sportspress_enable_live_countdowns', 'yes' ) == 'yes' ? true : false, ); @@ -19,7 +20,7 @@ if ( isset( $id ) ): else: $args = array(); if ( isset( $team ) ) - $args = array( 'key' => 'sp_team', 'value' => $team ); + $args = array( array( 'key' => 'sp_team', 'value' => $team ) ); $post = sp_get_next_event( $args ); endif; @@ -66,4 +67,4 @@ if ( ! isset( $post ) ) return;
- + \ No newline at end of file