Make WordPress Core

Opened 13 months ago

#60559 new defect (bug)

Widgets moved by calling the sidebars endpoint

Reported by: davit16's profile davit16 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Widgets Keywords:
Focuses: rest-api Cc:

Description

The GET /wp/v2/sidebars endpoint moves the widgets permanently, if for some reasons, one or more sidebars are not registered for WP REST. Moreover, it does it even if it returns a 401 status code.

To reproduce the issue:

  1. Have Gutenberg disable with the "Disable Gutenberg" plugin
  1. Add this code to theme's functions.php
    function test_register_sidebars() {
            if ( strpos( $_SERVER['REQUEST_URI'], '/wp-json/' ) === false ) {
                    register_sidebar( [
                            'name'          => 'Sidebar 1 - not registered on WP REST',
                            'id'            => 'sidebar-1',
                            'before_widget' => '<section id="%1$s" class="widget %2$s">',
                            'after_widget'  => '</section>',
                            'before_title'  => '<h2 class="widget-title">',
                            'after_title'   => '</h2>',
                    ] );
            }
    
            register_sidebar( [
                            'name'          => 'Sidebar 2',
                            'id'            => 'sidebar-2',
                            'before_widget' => '<section id="%1$s" class="widget %2$s">',
                            'after_widget'  => '</section>',
                            'before_title'  => '<h2 class="widget-title">',
                            'after_title'   => '</h2>',
            ] );
    }
    add_action( 'widgets_init', 'test_register_sidebars' );
    
  1. Add widgets to "Sidebar 1"
  1. Visit GET /wp-json/wp/v2/sidebars

Attachments (1)

Sidebars endpoint.mp4 (599.3 KB) - added by davit16 13 months ago.

Download all attachments as: .zip

Change History (1)

Note: See TracTickets for help on using tickets.