Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Scenario: It is common that a JS dependency is bundled with a style file to work properly (just think about your favorite slideshow jQuery plugin). AFAIK, in this situation, the script and style have to be included in separate wp_enqueue_script and wp_enqueue_style calls.

I am thinking about how to automate this process.

A solution I could come about is to declare the configuration in a .json file in which an entry looks like this:

"jquery-plugin": ["static/js/jquery-plugin.js", "1.0", ["jquery"], "jquery-plugin.css"]

(the configuration is [file_path, version, js dependency, bundled css file]).

When my plugin is loaded, the .json file is read, parsed and then the scripts and styles are registered. Also, information about whether a script has a bundled style file is kept in a global array, let's call it $_scirpts_has_style. With $_scirpts_has_style, the bundled style can get wp_enqueue_style'd automatically after the corresponding script is wp_enqueue_script'ed.

So, what I basically want is some signal which informs me that a script is enqueued, but I cannot find such signal (action/filter). script_loader_src is something very close but it is triggered when the script is getting printed, which is too late to enqueue a style file.

Is there any action/filter that does this? Or,

What's your solution to this problem?

share|improve this question
1  
There must be a specific condition to trigger the enqueuing of your script. Why don’t you use the same condition for your stylesheet? –  toscho Apr 16 '13 at 5:07
    
@toscho You're right. But consider this: Once the user enqueues a script, all its dependencies are enqueued as well, which is done automatically and silently by WP. Auto-dependency resolving is a certain benefit to rely on, otherwise there's no meaning to use wp_enqueue_script system. –  kavinyao Apr 16 '13 at 9:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.