From caf57891bb805cb25252c18dd94716564be08c96 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 27 Apr 2014 19:04:50 +1000 Subject: [PATCH] Enable event status selector in event list widget --- includes/class-sp-calendar.php | 30 +++++++++++++++---- includes/sp-core-functions.php | 5 ++++ .../widgets/class-sp-widget-event-list.php | 21 +++++++++++-- templates/event-list.php | 3 ++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/includes/class-sp-calendar.php b/includes/class-sp-calendar.php index 97d6d35f..143539b1 100644 --- a/includes/class-sp-calendar.php +++ b/includes/class-sp-calendar.php @@ -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' ), diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index d5dd41c5..bd58ffb8 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -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( '

-


'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 ); status = $status; $data = $calendar->data(); $usecolumns = $calendar->columns;