Just a discussion starter, or maybe there is already a way to do this that I am missing. Developing a plugin, and would like to add script/css links in the header when needed, using the applicable filter. However, I do not need to load these on most pages, but it could be variable, so I cannot simply check the $zp_current_page in the plugin file. Any suggestions on another way?
Even core extensions load all their scripts/css on pages when not necessary. For example, on my index page, I am loading rating and comment pagination js and css when it will never be needed.
Comments
Btw, most (we probably missed some) globals are listed here:
http://www.zenphoto.org/news/zenphotos-global-variables
There are also a lot of other functions to test like `is_Pages()`, `is_Newspage()`. Also there are way to test the context like `in_context()`.
If you need to address specific albums or pages itself and not just the theme page you have to add checks there as well.
Regarding plugins you think loading stuff where they should not please open tickets. Might very well be that we did miss some.
I will look at some of the core extensions for ideas. And also look to see how comment pagination/rating scripts are loaded and submit tickets. Thanks -
If your function attached to the filter does not return anything if it is not on the right page or in the right context nothing happens.
Maybe I don't understand what you are after?
1. I have a user plugin.
2. In the plugin class I have a function that can be called in template files or codeblocks.
3. When the function is called, in order for it to work, I need to place scripts and css calls in the <head> (ideally).
Currently I have this in the "plugin".php, outside of the main function:
`zp_register_filter('theme_head','printJSwhatever...');`
which calls a function to print the necessary js/css calls in the <head>. But it makes this call ALWAYS, on every page when the plugin is activated. I am looking for the possibility to only print this when the main plugin function is called either by a template page or codeblock entry. Not an expert in php or zp plugin architecture, probably something simple....
If it is just a bit JS you could print that with the function itself as it does not matter where that appears. For CSS that is different of course.
Generally speaking, your plugin should try to determine what it should be doing when it gets loaded if it can. So, for instance, the colorbox_js filter checks to see if it should register a theme_head filter based on the "page" being rendered.
If you cannot determine what needs to be in the head until after the head has been created the only means for changing it is with javascript. The "head consolidator" plugin (Zenphoto unsupported repository) is an example of doing that.