Enable selecting date from widgets

This commit is contained in:
Brian Miyaji
2014-06-18 23:17:34 +10:00
parent 51b115377e
commit 96786dc365
5 changed files with 46 additions and 8 deletions

View File

@@ -11,13 +11,14 @@ class SP_Widget_Event_Blocks extends WP_Widget {
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$status = empty($instance['status']) ? 'default' : $instance['status'];
$date = empty($instance['date']) ? 'default' : $instance['date'];
$number = empty($instance['number']) ? null : $instance['number'];
$order = empty($instance['order']) ? 'default' : $instance['order'];
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
sp_get_template( 'event-blocks.php', array( 'id' => $id, 'status' => $status, 'number' => $number, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) );
sp_get_template( 'event-blocks.php', array( 'id' => $id, 'status' => $status, 'date' => $date, 'number' => $number, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) );
echo $after_widget;
}
@@ -26,6 +27,7 @@ class SP_Widget_Event_Blocks extends WP_Widget {
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['status'] = $new_instance['status'];
$instance['date'] = $new_instance['date'];
$instance['number'] = intval($new_instance['number']);
$instance['order'] = strip_tags($new_instance['order']);
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
@@ -34,10 +36,11 @@ class SP_Widget_Event_Blocks extends WP_Widget {
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'number' => 5, 'order' => 'default', 'show_all_events_link' => true ) );
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'date' => 'default', 'number' => 5, 'order' => 'default', 'show_all_events_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$status = $instance['status'];
$date = $instance['date'];
$number = intval($instance['number']);
$order = strip_tags($instance['order']);
$show_all_events_link = $instance['show_all_events_link'];
@@ -75,6 +78,19 @@ class SP_Widget_Event_Blocks extends WP_Widget {
?>
</p>
<p><label for="<?php echo $this->get_field_id('date'); ?>"><?php _e( 'Date:', 'sportspress' ); ?></label>
<?php
$args = array(
'show_option_default' => __( 'Default', 'sportspress' ),
'name' => $this->get_field_name('date'),
'id' => $this->get_field_id('date'),
'selected' => $date,
'class' => 'sp-event-date-select widefat',
);
sp_dropdown_dates( $args );
?>
</p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of events to show:', 'sportspress' ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>