Admin dashboard widget, namespace EOS, remove unused widgets
This commit is contained in:
@@ -9,8 +9,9 @@ function sportspress_admin_enqueue_scripts( $hook ) {
|
||||
wp_enqueue_style( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL . 'assets/css/admin.css', array(), time() );
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'chosen', SPORTSPRESS_PLUGIN_URL .'assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
|
||||
wp_enqueue_script( 'caret', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
|
||||
wp_enqueue_script( 'jquery-chosen', SPORTSPRESS_PLUGIN_URL .'assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
|
||||
wp_enqueue_script( 'jquery-caret', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
|
||||
wp_enqueue_script( 'jquery-countdown', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.0.2', true );
|
||||
|
||||
if ( $hook == 'edit-tags.php' && isset( $_GET['taxonomy'] ) && $_GET['taxonomy'] == 'sp_venue' ):
|
||||
wp_enqueue_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' );
|
||||
@@ -21,6 +22,6 @@ function sportspress_admin_enqueue_scripts( $hook ) {
|
||||
wp_enqueue_script( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL .'assets/js/admin.js', array( 'jquery' ), time(), true );
|
||||
|
||||
// Localize scripts.
|
||||
wp_localize_script( 'sportspress-admin', 'localized_strings', array( 'remove_text' => __( '— Remove —', 'sportspress' ) ) );
|
||||
wp_localize_script( 'sportspress-admin', 'localized_strings', array( 'remove_text' => __( '— Remove —', 'sportspress' ), 'days' => __( 'days', 'sportspress' ), 'hrs' => __( 'hrs', 'sportspress' ), 'mins' => __( 'mins', 'sportspress' ), 'secs' => __( 'secs', 'sportspress' ) ) );
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'sportspress_admin_enqueue_scripts' );
|
||||
|
||||
@@ -35,5 +35,7 @@ function sportspress_admin_init() {
|
||||
$administrator->add_cap( $cap . '_' . $post_type . 's' );
|
||||
endforeach;
|
||||
endforeach;
|
||||
|
||||
$administrator->add_cap( 'view_sportspress_reports' );
|
||||
}
|
||||
add_action( 'admin_init', 'sportspress_admin_init' );
|
||||
|
||||
7
admin/hooks/current-screen.php
Normal file
7
admin/hooks/current-screen.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
function sportspress_current_screen() {
|
||||
$screen = get_current_screen();
|
||||
if ( $screen->id == 'dashboard' )
|
||||
include_once( dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/tools/dashboard.php' );
|
||||
}
|
||||
add_action( 'current_screen', 'sportspress_current_screen' );
|
||||
@@ -74,6 +74,8 @@ function sportspress_activation_hook() {
|
||||
'delete_sp_tables' => true,
|
||||
'delete_private_sp_tables' => true,
|
||||
'delete_published_sp_tables' => true,
|
||||
|
||||
'view_sportspress_reports' => true,
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
115
admin/tools/dashboard.php
Normal file
115
admin/tools/dashboard.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin Dashboard
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 2.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Admin_Dashboard' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Admin_Dashboard Class
|
||||
*/
|
||||
class SP_Admin_Dashboard {
|
||||
|
||||
/**
|
||||
* Hook in tabs.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Only hook in admin parts if the user has admin access
|
||||
if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_tables' ) ) {
|
||||
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init dashboard widgets
|
||||
*/
|
||||
public function init() {
|
||||
wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress Status', 'sportspress' ), array( $this, 'status_widget' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show status widget
|
||||
*/
|
||||
public function status_widget() {
|
||||
$next_event = sportspress_get_next_event();
|
||||
$now = new DateTime( current_time( 'mysql', 0 ) );
|
||||
$date = new DateTime( $next_event->post_date );
|
||||
$interval = date_diff( $now, $date );
|
||||
|
||||
$count = wp_count_posts( 'sp_event' );
|
||||
$scheduled_count = $count->future;
|
||||
$published_count = $count->publish;
|
||||
?>
|
||||
<ul class="sp_status_list">
|
||||
<?php if ( $next_event ): ?>
|
||||
<li class="countdown" data-countdown="<?php echo str_replace( '-', '/', $next_event->post_date ); ?>">
|
||||
<a href="<?php echo get_edit_post_link( $next_event->ID ); ?>">
|
||||
<?php printf( __( '<strong>%s</strong> until next event', 'sportspress' ), $interval->d . ' ' . __( 'days', 'sportspress' ) . ' ' . sprintf( '%02s:%02s:%02s', $interval->h, $interval->i, $interval->s ) ); ?>
|
||||
(<?php echo $next_event->post_title; ?>)
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li class="events-scheduled">
|
||||
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=future' ); ?>">
|
||||
<?php printf( _n( '<strong>%s event</strong> scheduled', '<strong>%s events</strong> scheduled', $scheduled_count, 'sportspress' ), $scheduled_count ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li class="events-published">
|
||||
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=publish' ); ?>">
|
||||
<?php printf( _n( '<strong>%s event</strong> published', '<strong>%s events</strong> published', $published_count, 'sportspress' ), $published_count ); ?>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Recent reviews widget
|
||||
*/
|
||||
public function recent_reviews() {
|
||||
global $wpdb;
|
||||
$comments = $wpdb->get_results( "SELECT *, SUBSTRING(comment_content,1,100) AS comment_excerpt
|
||||
FROM $wpdb->comments
|
||||
LEFT JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
|
||||
WHERE comment_approved = '1'
|
||||
AND comment_type = ''
|
||||
AND post_password = ''
|
||||
AND post_type = 'product'
|
||||
ORDER BY comment_date_gmt DESC
|
||||
LIMIT 8" );
|
||||
|
||||
if ( $comments ) {
|
||||
echo '<ul>';
|
||||
foreach ( $comments as $comment ) {
|
||||
|
||||
echo '<li>';
|
||||
|
||||
echo get_avatar( $comment->comment_author, '32' );
|
||||
|
||||
$rating = get_comment_meta( $comment->comment_ID, 'rating', true );
|
||||
|
||||
echo '<div class="star-rating" title="' . esc_attr( $rating ) . '">
|
||||
<span style="width:'. ( $rating * 20 ) . '%">' . $rating . ' ' . __( 'out of 5', 'sportspress' ) . '</span></div>';
|
||||
|
||||
echo '<h4 class="meta"><a href="' . get_permalink( $comment->ID ) . '#comment-' . absint( $comment->comment_ID ) .'">' . esc_html__( $comment->post_title ) . '</a> ' . __( 'reviewed by', 'sportspress' ) . ' ' . esc_html( $comment->comment_author ) .'</h4>';
|
||||
echo '<blockquote>' . wp_kses_data( $comment->comment_excerpt ) . ' [...]</blockquote></li>';
|
||||
|
||||
}
|
||||
echo '</ul>';
|
||||
} else {
|
||||
echo '<p>' . __( 'There are no product reviews yet.', 'sportspress' ) . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Admin_Dashboard();
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
class SportsPress_Widget_Future_Events extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_recent_entries widget_sp_future_events', 'description' => __( 'A list of upcoming events.', 'sportspress' ) );
|
||||
parent::__construct('sp_future_events', __( 'SportsPress Future Events', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Future Events' ) : $instance['title'], $instance, $this->id_base);
|
||||
$league = empty($instance['league']) ? null : $instance['league'];
|
||||
$season = empty($instance['season']) ? null : $instance['season'];
|
||||
$venue = empty($instance['venue']) ? null : $instance['venue'];
|
||||
$team = empty($instance['team']) ? null : $instance['team'];
|
||||
$number = empty($instance['number']) ? get_option( 'posts_per_page' ) : $instance['number'];
|
||||
$args = array(
|
||||
'status' => 'future',
|
||||
'league' => $league,
|
||||
'season' => $season,
|
||||
'venue' => $venue,
|
||||
'team' => $team,
|
||||
'number' => $number,
|
||||
);
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="sp_future_events_wrap">';
|
||||
echo sportspress_events( $args );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['league'] = intval($new_instance['league']);
|
||||
$instance['season'] = intval($new_instance['season']);
|
||||
$instance['venue'] = intval($new_instance['venue']);
|
||||
$instance['team'] = intval($new_instance['team']);
|
||||
$instance['number'] = intval($new_instance['number']);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'league' => '', 'season' => '', 'venue' => '', 'team' => '', 'number' => 3 ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$league = intval($instance['league']);
|
||||
$season = intval($instance['season']);
|
||||
$venue = intval($instance['venue']);
|
||||
$team = intval($instance['team']);
|
||||
$number = intval($instance['number']);
|
||||
?>
|
||||
<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('league'); ?>"><?php _e( 'League:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => $this->get_field_name('league'),
|
||||
'id' => $this->get_field_id('league'),
|
||||
'selected' => $league,
|
||||
'show_option_all' => __( 'All Leagues', 'sportspress' ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('season'); ?>"><?php _e( 'Season:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => $this->get_field_name('season'),
|
||||
'id' => $this->get_field_id('season'),
|
||||
'selected' => $season,
|
||||
'show_option_all' => __( 'All Seasons', 'sportspress' ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('venue'); ?>"><?php _e( 'Venue:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_venue',
|
||||
'name' => $this->get_field_name('venue'),
|
||||
'id' => $this->get_field_id('venue'),
|
||||
'selected' => $venue,
|
||||
'show_option_all' => __( 'All Venues', 'sportspress' ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('team'); ?>"><?php _e( '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 Teams', 'sportspress' ),
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_table', __( 'Add New League Table', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</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 $number; ?>" size="3"></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Future_Events" );' ) );
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
class SportsPress_Widget_Recent_Events extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_recent_entries widget_sp_recent_events', 'description' => __( 'A list of recent events.', 'sportspress' ) );
|
||||
parent::__construct('sp_recent_events', __( 'SportsPress Recent Events', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Recent Events' ) : $instance['title'], $instance, $this->id_base);
|
||||
$league = empty($instance['league']) ? null : $instance['league'];
|
||||
$season = empty($instance['season']) ? null : $instance['season'];
|
||||
$venue = empty($instance['venue']) ? null : $instance['venue'];
|
||||
$team = empty($instance['team']) ? null : $instance['team'];
|
||||
$number = empty($instance['number']) ? get_option( 'posts_per_page' ) : $instance['number'];
|
||||
$args = array(
|
||||
'status' => 'publish',
|
||||
'league' => $league,
|
||||
'season' => $season,
|
||||
'venue' => $venue,
|
||||
'team' => $team,
|
||||
'number' => $number,
|
||||
);
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="sp_recent_events_wrap">';
|
||||
echo sportspress_events( $args );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['league'] = intval($new_instance['league']);
|
||||
$instance['season'] = intval($new_instance['season']);
|
||||
$instance['venue'] = intval($new_instance['venue']);
|
||||
$instance['team'] = intval($new_instance['team']);
|
||||
$instance['number'] = intval($new_instance['number']);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'league' => '', 'season' => '', 'venue' => '', 'team' => '', 'number' => 3 ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$league = intval($instance['league']);
|
||||
$season = intval($instance['season']);
|
||||
$venue = intval($instance['venue']);
|
||||
$team = intval($instance['team']);
|
||||
$number = intval($instance['number']);
|
||||
?>
|
||||
<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('league'); ?>"><?php _e( 'League:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => $this->get_field_name('league'),
|
||||
'id' => $this->get_field_id('league'),
|
||||
'selected' => $league,
|
||||
'show_option_all' => __( 'All Leagues', 'sportspress' ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('season'); ?>"><?php _e( 'Season:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => $this->get_field_name('season'),
|
||||
'id' => $this->get_field_id('season'),
|
||||
'selected' => $season,
|
||||
'show_option_all' => __( 'All Seasons', 'sportspress' ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('venue'); ?>"><?php _e( 'Venue:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_venue',
|
||||
'name' => $this->get_field_name('venue'),
|
||||
'id' => $this->get_field_id('venue'),
|
||||
'selected' => $venue,
|
||||
'show_option_all' => __( 'All Venues', 'sportspress' ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('team'); ?>"><?php _e( '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 Teams', 'sportspress' ),
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_table', __( 'Add New League Table', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</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 $number; ?>" size="3"></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Recent_Events" );' ) );
|
||||
Reference in New Issue
Block a user