I have a problem: a wordpress site that i manage keep loose the widgets. When i open the widget admin panel, all the sidebar are empty.

I've debugged some code and found that the widget exists into the database field 'sidebars_widgets'. But when it comes to display them, it stops here:

wp-includes/widgets.php, line #658

if ( !isset($wp_registered_widgets[$id]) ) continue

because the wp_registered_widgets only contains the available and the non-active widgets. For example, i have a text-2 widget inside my sidebar, but the wp_registered_widgets variable only contains text-1, the available one.

So far, I'm in trouble with understanding where this variable is populated. Someone can help?

1 Answer 1


Founded here: wp-includes/class-wp-widget.php #248

public function _register() {
    $settings = $this->get_settings();
    $empty = true;

    // When $settings is an array-like object, get an intrinsic array for use with array_keys().
    if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {
        $settings = $settings->getArrayCopy();

    if ( is_array( $settings ) ) {
        foreach ( array_keys( $settings ) as $number ) {
            if ( is_numeric( $number ) ) {
                $this->_set( $number );
                $this->_register_one( $number );
                $empty = false;

    if ( $empty ) {
        // If there are none, we register the widget's existence with a generic template.
        $this->_set( 1 );

The get_settings function retrieve the options for the widget saved in the wp_options table. I've in someway lost these informations into the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.