Add an option to Countdown widget to show Excluded (i.e. cancelled, postponed) events.

This commit is contained in:
savvasha
2020-04-12 13:32:11 +03:00
parent ec00d7d74b
commit 9f2888fd45
2 changed files with 26 additions and 10 deletions

View File

@@ -16,6 +16,7 @@ class SP_Widget_Countdown extends WP_Widget {
$show_venue = empty($instance['show_venue']) ? false : $instance['show_venue'];
$show_league = empty($instance['show_league']) ? false : $instance['show_league'];
$show_date = empty($instance['show_date']) ? false : $instance['show_date'];
$show_excluded = empty($instance['show_excluded']) ? false : $instance['show_excluded'];
do_action( 'sportspress_before_widget', $args, $instance, 'countdown' );
echo $before_widget;
@@ -26,7 +27,7 @@ class SP_Widget_Countdown extends WP_Widget {
// Action to hook into
do_action( 'sportspress_before_widget_template', $args, $instance, 'countdown' );
sp_get_template( 'countdown.php', array( 'calendar' => $calendar, 'team' => $team, 'id' => $id, 'title' => $caption, 'show_venue' => $show_venue, 'show_league' => $show_league, 'show_date' => $show_date ) );
sp_get_template( 'countdown.php', array( 'calendar' => $calendar, 'team' => $team, 'id' => $id, 'title' => $caption, 'show_venue' => $show_venue, 'show_league' => $show_league, 'show_date' => $show_date, 'show_excluded' => $show_excluded ) );
// Action to hook into
do_action( 'sportspress_after_widget_template', $args, $instance, 'countdown' );
@@ -45,6 +46,7 @@ class SP_Widget_Countdown extends WP_Widget {
$instance['show_venue'] = intval($new_instance['show_venue']);
$instance['show_league'] = intval($new_instance['show_league']);
$instance['show_date'] = intval($new_instance['show_date']);
$instance['show_excluded'] = intval($new_instance['show_excluded']);
// Filter to hook into
$instance = apply_filters( 'sportspress_widget_update', $instance, $new_instance, $old_instance, 'countdown' );
@@ -62,6 +64,7 @@ class SP_Widget_Countdown extends WP_Widget {
$show_venue = intval($instance['show_venue']);
$show_league = intval($instance['show_league']);
$show_date = intval($instance['show_date']);
$show_excluded = intval($instance['show_excluded']);
// Action to hook into
do_action( 'sportspress_before_widget_template_form', $this, $instance, 'countdown' );
@@ -135,6 +138,9 @@ class SP_Widget_Countdown extends WP_Widget {
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_date'); ?>" name="<?php echo $this->get_field_name('show_date'); ?>" value="1" <?php checked( $show_date, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_date'); ?>"><?php _e( 'Display date', 'sportspress' ); ?></label></p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_excluded'); ?>" name="<?php echo $this->get_field_name('show_excluded'); ?>" value="1" <?php checked( $show_excluded, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_excluded'); ?>"><?php _e( 'Display excluded events', 'sportspress' ); ?></label></p>
<?php
// Action to hook into
do_action( 'sportspress_after_widget_template_form', $this, $instance, 'countdown' );

View File

@@ -23,6 +23,16 @@ $defaults = array(
'show_logos' => get_option( 'sportspress_countdown_show_logos', 'no' ) == 'yes' ? true : false,
'show_thumbnail' => get_option( 'sportspress_countdown_show_thumbnail', 'no' ) == 'yes' ? true : false,
);
if ( isset( $show_excluded ) && $show_excluded ){
$excluded_statuses = array();
}else{
$excluded_statuses = apply_filters( 'sp_countdown_excluded_statuses', array(
'postponed',
'cancelled',
) );
}
if ( isset( $id ) ):
$post = get_post( $id );
elseif ( $calendar ):
@@ -36,10 +46,6 @@ elseif ( $calendar ):
/**
* Exclude postponed or cancelled events.
*/
$excluded_statuses = apply_filters( 'sp_countdown_excluded_statuses', array(
'postponed',
'cancelled',
) );
while ( $post = array_shift( $data ) ) {
$sp_status = get_post_meta($post->ID, 'sp_status', true);
if( ! in_array( $sp_status, $excluded_statuses ) ) {
@@ -80,10 +86,7 @@ else:
$args['meta_query'][] = [
'key' => 'sp_status',
'compare' => 'NOT IN',
'value' => apply_filters( 'sp_countdown_excluded_statuses', array(
'postponed',
'cancelled',
) ),
'value' => $excluded_statuses,
];
$post = sp_get_next_event( $args );
@@ -98,6 +101,13 @@ if ( $title )
$title = $post->post_title;
if ( $link_events ) $title = '<a href="' . get_post_permalink( $post->ID, false, true ) . '">' . $title . '</a>';
$sp_status = get_post_meta($post->ID, 'sp_status', true);
$statuses = apply_filters( 'sportspress_event_statuses', array(
'ok' => __( 'On time', 'sportspress' ),
'tbd' => __( 'TBD', 'sportspress' ),
'postponed' => __( 'Postponed', 'sportspress' ),
'cancelled' => __( 'Canceled', 'sportspress' ),
) );
?>
<div class="sp-template sp-template-countdown">
<div class="sp-countdown-wrapper">
@@ -128,7 +138,7 @@ if ( $link_events ) $title = '<a href="' . get_post_permalink( $post->ID, false,
}
}
?>
<?php echo $title; ?>
<?php echo $title.' ('.$statuses[ $sp_status ].')'; ?>
</h3>
<?php
if ( isset( $show_date ) && $show_date ):