• I’ve come across a bug while developing the latest version of my plugin: when using a class for plugin functions it is impossible to call Widget register functions from inside a class if that class is not instantiated to a variable.

    If I do $foo = new Class(); I can call the Widget functions from inside the classes functions. If I do Class::function(); then it cannot see the widget registering function inside and dies with a ‘Call to undefined function wp_register_sidebar_widget()’ error.

    Looking into it (check default-filters.php) it appears that the Widgets are only being loaded after plugins have loaded…

    add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );

    …which seems a pretty bad idea as the plugins depend on the Widgets. Not sure why this error does not show up when the class is instantiated.

    What is the intended result of loading Widgets this late?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You should be hooking to “widgets_init” before calling any widget functions. The widgets_init action is (and always has been) the actual correct place to call your register widget functions.

    Widgets might not be loading at all. Trying to register a widget when you have no idea if they’re loaded or not is the wrong thing to do.

    In other words, regardless of whether you are in a class or not, nothing your plugin does should call the register widget functions until the widgets_init action.

    Thread Starter mutube

    (@mutube)

    Thanks Otto42, as mentioned in the other thread it seems to make no difference. Clearly the problem here isn’t the order they’re loading in… I’ll have another look and see what I dig up

    Thread Starter mutube

    (@mutube)

    Oh my, I’m a plonker.

    I was calling on the action using add_action('plugins_loaded', adsensem::init(), 1); which of course triggered the action (to evaluate the function) but not the “right way”.

    Changing that to ‘adsensem::init’ (like I used EVERYWHERE ELSE in the plugin!) works a treat.

    Dumb, dumb, dumb.

    Thanks for the help & tip for ‘widgets_init’.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Widgets Loaded Late?’ is closed to new replies.