Enable event status selector in event list widget

This commit is contained in:
Brian Miyaji
2014-04-27 19:04:50 +10:00
parent dbb63247fd
commit caf57891bb
4 changed files with 51 additions and 8 deletions

View File

@@ -12,6 +12,30 @@
*/
class SP_Calendar extends SP_Custom_Post {
/** @var array The events status. */
public $status;
/**
* __construct function.
*
* @access public
* @param mixed $post
*/
public function __construct( $post ) {
if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ):
$this->ID = absint( $post->ID );
$this->post = $post;
else:
$this->ID = absint( $post );
$this->post = get_post( $this->ID );
endif;
$this->status = $this->__get( 'status' );
if ( ! $this->status )
$this->status = 'any';
}
/**
* Returns formatted data
*
@@ -21,17 +45,13 @@ class SP_Calendar extends SP_Custom_Post {
public function data() {
global $pagenow;
$post_status = $this->status;
if ( ! $post_status )
$post_status = 'any';
$args = array(
'post_type' => 'sp_event',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'post_date',
'order' => 'ASC',
'post_status' => $post_status,
'post_status' => $this->status,
'tax_query' => array(
'relation' => 'AND'
),

View File

@@ -378,6 +378,7 @@ if ( !function_exists( 'sp_get_post_order' ) ) {
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
function sp_dropdown_statuses( $args = array() ) {
$defaults = array(
'show_option_default' => false,
'name' => 'sp_status',
'id' => null,
'selected' => null,
@@ -387,6 +388,10 @@ if ( !function_exists( 'sp_dropdown_statuses' ) ) {
printf( '<select name="%s" class="postform %s">', $args['name'], $args['class'] );
if ( $args['show_option_default'] ):
printf( '<option value="default">%s</option>', $args['show_option_default'] );
endif;
$statuses = apply_filters( 'sportspress_statuses', array(
'any' => __( 'All', 'sportspress' ),
'publish' => __( 'Published', 'sportspress' ),

View File

@@ -10,13 +10,14 @@ class SP_Widget_Event_List extends WP_Widget {
extract($args);
$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'];
$number = empty($instance['number']) ? null : $instance['number'];
$columns = empty($instance['columns']) ? null : $instance['columns'];
$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-list.php', array( 'id' => $id, 'number' => $number, 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
sp_get_template( 'event-list.php', array( 'id' => $id, 'status' => $status, 'number' => $number, 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
echo $after_widget;
}
@@ -24,6 +25,7 @@ class SP_Widget_Event_List extends WP_Widget {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['status'] = $new_instance['status'];
$instance['number'] = intval($new_instance['number']);
$instance['columns'] = (array)$new_instance['columns'];
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
@@ -32,9 +34,10 @@ class SP_Widget_Event_List extends WP_Widget {
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'number' => 5, 'columns' => null, 'show_all_events_link' => true ) );
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'number' => 5, 'columns' => null, 'show_all_events_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$status = $instance['status'];
$number = intval($instance['number']);
$columns = $instance['columns'];
$show_all_events_link = $instance['show_all_events_link'];
@@ -59,10 +62,22 @@ class SP_Widget_Event_List extends WP_Widget {
?>
</p>
<p><label for="<?php echo $this->get_field_id('status'); ?>"><?php _e( 'Status:', 'sportspress' ); ?></label>
<?php
$args = array(
'show_option_default' => __( 'Default', 'sportspress' ),
'name' => $this->get_field_name('status'),
'id' => $this->get_field_id('status'),
'selected' => $status,
'class' => 'sp-event-status-select widefat',
);
sp_dropdown_statuses( $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>
<p class="sp-prefs">
<?php _e( 'Columns:', 'sportspress' ); ?><br>
<?php

View File

@@ -12,6 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$primary_result = get_option( 'sportspress_primary_result', null );
$defaults = array(
'status' => 'default',
'number' => -1,
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false,
@@ -28,6 +29,8 @@ extract( $defaults, EXTR_SKIP );
<tr>
<?php
$calendar = new SP_Calendar( $id );
if ( $status != 'default' )
$calendar->status = $status;
$data = $calendar->data();
$usecolumns = $calendar->columns;