mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-20 07:04:24 +09:00
Register styles in main plugin
Enqueue styles only if needed
This commit is contained in:
@@ -8,7 +8,13 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
$widget_ops = array( 'classname' => 'LatestRidesWidget', 'description' => __( 'Will publish your latest rides activity from strava.com.' ) );
|
$widget_ops = array( 'classname' => 'LatestRidesWidget', 'description' => __( 'Will publish your latest rides activity from strava.com.' ) );
|
||||||
parent::__construct( 'wp-strava', $name = 'Strava Latest Rides', $widget_ops );
|
parent::__construct( 'wp-strava', $name = 'Strava Latest Rides', $widget_ops );
|
||||||
wp_enqueue_style( 'wp-strava' ); //TODO only load this when wigit is loaded
|
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function maybe_enqueue() {
|
||||||
|
if ( is_active_widget( false, false, $this->id_base ) ) {
|
||||||
|
wp_enqueue_style( 'wp-strava-style' ); //only load this when wigit is loaded
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see WP_Widget::widget */
|
/** @see WP_Widget::widget */
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ class WPStrava_RideShortcode {
|
|||||||
|
|
||||||
static function init() {
|
static function init() {
|
||||||
add_shortcode('ride', array(__CLASS__, 'handler'));
|
add_shortcode('ride', array(__CLASS__, 'handler'));
|
||||||
|
|
||||||
add_action('init', array(__CLASS__, 'registerScripts'));
|
|
||||||
add_action('wp_footer', array(__CLASS__, 'printScripts'));
|
add_action('wp_footer', array(__CLASS__, 'printScripts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shortcode handler function
|
// Shortcode handler function
|
||||||
// [ride id=id som=metric efforts=false threshold=5 map-width="100%" map-height="400px"] tag
|
// [ride id=id som=metric map_width="100%" map_height="400px"]
|
||||||
function handler($atts) {
|
function handler($atts) {
|
||||||
self::$add_script = true;
|
self::$add_script = true;
|
||||||
|
|
||||||
@@ -72,13 +70,6 @@ class WPStrava_RideShortcode {
|
|||||||
}
|
}
|
||||||
} // handler
|
} // handler
|
||||||
|
|
||||||
static function registerScripts() {
|
|
||||||
wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
|
|
||||||
|
|
||||||
//wp_register_script('wp-strava-script', WPSTRAVA_PLUGIN_URL . 'js/wp-strava.js', array( 'jquery' ), '1.0', true);
|
|
||||||
//wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
|
|
||||||
}
|
|
||||||
|
|
||||||
static function printScripts() {
|
static function printScripts() {
|
||||||
if (self::$add_script) {
|
if (self::$add_script) {
|
||||||
wp_enqueue_style('wp-strava-style');
|
wp_enqueue_style('wp-strava-style');
|
||||||
|
|||||||
@@ -203,10 +203,6 @@ class WPStrava_Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function print_options_label() {
|
|
||||||
?><p>Options</p><?php
|
|
||||||
}
|
|
||||||
|
|
||||||
public function print_som_input() {
|
public function print_som_input() {
|
||||||
$strava_som = get_option( 'strava_som' );
|
$strava_som = get_option( 'strava_som' );
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ class WPStrava {
|
|||||||
|
|
||||||
if ( is_admin() ) {
|
if ( is_admin() ) {
|
||||||
$this->settings->hook();
|
$this->settings->hook();
|
||||||
|
} else {
|
||||||
|
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register StravaLatestRidesWidget widget
|
// Register StravaLatestRidesWidget widget
|
||||||
@@ -66,4 +68,9 @@ class WPStrava {
|
|||||||
|
|
||||||
return $this->rides;
|
return $this->rides;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function register_scripts() {
|
||||||
|
// Register a personalized stylesheet
|
||||||
|
wp_register_style( 'wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -37,15 +37,3 @@ if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) {
|
|||||||
|
|
||||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
|
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
|
||||||
$wpstrava = WPStrava::get_instance();
|
$wpstrava = WPStrava::get_instance();
|
||||||
|
|
||||||
//@TODO only load these when needed using is_active_widget()
|
|
||||||
function wpstrava_load_scripts_and_styles() {
|
|
||||||
// Register a personalized stylesheet
|
|
||||||
wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
|
|
||||||
wp_enqueue_style('wp-strava');
|
|
||||||
|
|
||||||
// Load required javascript libraries
|
|
||||||
wp_enqueue_script('jquery');
|
|
||||||
//wp_enqueue_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
|
|
||||||
}
|
|
||||||
add_action('wp_enqueue_script', 'wpstrava_load_scripts_and_styles');
|
|
||||||
|
|||||||
Reference in New Issue
Block a user