Enqueue admin scripts and styles in class
This commit is contained in:
115
includes/admin/class-sp-admin-assets.php
Normal file
115
includes/admin/class-sp-admin-assets.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Load assets.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Admin_Assets' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Admin_Assets Class
|
||||
*/
|
||||
class SP_Admin_Assets {
|
||||
|
||||
/**
|
||||
* Hook in tabs.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles
|
||||
*/
|
||||
public function admin_styles() {
|
||||
global $wp_scripts;
|
||||
|
||||
// Sitewide menu CSS
|
||||
wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION );
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
|
||||
|
||||
// Admin styles for SP pages only
|
||||
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . 'assets/css/admin.css', array(), SP_VERSION );
|
||||
wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . 'assets/css/chosen.css', array(), '1.1.0' );
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
}
|
||||
|
||||
if ( in_array( $screen->id, array( 'dashboard' ) ) ) {
|
||||
wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION );
|
||||
}
|
||||
|
||||
do_action( 'sportspress_admin_css' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts
|
||||
*/
|
||||
public function admin_scripts() {
|
||||
global $wp_query, $post;
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
// Register scripts
|
||||
wp_register_script( 'jquery-chosen', SP()->plugin_url() .'assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
|
||||
|
||||
wp_register_script( 'jquery-tiptip', SP()->plugin_url() .'assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true );
|
||||
|
||||
wp_register_script( 'jquery-caret', SP()->plugin_url() .'assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
|
||||
|
||||
wp_register_script( 'jquery-countdown', SP()->plugin_url() .'assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.0.2', true );
|
||||
|
||||
wp_register_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' );
|
||||
|
||||
wp_register_script( 'jquery-locationpicker', SP()->plugin_url() .'assets/js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true );
|
||||
|
||||
wp_register_script( 'sportspress-admin-locationpicker', SP()->plugin_url() .'assets/js/admin-locationpicker.js', array( 'jquery', 'google-maps', 'jquery-locationpicker' ), SP_VERSION, true );
|
||||
|
||||
wp_register_script( 'sportspress-admin', SP()->plugin_url() .'assets/js/admin.js', array( 'jquery', 'jquery-chosen', 'jquery-tiptip', 'jquery-caret', 'jquery-countdown' ), SP_VERSION, true );
|
||||
|
||||
// SportsPress admin pages
|
||||
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'jquery-chosen' );
|
||||
wp_enqueue_script( 'jquery-tiptip' );
|
||||
wp_enqueue_script( 'jquery-caret' );
|
||||
wp_enqueue_script( 'jquery-countdown' );
|
||||
wp_enqueue_script( 'sportspress-admin' );
|
||||
|
||||
$params = array(
|
||||
'none' => __( 'None', 'sportspress' ),
|
||||
'remove_text' => __( '— Remove —', 'sportspress' ),
|
||||
'days' => __( 'days', 'sportspress' ),
|
||||
'hrs' => __( 'hrs', 'sportspress' ),
|
||||
'mins' => __( 'mins', 'sportspress' ),
|
||||
'secs' => __( 'secs', 'sportspress' )
|
||||
);
|
||||
|
||||
// Localize scripts
|
||||
wp_localize_script( 'sportspress-admin', 'localized_strings', $params );
|
||||
}
|
||||
|
||||
// Edit venue pages
|
||||
if ( in_array( $screen->id, array( 'edit-sp_venue' ) ) ) {
|
||||
|
||||
wp_enqueue_script( 'google-maps' );
|
||||
wp_enqueue_script( 'jquery-locationpicker' );
|
||||
wp_enqueue_script( 'sportspress-admin-locationpicker' );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Admin_Assets();
|
||||
@@ -30,7 +30,7 @@ class SP_Admin {
|
||||
*/
|
||||
public function includes() {
|
||||
// Functions
|
||||
// include_once( 'sp-admin-functions.php' );
|
||||
include_once( 'sp-admin-functions.php' );
|
||||
// include_once( 'sp-meta-box-functions.php' );
|
||||
|
||||
// Classes
|
||||
@@ -42,7 +42,7 @@ class SP_Admin {
|
||||
// include( 'class-sp-admin-menus.php' );
|
||||
// include( 'class-sp-admin-welcome.php' );
|
||||
// include( 'class-sp-admin-notices.php' );
|
||||
// include( 'class-sp-admin-assets.php' );
|
||||
include( 'class-sp-admin-assets.php' );
|
||||
// include( 'class-sp-admin-permalink-settings.php' );
|
||||
// include( 'class-sp-admin-editor.php' );
|
||||
|
||||
|
||||
51
includes/admin/sp-admin-functions.php
Normal file
51
includes/admin/sp-admin-functions.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Admin Functions
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Core
|
||||
* @package SportsPress/Admin/Functions
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* Get all SportsPress screen ids
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function sp_get_screen_ids() {
|
||||
return apply_filters( 'sportspress_screen_ids', array(
|
||||
'edit-sp_result',
|
||||
'sp_result',
|
||||
'edit-sp_outcome',
|
||||
'sp_outcome',
|
||||
'edit-sp_performance',
|
||||
'sp_performance',
|
||||
'edit-sp_column',
|
||||
'sp_column',
|
||||
'edit-sp_metric',
|
||||
'sp_metric',
|
||||
'edit-sp_statistic',
|
||||
'sp_statistic',
|
||||
'edit-sp_event',
|
||||
'sp_event',
|
||||
'edit-sp_calendar',
|
||||
'sp_calendar',
|
||||
'edit-sp_team',
|
||||
'sp_team',
|
||||
'edit-sp_table',
|
||||
'sp_table',
|
||||
'edit-sp_player',
|
||||
'sp_player',
|
||||
'edit-sp_list',
|
||||
'sp_list',
|
||||
'edit-sp_staff',
|
||||
'sp_staff',
|
||||
'edit-sp_venue',
|
||||
'edit-sp_league',
|
||||
'edit-sp_season',
|
||||
'edit-sp_position',
|
||||
) );
|
||||
}
|
||||
Reference in New Issue
Block a user