Add "Order" and "Order by" selection fields for countdown widget

This commit is contained in:
savvasha
2021-03-31 12:38:56 +03:00
parent c4cbc5e97c
commit 775ac5cb2f
2 changed files with 33 additions and 3 deletions

View File

@@ -17,6 +17,8 @@ class SP_Widget_Countdown extends WP_Widget {
$show_league = empty($instance['show_league']) ? false : $instance['show_league']; $show_league = empty($instance['show_league']) ? false : $instance['show_league'];
$show_date = empty($instance['show_date']) ? false : $instance['show_date']; $show_date = empty($instance['show_date']) ? false : $instance['show_date'];
$show_excluded = empty($instance['show_excluded']) ? false : $instance['show_excluded']; $show_excluded = empty($instance['show_excluded']) ? false : $instance['show_excluded'];
$order = empty($instance['order']) ? false : $instance['order'];
$orderby = empty($instance['orderby']) ? false : $instance['orderby'];
do_action( 'sportspress_before_widget', $args, $instance, 'countdown' ); do_action( 'sportspress_before_widget', $args, $instance, 'countdown' );
echo $before_widget; echo $before_widget;
@@ -27,7 +29,7 @@ class SP_Widget_Countdown extends WP_Widget {
// Action to hook into // Action to hook into
do_action( 'sportspress_before_widget_template', $args, $instance, 'countdown' ); 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, 'show_excluded' => $show_excluded ) ); 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, 'order' => $order, 'orderby' => $orderby ) );
// Action to hook into // Action to hook into
do_action( 'sportspress_after_widget_template', $args, $instance, 'countdown' ); do_action( 'sportspress_after_widget_template', $args, $instance, 'countdown' );
@@ -47,6 +49,8 @@ class SP_Widget_Countdown extends WP_Widget {
$instance['show_league'] = intval($new_instance['show_league']); $instance['show_league'] = intval($new_instance['show_league']);
$instance['show_date'] = intval($new_instance['show_date']); $instance['show_date'] = intval($new_instance['show_date']);
$instance['show_excluded'] = intval($new_instance['show_excluded']); $instance['show_excluded'] = intval($new_instance['show_excluded']);
$instance['order'] = strip_tags($new_instance['order']);
$instance['orderby'] = strip_tags($new_instance['orderby']);
// Filter to hook into // Filter to hook into
$instance = apply_filters( 'sportspress_widget_update', $instance, $new_instance, $old_instance, 'countdown' ); $instance = apply_filters( 'sportspress_widget_update', $instance, $new_instance, $old_instance, 'countdown' );
@@ -55,7 +59,7 @@ class SP_Widget_Countdown extends WP_Widget {
} }
function form( $instance ) { function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'calendar' => '', 'team' => '', 'id' => '', 'caption' => '', 'show_venue' => false, 'show_league' => false, 'show_date' => false, 'show_excluded' => false ) ); $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'calendar' => '', 'team' => '', 'id' => '', 'caption' => '', 'show_venue' => false, 'show_league' => false, 'show_date' => false, 'show_excluded' => false, 'order' => '', 'orderby' => '' ) );
$title = strip_tags($instance['title']); $title = strip_tags($instance['title']);
$caption = strip_tags($instance['caption']); $caption = strip_tags($instance['caption']);
$calendar = intval($instance['calendar']); $calendar = intval($instance['calendar']);
@@ -65,6 +69,8 @@ class SP_Widget_Countdown extends WP_Widget {
$show_league = intval($instance['show_league']); $show_league = intval($instance['show_league']);
$show_date = intval($instance['show_date']); $show_date = intval($instance['show_date']);
$show_excluded = intval($instance['show_excluded']); $show_excluded = intval($instance['show_excluded']);
$order = strip_tags($instance['order']);
$orderby = strip_tags($instance['orderby']);
// Action to hook into // Action to hook into
do_action( 'sportspress_before_widget_template_form', $this, $instance, 'countdown' ); do_action( 'sportspress_before_widget_template_form', $this, $instance, 'countdown' );
@@ -91,6 +97,21 @@ class SP_Widget_Countdown extends WP_Widget {
endif; endif;
?> ?>
</p> </p>
<p class="sp-dropdown-filter"><label for="<?php echo $this->get_field_id('orderby'); ?>"><?php printf( __( 'Sort by:', 'sportspress' ) ); ?></label>
<select name="<?php echo $this->get_field_name('orderby'); ?>" class="postform widefat">
<option value="" <?php selected( 'default', $orderby ); ?>><?php _e( 'Default', 'sportspress' ); ?></option>
<option value="date" <?php selected( 'date', $orderby ); ?>><?php _e( 'Date', 'sportspress' ); ?></option>
<option value="day" <?php selected( 'day', $orderby ); ?>><?php _e( 'Match Day', 'sportspress' ); ?></option>
</select>
</p>
<p class="sp-dropdown-filter"><label for="<?php echo $this->get_field_id('order'); ?>"><?php printf( __( 'Sort Order:', 'sportspress' ) ); ?></label>
<select name="<?php echo $this->get_field_name('order'); ?>" class="postform widefat">
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
</select>
</p>
<p class="sp-dropdown-filter"><label for="<?php echo $this->get_field_id('team'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Team', 'sportspress' ) ); ?></label> <p class="sp-dropdown-filter"><label for="<?php echo $this->get_field_id('team'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Team', 'sportspress' ) ); ?></label>
<?php <?php

View File

@@ -12,6 +12,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$defaults = array( $defaults = array(
'team' => null, 'team' => null,
'calendar' => null, 'calendar' => null,
'order' => null,
'orderby' => null,
'league' => null, 'league' => null,
'season' => null, 'season' => null,
'id' => null, 'id' => null,
@@ -40,7 +42,14 @@ elseif ( $calendar ):
if ( $team ) if ( $team )
$calendar->team = $team; $calendar->team = $team;
$calendar->status = 'future'; $calendar->status = 'future';
$calendar->order = 'ASC'; if ( $order ) {
$calendar->order = $order;
}else{
$calendar->order = 'ASC';
}
if ( $orderby ) {
$calendar->orderby = $orderby;
}
$data = $calendar->data(); $data = $calendar->data();
/** /**