Last active
February 18, 2016 15:01
-
-
Save mcorkum/b66b545bcfc760feeec3 to your computer and use it in GitHub Desktop.
Plugin Script Enqueue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Carleton Gallery | |
*/ | |
/* | |
Plugin Name: Carleton Gallery | |
Plugin URI: http://carleton.ca/webservices | |
Description: Override Default WP Gallery Shortcode with something better. | |
Version: 1 | |
Author: Mike Corkum | |
Author URI: http://carleton.ca/webservices | |
License: Hi Roy! | |
Text Domain: cu-gallery | |
*/ | |
remove_shortcode( 'gallery' ); | |
class Carleton_Gallery_Override { | |
static $add_script; | |
static function init() { | |
add_shortcode('gallery', array(__CLASS__, 'handle_shortcode')); | |
add_action('init', array(__CLASS__, 'register_script')); | |
add_action('wp_footer', array(__CLASS__, 'print_script')); | |
} | |
static function handle_shortcode($atts) { | |
global $post; | |
self::$add_script = true; | |
// TODO: Handle Gallery Shortcode here | |
} | |
static function register_script() { | |
wp_register_script('gallery-script', plugins_url('gallery.js', __FILE__), array('jquery'), '1.0', true); | |
} | |
static function print_script() { | |
if ( ! self::$add_script ) | |
return; | |
wp_print_scripts('gallery-script'); | |
} | |
} | |
Carleton_Gallery_Override::init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment