[wp-trac] [WordPress Trac] #11923: Allow supressing the hook in wp_print_(script|style)()

WordPress Trac wp-trac at lists.automattic.com
Sat Jan 16 10:54:14 UTC 2010


#11923: Allow supressing the hook in wp_print_(script|style)()
-------------------------+--------------------------------------------------
 Reporter:  scribu       |       Owner:  azaozz   
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  3.0      
Component:  JavaScript   |     Version:           
 Severity:  normal       |    Keywords:  has-patch
-------------------------+--------------------------------------------------
 Here's an example of what I'm currently doing:

 {{{
 class My_Shortcode {
         static $add_script;

         function init() {
                 add_shortcode('myshortcode', array(__CLASS__,
 'handle_shortcode'));
                 add_action('wp_footer', array(__CLASS__, 'add_script'));
         }

         function handle_shortcode($atts) {
                 self::$add_script = true;

                 // actual shortcode handling here
         }

         function add_script() {
                 global $wp_scripts;

                 if ( ! self::$add_script )
                         return;

                 wp_register_script('my-script', plugins_url('my-
 script.js', __FILE__), array('jquery'), '1.0', true);

                 $wp_scripts->do_items('my-script');
         }
 }

 My_Shortcode::init();
 }}}

 From [http://scribu.net/wordpress/optimal-script-loading.html here].

 It would be nice to replace

 {{{
 $wp_scripts->do_items('my-script');
 }}}

 with

 {{{
 wp_print_scripts('my-script');
 }}}

 The problem is that {{{wp_print_scripts()}}} fires the 'wp_print_scripts'
 hook, which can cause problems, like duplicate JavaScript code, etc.

 All that's needed is a way to suppress that hook, when needed.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11923>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list