This is less of a support or announcement and more of a discussion for input.
I'm bringing all my plugins up to 1.3.1.2-6003 compliance and am removing the reliance on any deprecated functions (addpluginscript for one).
The way I currently have the filter-function setup is an if check, then load. I guess my question comes from if this is really even needed or the best approach.
Does zp_register_filter load the same function multiple times if it's the same name? Or will it load it the first time, and skip it without error after, which is what I think is currently happening as the function loads once (which is the desired effect).
I'm just trying to figure out if I even need this ifcheck to begin with on it.
Comments
If your plugins are all quite similiar joing them to one plugin is probably a good idea to save unnecessarily code duplication anyway. You could make options for the several parts.
The function, of course, is only declared when your plugin loads. If you have multiple plugins with the same function name and load them all you will get the redeclare error. Not sure what class of error redeclare is, maybe it is supressed in your install.
Because looking at what I'm using now, with a non-foggy brain I can see that the if-check I used was completely useless.
It is however only loading one instance of the meta-keys.
I guess at this point combining all the plug-ins into one larger plug-in would make more sense, but I kind of like the ability for users to just download and use the parts they want.
So here's how it's setup currently.
zenFBSuite of plug-ins load all the required meta-keys for the OpenGraph data that makes them function properly. They all use the same meta-keys so they only need to load once. Previously (before switching to this filter usage) it was loading each set of meta keys equal to the number of the plug-ins used.
It was messy but I figured the minor overhead usage was better than one large plug-in with all the options and then confusion on which to set for which plugin.
So now, I've converted all the meta-keys from addpluginscript functions to one function called zenFBOpenGraphJS().
Each plug-in has the same function, and each function uses a `zp_register_filter('theme_head', 'zenFBOpenGraphJS');`
After enabling all plug-ins at once and checking the header, it's only loading one set of meta-keys, which is ideal. I'm just worried I'm not going about it properly, since now that I look back at the code, the if-check is really not stopping the function call.
They all use the above from codeblock the same, so if I'm understanding what you said sbillard, it functions that way properly since they're all the same priority? So since they're all the same priority, they all are combined into once instance, so I shouldn't be getting the redeclare error, right?(which I'm not currently)
I guess what I would do is make a separate script for the js part that has the register filter call and the function declaration. Then each other plugin would just do a `require_once()` on that script. This way, only one function declaration and only one filter registration no matter how many of the other plugins are enabled.