CSS only loaded when shortcode present.

This commit is contained in:
Stefan Kalscheuer 2015-09-18 11:11:40 +02:00
parent 2692f2bd0c
commit b39a577faf
5 changed files with 28 additions and 19 deletions

View File

@ -14,6 +14,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
function wplt_get_default_options() {
return array(
'enable_css' => 1,
'reset_settings' => 0 z
'reset_settings' => 0,
'shortcode_present' => false
);
}

View File

@ -8,23 +8,26 @@ if ( !defined( 'ABSPATH' ) ) exit;
/**
* Register scripts and styles
*
* @param string $page current page
*
* @return bool
*/
function wplt_enqueue_scripts( $page ) {
function wplt_register_scripts() {
// Register frontend CSS
wp_register_style( 'wplt-css', WPLT_PLUGIN_URL . 'includes/css/wp-liveticker2.css', '', WPLT_VERSION, 'all' );
}
add_action( 'init', 'wplt_register_scripts' );
/**
* Print scripts and styles if shortcode is present.
* @return bool
*/
function wplt_print_scripts() {
global $wplt_options;
// Register frontend CSS
wp_register_style( 'wplt-css', WPLT_PLUGIN_URL . 'includes/css/wp-liveticker2.css', '', '1.0', 'all' );
// Enqueue frontend CSS if option is enabled
if( $wplt_options['enable_css'] ) {
wp_enqueue_style( 'wplt-css' );
if( $wplt_options['enable_css'] && $wplt_options['shortcode_present'] ) {
wp_print_styles( 'wplt-css' );
}
}
add_action( 'wp_enqueue_scripts', 'wplt_enqueue_scripts' );
add_action( 'wp_footer', 'wplt_print_scripts' );
/**
* Register admin scripts and style

View File

@ -23,6 +23,8 @@ add_filter( 'wp_ajax_get_new_ticks', array( $this, 'wplt_ajax_get_new_ticks' ) )
function wplt_shortcode_ticker_show( $atts ) {
global $wplt_options;
$wplt_options['shortcode_present'] = true;
/*$wplt_ticker_options = array();
extract(
@ -37,7 +39,7 @@ function wplt_shortcode_ticker_show( $atts ) {
{
if(!$atts[1]) $atts[1] = -1;
$output .= '<ul class="wplt_ticker">';
$output = '<ul class="wplt_ticker">';
$args = array( 'post_type' => 'wplt_tick',
'posts_per_page' => $atts[1],

View File

@ -44,5 +44,8 @@ Use the shortcode [liveticker2 id="slug"].
== Changelog ==
= 1.0 =
+ Initial stable plugin release.
= 0.4 =
+ CSS only loaded when shortcode is called
= 0.3 =
+ Initial plugin release.

View File

@ -2,7 +2,7 @@
/**
* Plugin Name: WP Liveticker 2
* Description: A simple Liveticker for Wordpress.
* Version: 0.3 beta
* Version: 0.4 beta
* Author: Stefan Kalscheuer
* Author URI: http://www.stklblog.de
* Text Domain: wplt2
@ -34,7 +34,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
* Constants
*/
if( !defined( 'WPLT_VERSION' ) )
define( 'WPLT_VERSION', '0.1' );
define( 'WPLT_VERSION', '0.4' );
if( !defined( 'WPLT_PLUGIN_URL' ) )
define( 'WPLT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );