Add League Table widget and display future events
This commit is contained in:
17
admin/hooks/the-posts.php
Normal file
17
admin/hooks/the-posts.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
function sportspress_the_posts( $posts ) {
|
||||||
|
global $wp_query, $wpdb;
|
||||||
|
if( is_single() && $wp_query->post_count == 0 && isset( $wp_query->query_vars['sp_event'] ) ) {
|
||||||
|
$posts = $wpdb->get_results( $wp_query->request );
|
||||||
|
}
|
||||||
|
return $posts;
|
||||||
|
}
|
||||||
|
//add_filter( 'the_posts', 'sportspress_the_posts' );
|
||||||
|
|
||||||
|
function sportspress_posts_where( $where, $that ) {
|
||||||
|
global $wpdb;
|
||||||
|
if( 'sp_event' == $that->query_vars['post_type'] && is_archive() )
|
||||||
|
$where = str_replace( "{$wpdb->posts}.post_status = 'publish'", "{$wpdb->posts}.post_status = 'publish' OR $wpdb->posts.post_status = 'future'", $where );
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
add_filter( 'posts_where', 'sportspress_posts_where', 2, 10 );
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Register all of the default WordPress widgets on startup.
|
|
||||||
*
|
|
||||||
* Calls 'widgets_init' action after all of the WordPress widgets have been
|
|
||||||
* registered.
|
|
||||||
*
|
|
||||||
* @since 2.2.0
|
|
||||||
*/
|
|
||||||
function sportspress_widgets_init() {
|
|
||||||
|
|
||||||
register_widget('SportsPress_Widget_Calendar');
|
|
||||||
}
|
|
||||||
|
|
||||||
add_action('widgets_init', 'sportspress_widgets_init', 1);
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||||
function sportspress_events_calendar( $initial = true ) {
|
function sportspress_events_calendar( $initial = true ) {
|
||||||
|
|
||||||
global $wpdb, $m, $wp_locale, $posts;
|
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
|
||||||
|
|
||||||
// Quick check. If we have no posts at all, abort!
|
// Quick check. If we have no posts at all, abort!
|
||||||
if ( !$posts )
|
if ( !$posts )
|
||||||
@@ -12,8 +12,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
|||||||
$week_begins = intval(get_option('start_of_week'));
|
$week_begins = intval(get_option('start_of_week'));
|
||||||
|
|
||||||
// Get year and month from query vars
|
// Get year and month from query vars
|
||||||
$year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : 0;
|
$year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : $year;
|
||||||
$monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : 0;
|
$monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : $monthnum;
|
||||||
|
|
||||||
// Let's figure out when we are
|
// Let's figure out when we are
|
||||||
if ( !empty($monthnum) && !empty($year) ) {
|
if ( !empty($monthnum) && !empty($year) ) {
|
||||||
@@ -80,7 +80,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
|||||||
<tr>';
|
<tr>';
|
||||||
|
|
||||||
if ( $previous ) {
|
if ( $previous ) {
|
||||||
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ), get_permalink() ) . '" title="' . esc_attr( sprintf(__('View events for %1$s %2$s', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
|
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
|
||||||
} else {
|
} else {
|
||||||
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
|
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
|||||||
$calendar_output .= "\n\t\t".'<td class="pad"> </td>';
|
$calendar_output .= "\n\t\t".'<td class="pad"> </td>';
|
||||||
|
|
||||||
if ( $next ) {
|
if ( $next ) {
|
||||||
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ), get_permalink() ) . '" title="' . esc_attr( sprintf(__('View events for %1$s %2$s', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
|
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
|
||||||
} else {
|
} else {
|
||||||
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
|
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
class SportsPress_Widget_Calendar extends WP_Widget {
|
class SportsPress_Widget_Calendar extends WP_Widget {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$widget_ops = array('classname' => 'widget_calendar sp_widget_calendar', 'description' => __( 'A calendar of your site’s Events.') );
|
$widget_ops = array('classname' => 'widget_calendar widget_sp_calendar', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
|
||||||
parent::__construct('sp_calendar', __('Events Calendar'), $widget_ops);
|
parent::__construct('sp_calendar', __( 'Events Calendar', 'sportspress' ), $widget_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
function widget( $args, $instance ) {
|
function widget( $args, $instance ) {
|
||||||
@@ -12,7 +12,7 @@ class SportsPress_Widget_Calendar extends WP_Widget {
|
|||||||
echo $before_widget;
|
echo $before_widget;
|
||||||
if ( $title )
|
if ( $title )
|
||||||
echo $before_title . $title . $after_title;
|
echo $before_title . $title . $after_title;
|
||||||
echo '<div id="calendar_wrap sp_calendar_wrap">';
|
echo '<div id="calendar_wrap">';
|
||||||
echo sportspress_events_calendar();
|
echo sportspress_events_calendar();
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo $after_widget;
|
echo $after_widget;
|
||||||
@@ -29,8 +29,9 @@ class SportsPress_Widget_Calendar extends WP_Widget {
|
|||||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
|
||||||
$title = strip_tags($instance['title']);
|
$title = strip_tags($instance['title']);
|
||||||
?>
|
?>
|
||||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
|
<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>
|
<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>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Calendar" );' ) );
|
||||||
54
admin/widgets/table.php
Normal file
54
admin/widgets/table.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
class SportsPress_Widget_League_Table extends WP_Widget {
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
|
||||||
|
parent::__construct('sp_table', __( 'League Table', 'sportspress', 'sportspress' ), $widget_ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
function widget( $args, $instance ) {
|
||||||
|
extract($args);
|
||||||
|
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||||
|
$id = empty($instance['id']) ? null : $instance['id'];
|
||||||
|
echo $before_widget;
|
||||||
|
if ( $title )
|
||||||
|
echo $before_title . $title . $after_title;
|
||||||
|
echo '<div id="sp_league_table_wrap">';
|
||||||
|
echo sportspress_league_table( $id );
|
||||||
|
echo '</div>';
|
||||||
|
echo $after_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update( $new_instance, $old_instance ) {
|
||||||
|
$instance = $old_instance;
|
||||||
|
$instance['title'] = strip_tags($new_instance['title']);
|
||||||
|
$instance['id'] = intval($new_instance['id']);
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function form( $instance ) {
|
||||||
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '' ) );
|
||||||
|
$title = strip_tags($instance['title']);
|
||||||
|
$id = intval($instance['id']);
|
||||||
|
?>
|
||||||
|
<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>
|
||||||
|
<?php
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_table',
|
||||||
|
'name' => $this->get_field_name('id'),
|
||||||
|
'id' => $this->get_field_id('id'),
|
||||||
|
'show_option_none' => __( '-- Select --', 'sportspress' ),
|
||||||
|
'selected' => $id,
|
||||||
|
'values' => 'ID',
|
||||||
|
);
|
||||||
|
sportspress_dropdown_pages( $args );
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_League_Table" );' ) );
|
||||||
@@ -302,8 +302,8 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sportspress_the_posts' ) ) {
|
if ( !function_exists( 'sportspress_posts' ) ) {
|
||||||
function sportspress_the_posts( $post_id = null, $meta = 'post' ) {
|
function sportspress_posts( $post_id = null, $meta = 'post' ) {
|
||||||
if ( ! isset( $post_id ) )
|
if ( ! isset( $post_id ) )
|
||||||
global $post_id;
|
global $post_id;
|
||||||
$ids = get_post_meta( $post_id, $meta, false );
|
$ids = get_post_meta( $post_id, $meta, false );
|
||||||
|
|||||||
@@ -73,9 +73,9 @@ require_once dirname( __FILE__ ) . '/admin/terms/position.php';
|
|||||||
|
|
||||||
// Widgets
|
// Widgets
|
||||||
require_once dirname( __FILE__ ) . '/admin/widgets/calendar.php';
|
require_once dirname( __FILE__ ) . '/admin/widgets/calendar.php';
|
||||||
|
require_once dirname( __FILE__ ) . '/admin/widgets/table.php';
|
||||||
|
|
||||||
// Typical request actions
|
// Typical request actions
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/widgets-init.php';
|
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/plugins-loaded.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/plugins-loaded.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/after-setup-theme.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/after-setup-theme.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/wp-enqueue-scripts.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/wp-enqueue-scripts.php';
|
||||||
@@ -98,6 +98,7 @@ require_once dirname( __FILE__ ) . '/admin/hooks/save-post.php';
|
|||||||
require_once dirname( __FILE__ ) . '/admin/hooks/admin-post-thumbnail-html.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/admin-post-thumbnail-html.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/gettext.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/gettext.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/pre-get-posts.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/pre-get-posts.php';
|
||||||
|
require_once dirname( __FILE__ ) . '/admin/hooks/the-posts.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/sanitize-title.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/sanitize-title.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/the-content.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/the-content.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/hooks/wp-insert-post-data.php';
|
require_once dirname( __FILE__ ) . '/admin/hooks/wp-insert-post-data.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user