[wp-hackers] wp_default_scripts unreliable?

Jason Penney jpenney at jczorkmid.net
Thu Jul 1 21:00:16 UTC 2010


My "Use Google Libraries" plugin uses the wp_default_scripts hook.  Most
of the time, this works fine.  Sometimes it seems like my plugin isn't
even installed.  wp_default_scripts fires in the constructor for
WP_Scripts.  This means that any plugin that calls the
wp_register_script or wp_enqueue_script in its main body of code
(outside of any hooks) will cause wp_default_scripts to fire, which may
be before my plugin code has been loaded.  There seem to be a lot of
these floating around.

I've worked around this by seeing if $wp_scripts has been previously
referenced (is_a($wp_scripts, 'WP_Scripts')) and forcing my action to
execute at that time if it has, but that means that other plugins can't
call remove_action on my hook to disable it in situations where there's
a need to (I know of at least one plugin that does this for mobile
device support).

Is this how wp_default_scripts is intended to work?  Any suggestions on
a better way to handle this?  I guess this would apply to
wp_default_styles as well.

Jay

-- 
Jason C Penney (jpenney at jczorkmid.net)
http://jasonpenney.net/


More information about the wp-hackers mailing list