/** * Constructor * * @since 0.1.0 */ public function __construct($shortcode = '', $version = '', $atts_defaults = array()) { $this->shortcode = $shortcode; $this->atts_defaults = $atts_defaults; $this->version = $version; if (empty($this->shortcode) || empty($this->version)) { wp_die(get_class($this) . ' must have $shortcode and $version properties set and non-empty.'); } parent::__construct($this->shortcode, $this->_js_button_data(), $this->_additional_args()); remove_action('init', array($this, 'hooks')); // Since we're hooking in the Shortcode_Button hooks method later, we need to hook in the // ajax callbacks now (or they don't get fired). add_action('wp_ajax_scb_parse_shortcode', array('Shortcode_Button', 'ajax_parse_shortcode')); add_action('wp_ajax_nopriv_scb_parse_shortcode', array('Shortcode_Button', 'ajax_parse_shortcode')); }
/** * Enqueue our quicktag/general purpose button script, and localize our button data * * @since 0.1.0 */ public static function add_quicktag_button_script() { static $once = false; if ($once || !self::$scripts_url) { return; } $current_screen = get_current_screen(); if (empty(self::$buttons_data) || !isset($current_screen->parent_base) || $current_screen->parent_base != 'edit') { return; } $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script(self::$handle, self::url("js/shortcode-quicktag-button{$suffix}.js"), array('jquery', 'quicktags'), self::VERSION, true); // wp-jquery-ui-dialog css still needed as we're borrowing some dialog markup. wp_enqueue_style(self::$handle, self::url("css/shortcode-button{$suffix}.css"), array('wp-jquery-ui-dialog'), self::VERSION); wp_localize_script(self::$handle, 'shortcodeButtonsl10n', array_reverse(self::$buttons_data)); self::$buttons_data = array(); include_once self::$dir . 'templates/modal.php'; $once = true; }