Add team option to countdown widget close #43

This commit is contained in:
Brian Miyaji
2014-08-23 19:52:51 +10:00
parent aa98f74fbc
commit 091c2a33ff
5 changed files with 64 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/
function sp_get_screen_ids() {
return apply_filters( 'sportspress_screen_ids', array(
'widgets',
'dashboard',
'dashboard_page_sp-about',
'toplevel_page_sportspress',

View File

@@ -560,6 +560,7 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) {
'property' => null,
'placeholder' => null,
'chosen' => false,
'filter' => false,
);
$args = array_merge( $defaults, $args );
@@ -586,6 +587,9 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) {
$chosen = $args['chosen'];
unset( $args['chosen'] );
$filter = $args['filter'];
unset( $args['filter'] );
$posts = get_posts( $args );
if ( $posts || $args['prepend_options'] || $args['append_options'] ):
@@ -623,7 +627,17 @@ if ( !function_exists( 'sp_dropdown_pages' ) ) {
$selected_prop = selected( $this_value, $selected, false );
endif;
printf( '<option value="%s" %s>%s</option>', $this_value, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) );
if ( $filter !== false ):
$class = 'sp-post sp-filter-0';
$filter_values = get_post_meta( $post->ID, $filter, false );
foreach ( $filter_values as $filter_value ):
$class .= ' sp-filter-' . $filter_value;
endforeach;
else:
$class = '';
endif;
printf( '<option value="%s" class="%s" %s>%s</option>', $this_value, $class, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) );
endforeach;
wp_reset_postdata();

View File

@@ -9,19 +9,21 @@ class SP_Widget_Countdown extends WP_Widget {
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base);
$team = empty($instance['team']) ? null : $instance['team'];
$id = empty($instance['id']) ? null : $instance['id'];
$show_venue = empty($instance['show_venue']) ? false : $instance['show_venue'];
$show_league = empty($instance['show_league']) ? false : $instance['show_league'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
sp_get_template( 'countdown.php', array( 'id' => $id, 'show_venue' => $show_venue, 'show_league' => $show_league ) );
sp_get_template( 'countdown.php', array( 'team' => $team, 'id' => $id, 'show_venue' => $show_venue, 'show_league' => $show_league ) );
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['team'] = intval($new_instance['team']);
$instance['id'] = intval($new_instance['id']);
$instance['show_venue'] = intval($new_instance['show_venue']);
$instance['show_league'] = intval($new_instance['show_league']);
@@ -30,8 +32,9 @@ class SP_Widget_Countdown extends WP_Widget {
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'show_venue' => false, 'show_league' => false ) );
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'team' => '', 'id' => '', 'show_venue' => false, 'show_league' => false ) );
$title = strip_tags($instance['title']);
$team = intval($instance['team']);
$id = intval($instance['id']);
$show_venue = intval($instance['show_venue']);
$show_league = intval($instance['show_league']);
@@ -39,7 +42,24 @@ class SP_Widget_Countdown extends WP_Widget {
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Event', '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
$args = array(
'post_type' => 'sp_team',
'name' => $this->get_field_name('team'),
'id' => $this->get_field_id('team'),
'selected' => $team,
'show_option_all' => __( 'All', 'sportspress' ),
'values' => 'ID',
'class' => 'widefat',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p class="sp-dropdown-target"><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Event', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_event',
@@ -51,6 +71,7 @@ class SP_Widget_Countdown extends WP_Widget {
'class' => 'widefat',
'show_dates' => true,
'post_status' => 'future',
'filter' => 'sp_team',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_event', __( 'Add New', 'sportspress' ) );