Title: Widgets Loaded Late?
Last modified: August 19, 2016

---

# Widgets Loaded Late?

 *  [mutube](https://wordpress.org/support/users/mutube/)
 * (@mutube)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/widgets-loaded-late/)
 * 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)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 2 months ago](https://wordpress.org/support/topic/widgets-loaded-late/#post-704576)
 * 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](https://wordpress.org/support/users/mutube/)
 * (@mutube)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/widgets-loaded-late/#post-704619)
 * 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](https://wordpress.org/support/users/mutube/)
 * (@mutube)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/widgets-loaded-late/#post-704623)
 * 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.

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 3 replies
 * 2 participants
 * Last reply from: [mutube](https://wordpress.org/support/users/mutube/)
 * Last activity: [18 years, 2 months ago](https://wordpress.org/support/topic/widgets-loaded-late/#post-704623)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
