Customer asks if a specific carousel plugin he uses can be widgetized. That means I should create a widget inside functions.php which calls the plugin’s function. That means that the plugin’s code has to be loaded first so that the function be available to WordPress when the functions.php file is loaded, right? Would that work?
Leave a Reply
You must be logged in to post a comment.
The plugins are loaded right before theme (yes, I’ve been looking for excuse to use this):
However it is wrong to think about either as point of code execution. For most cases everything should be hooked and executed no earlier than
init
hook. According to Codex widget registration withregister_widget()
should be hooked towidget_init
.Because of that order of load doesn’t matter for this case, you will have everything loaded by the time widget needs it in any case.
One interesting approach would be to list all hooks to a file in a sequence of execution.
And you will get the output like this:
The possible goodies of this check are many, but please note the output will be different for different page templates you will call, or if you are in a dashboard.
I simply called this from
/?p=1
or Hello World page.If you don’t have a single plugin activated, you may put this code into
mu-plugins
folder.It may be better to use WP FS API, but this way is realy concise.
You can have a widget inside the plugin’s .php file (and have a shared global variable which they can both use), if that’s what you’re asking. Here’s a tutorial with sample code I stumbled upon a while back.
Also, here’s a list of actions run during a typical request, in order of execution. #2 and #10 suggest that plugins load first; not sure about functions.php.