WordPress.org

Make WordPress Core

Changeset 51248


Ignore:
Timestamp:
06/28/2021 04:33:36 AM (3 months ago)
Author:
noisysocks
Message:

Widgets REST API: Fix non-multi widgets not appearing in wp_inactive_widgets

Registered widgets that do not extend WP_Widget should appear in the
wp_inactive_widgets sidebar by default. Having the widgets REST API call
retrieve_widgets() before serving any request ensures that this will happen.

This is a similar fix to [51235].

Fixes #53534.
Props zieladam, timothyblynjacobs.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php

    r51239 r51248  
    110110     */
    111111    public function get_items( $request ) {
     112        retrieve_widgets();
     113
    112114        $prepared = array();
    113115
     
    150152     */
    151153    public function get_item( $request ) {
     154        retrieve_widgets();
     155
    152156        $widget_id  = $request['id'];
    153157        $sidebar_id = wp_find_widgets_sidebar( $widget_id );
     
    230234    public function update_item( $request ) {
    231235        global $wp_widget_factory;
     236
     237        retrieve_widgets();
    232238
    233239        $widget_id  = $request['id'];
     
    291297    public function delete_item( $request ) {
    292298        global $wp_registered_widget_updates;
     299
     300        retrieve_widgets();
    293301
    294302        $widget_id  = $request['id'];
  • trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php

    r51137 r51248  
    9696
    9797    public function setUp() {
    98         global $wp_registered_widgets, $wp_registered_sidebars, $_wp_sidebars_widgets, $wp_widget_factory;
     98        global $wp_widget_factory;
    9999
    100100        parent::setUp();
     
    102102        wp_set_current_user( self::$admin_id );
    103103
    104         // Unregister all widgets and sidebars.
    105         $wp_registered_widgets  = array();
    106         $wp_registered_sidebars = array();
    107         $_wp_sidebars_widgets   = array();
    108         update_option( 'sidebars_widgets', array() );
    109 
    110104        // Re-register core widgets.
    111         $wp_widget_factory->_register_widgets();
     105        wp_widgets_init();
    112106
    113107        // Register a non-multi widget for testing.
     
    148142            )
    149143        );
     144    }
     145
     146    public function clean_up_global_scope() {
     147        global
     148            $wp_widget_factory,
     149            $wp_registered_sidebars,
     150            $wp_registered_widgets,
     151            $wp_registered_widget_controls,
     152            $wp_registered_widget_updates,
     153            $_wp_sidebars_widgets;
     154
     155        $wp_registered_sidebars        = array();
     156        $wp_registered_widgets         = array();
     157        $wp_registered_widget_controls = array();
     158        $wp_registered_widget_updates  = array();
     159        $wp_widget_factory->widgets    = array();
     160        $_wp_sidebars_widgets          = array();
     161
     162        update_option( 'sidebars_widgets', array() );
     163
     164        parent::clean_up_global_scope();
    150165    }
    151166
Note: See TracChangeset for help on using the changeset viewer.