<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52016] trunk: REST API: Allow sidebars and their widgets to be public.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52016">52016</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52016","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>TimothyBlynJacobs</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-11-05 02:14:07 +0000 (Fri, 05 Nov 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>REST API: Allow sidebars and their widgets to be public.

By default, only users with the `edit_theme_options` capability can access the sidebars and widgets REST API endpoints. In this commit, A new `show_in_rest` parameter is added to the `register_sidebar` function. When enabled, all users will be able to access that sidebar and any widgets belonging to that sidebar.

This commit reduces the `context` for a widget's `instance` information to only `edit`. This is to ensure that internal widget data is not inadvertently exposed to the public. A future ticket may expose additional APIs to allow widget authors to indicate that their instance data can be safely exposed. REST API consumers intending to access this `instance` information should take care to explicitly set the `context` parameter to `edit`.

Props spacedmonkey, zieladam.
Fixes <a href="https://core.trac.wordpress.org/ticket/53915">#53915</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestsidebarscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestwidgetscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php</a></li>
<li><a href="#trunksrcwpincludeswidgetsphp">trunk/src/wp-includes/widgets.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestsidebarscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestwidgetscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php</a></li>
<li><a href="#trunktestsqunitfixtureswpapigeneratedjs">trunk/tests/qunit/fixtures/wp-api-generated.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswprestsidebarscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php    2021-11-04 23:55:21 UTC (rev 52015)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php      2021-11-05 02:14:07 UTC (rev 52016)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,6 +19,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_REST_Sidebars_Controller extends WP_REST_Controller {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Tracks whether {@see retrieve_widgets()} has been called in the current request.
+        *
+        * @since 5.9.0
+        * @var bool
+        */
+       protected $widgets_retrieved = false;
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Sidebars controller constructor.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,6 +94,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items_permissions_check( $request ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->retrieve_widgets();
+               foreach ( wp_get_sidebars_widgets() as $id => $widgets ) {
+                       $sidebar = $this->get_sidebar( $id );
+
+                       if ( ! $sidebar ) {
+                               continue;
+                       }
+
+                       if ( $this->check_read_permission( $sidebar ) ) {
+                               return true;
+                       }
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $this->do_permissions_check();
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,12 +116,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param WP_REST_Request $request Full details about the request.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @return WP_REST_Response Response object on success.
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                retrieve_widgets();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->retrieve_widgets();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $data              = array();
+               $permissions_check = $this->do_permissions_check();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( wp_get_sidebars_widgets() as $id => $widgets ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $sidebar = $this->get_sidebar( $id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -108,6 +131,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( is_wp_error( $permissions_check ) && ! $this->check_read_permission( $sidebar ) ) {
+                               continue;
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data[] = $this->prepare_response_for_collection(
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->prepare_item_for_response( $sidebar, $request )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -125,10 +152,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_item_permissions_check( $request ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->retrieve_widgets();
+
+               $sidebar = $this->get_sidebar( $request['id'] );
+               if ( $sidebar && $this->check_read_permission( $sidebar ) ) {
+                       return true;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $this->do_permissions_check();
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Checks if a sidebar can be read publicly.
+        *
+        * @since 5.9.0
+        *
+        * @param array $sidebar The registered sidebar configuration.
+        * @return bool Whether the side can be read.
+        */
+       protected function check_read_permission( $sidebar ) {
+               return ! empty( $sidebar['show_in_rest'] );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Retrieves one sidebar from the collection.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -137,10 +183,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_item( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                retrieve_widgets();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->retrieve_widgets();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $sidebar = $this->get_sidebar( $request['id'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">                 if ( ! $sidebar ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'rest_sidebar_not_found', __( 'No sidebar exists with that id.' ), array( 'status' => 404 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,28 +279,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @global array $wp_registered_sidebars The registered sidebars.
-        *
</del><span class="cx" style="display: block; padding: 0 10px">          * @param string|int $id ID of the sidebar.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array|null The discovered sidebar, or null if it is not registered.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        protected function get_sidebar( $id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                global $wp_registered_sidebars;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return wp_get_sidebar( $id );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                foreach ( (array) $wp_registered_sidebars as $sidebar ) {
-                       if ( $sidebar['id'] === $id ) {
-                               return $sidebar;
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+        * Looks for "lost" widgets once per request.
+        *
+        * @since 5.9.0
+        *
+        * @see retrieve_widgets()
+        */
+       protected function retrieve_widgets() {
+               if ( ! $this->widgets_retrieved ) {
+                       retrieve_widgets();
+                       $this->widgets_retrieved = true;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-               if ( 'wp_inactive_widgets' === $id ) {
-                       return array(
-                               'id'   => 'wp_inactive_widgets',
-                               'name' => __( 'Inactive widgets' ),
-                       );
-               }
-
-               return null;
</del><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestwidgetscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php     2021-11-04 23:55:21 UTC (rev 52015)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php       2021-11-05 02:14:07 UTC (rev 52016)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +17,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_REST_Widgets_Controller extends WP_REST_Controller {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Tracks whether {@see retrieve_widgets()} has been called in the current request.
+        *
+        * @since 5.9.0
+        * @var bool
+        */
+       protected $widgets_retrieved = false;
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Widgets controller constructor.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -97,6 +105,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items_permissions_check( $request ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->retrieve_widgets();
+               if ( isset( $request['sidebar'] ) && $this->check_read_sidebar_permission( $request['sidebar'] ) ) {
+                       return true;
+               }
+
+               foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) {
+                       if ( $this->check_read_sidebar_permission( $sidebar_id ) ) {
+                               return true;
+                       }
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $this->permissions_check( $request );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -109,9 +128,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                retrieve_widgets();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->retrieve_widgets();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $prepared = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $prepared          = array();
+               $permissions_check = $this->permissions_check( $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( isset( $request['sidebar'] ) && $sidebar_id !== $request['sidebar'] ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,6 +138,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( is_wp_error( $permissions_check ) && ! $this->check_read_sidebar_permission( $sidebar_id ) ) {
+                               continue;
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         foreach ( $widget_ids as $widget_id ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -139,10 +163,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_item_permissions_check( $request ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->retrieve_widgets();
+
+               $widget_id  = $request['id'];
+               $sidebar_id = wp_find_widgets_sidebar( $widget_id );
+
+               if ( $sidebar_id && $this->check_read_sidebar_permission( $sidebar_id ) ) {
+                       return true;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $this->permissions_check( $request );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Checks if a sidebar can be read publicly.
+        *
+        * @since 5.9.0
+        *
+        * @param string $sidebar_id The sidebar id.
+        * @return bool Whether the sidebar can be read.
+        */
+       protected function check_read_sidebar_permission( $sidebar_id ) {
+               $sidebar = wp_get_sidebar( $sidebar_id );
+
+               return ! empty( $sidebar['show_in_rest'] );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Gets an individual widget.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -151,7 +198,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_item( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                retrieve_widgets();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->retrieve_widgets();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $widget_id  = $request['id'];
</span><span class="cx" style="display: block; padding: 0 10px">                $sidebar_id = wp_find_widgets_sidebar( $widget_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -247,9 +294,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * See https://core.trac.wordpress.org/ticket/53657.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                wp_get_sidebars_widgets();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->retrieve_widgets();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                retrieve_widgets();
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $widget_id  = $request['id'];
</span><span class="cx" style="display: block; padding: 0 10px">                $sidebar_id = wp_find_widgets_sidebar( $widget_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -323,9 +369,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * See https://core.trac.wordpress.org/ticket/53657.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                wp_get_sidebars_widgets();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->retrieve_widgets();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                retrieve_widgets();
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $widget_id  = $request['id'];
</span><span class="cx" style="display: block; padding: 0 10px">                $sidebar_id = wp_find_widgets_sidebar( $widget_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -440,6 +485,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Looks for "lost" widgets once per request.
+        *
+        * @since 5.9.0
+        *
+        * @see retrieve_widgets()
+        */
+       protected function retrieve_widgets() {
+               if ( ! $this->widgets_retrieved ) {
+                       retrieve_widgets();
+                       $this->widgets_retrieved = true;
+               }
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Saves the widget in the request object.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -767,23 +826,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'instance'      => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'Instance settings of the widget, if supported.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => 'object',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'context'     => array( 'view', 'edit', 'embed' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'context'     => array( 'edit' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                         'default'     => null,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'properties'  => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                'encoded' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'description' => __( 'Base64 encoded representation of the instance settings.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'type'        => 'string',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        'context'     => array( 'view', 'edit', 'embed' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 'context'     => array( 'edit' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                'hash'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'description' => __( 'Cryptographic hash of the instance settings.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'type'        => 'string',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        'context'     => array( 'view', 'edit', 'embed' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 'context'     => array( 'edit' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                'raw'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'description' => __( 'Unencoded instance settings, if supported.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'type'        => 'object',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        'context'     => array( 'view', 'edit', 'embed' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 'context'     => array( 'edit' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span></span></pre></div>
<a id="trunksrcwpincludeswidgetsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/widgets.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/widgets.php 2021-11-04 23:55:21 UTC (rev 52015)
+++ trunk/src/wp-includes/widgets.php   2021-11-05 02:14:07 UTC (rev 52016)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -220,6 +220,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.2.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.6.0 Added the `before_sidebar` and `after_sidebar` arguments.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.9.0 Added the `show_in_rest` argument.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @global array $wp_registered_sidebars Registered sidebars.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -250,6 +251,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *     @type string $after_sidebar  HTML content to append to the sidebar when displayed.
</span><span class="cx" style="display: block; padding: 0 10px">  *                                  Outputs before the {@see 'dynamic_sidebar_after'} action.
</span><span class="cx" style="display: block; padding: 0 10px">  *                                  Default empty string.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *     @type bool $show_in_rest     Whether to show this sidebar publicly in the REST API.
+ *                                  Defaults to only showing the sidebar to administrator users.
</ins><span class="cx" style="display: block; padding: 0 10px">  * }
</span><span class="cx" style="display: block; padding: 0 10px">  * @return string Sidebar ID added to $wp_registered_sidebars global.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,6 +275,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'after_title'    => "</h2>\n",
</span><span class="cx" style="display: block; padding: 0 10px">                'before_sidebar' => '',
</span><span class="cx" style="display: block; padding: 0 10px">                'after_sidebar'  => '',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'show_in_rest'   => false,
</ins><span class="cx" style="display: block; padding: 0 10px">         );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1036,6 +1040,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves the registered sidebar with the given id.
+ *
+ * @since 5.9.0
+ *
+ * @global array $wp_registered_sidebars The registered sidebars.
+ *
+ * @param string $id The sidebar id.
+ * @return array|null The discovered sidebar, or null if it is not registered.
+ */
+function wp_get_sidebar( $id ) {
+       global $wp_registered_sidebars;
+
+       foreach ( (array) $wp_registered_sidebars as $sidebar ) {
+               if ( $sidebar['id'] === $id ) {
+                       return $sidebar;
+               }
+       }
+
+       if ( 'wp_inactive_widgets' === $id ) {
+               return array(
+                       'id'   => 'wp_inactive_widgets',
+                       'name' => __( 'Inactive widgets' ),
+               );
+       }
+
+       return null;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Set the sidebar widget option to update sidebars.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.2.0
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestsidebarscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php   2021-11-04 23:55:21 UTC (rev 52015)
+++ trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php     2021-11-05 02:14:07 UTC (rev 52016)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -165,6 +165,102 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 53915
+        */
+       public function test_get_items_no_permission_show_in_rest() {
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name'         => 'Test sidebar',
+                               'show_in_rest' => true,
+                       )
+               );
+               wp_set_current_user( 0 );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/sidebars' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $data     = $this->remove_links( $data );
+               $this->assertSame(
+                       array(
+                               array(
+                                       'id'            => 'sidebar-1',
+                                       'name'          => 'Test sidebar',
+                                       'description'   => '',
+                                       'class'         => '',
+                                       'before_widget' => '',
+                                       'after_widget'  => '',
+                                       'before_title'  => '',
+                                       'after_title'   => '',
+                                       'status'        => 'active',
+                                       'widgets'       => array(),
+                               ),
+                       ),
+                       $data
+               );
+       }
+
+       /**
+        * @ticket 53915
+        */
+       public function test_get_items_without_show_in_rest_are_removed_from_the_list() {
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name'         => 'Test sidebar 1',
+                               'show_in_rest' => true,
+                       )
+               );
+               $this->setup_sidebar(
+                       'sidebar-2',
+                       array(
+                               'name'         => 'Test sidebar 2',
+                               'show_in_rest' => false,
+                       )
+               );
+               $this->setup_sidebar(
+                       'sidebar-3',
+                       array(
+                               'name'         => 'Test sidebar 3',
+                               'show_in_rest' => true,
+                       )
+               );
+               wp_set_current_user( self::$author_id );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/sidebars' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $data     = $this->remove_links( $data );
+               $this->assertSame(
+                       array(
+                               array(
+                                       'id'            => 'sidebar-1',
+                                       'name'          => 'Test sidebar 1',
+                                       'description'   => '',
+                                       'class'         => '',
+                                       'before_widget' => '',
+                                       'after_widget'  => '',
+                                       'before_title'  => '',
+                                       'after_title'   => '',
+                                       'status'        => 'active',
+                                       'widgets'       => array(),
+                               ),
+                               array(
+                                       'id'            => 'sidebar-3',
+                                       'name'          => 'Test sidebar 3',
+                                       'description'   => '',
+                                       'class'         => '',
+                                       'before_widget' => '',
+                                       'after_widget'  => '',
+                                       'before_title'  => '',
+                                       'after_title'   => '',
+                                       'status'        => 'active',
+                                       'widgets'       => array(),
+                               ),
+                       ),
+                       $data
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 41683
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_items_wrong_permission_author() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -192,6 +288,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><span class="cx" style="display: block; padding: 0 10px">                                array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'id'            => 'wp_inactive_widgets',
+                                       'name'          => 'Inactive widgets',
+                                       'description'   => '',
+                                       'class'         => '',
+                                       'before_widget' => '',
+                                       'after_widget'  => '',
+                                       'before_title'  => '',
+                                       'after_title'   => '',
+                                       'status'        => 'inactive',
+                                       'widgets'       => array(),
+                               ),
+                               array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                         'id'            => 'sidebar-1',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'name'          => 'Test sidebar',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description'   => '',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -206,6 +314,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $data
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -415,6 +524,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 41683
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_get_item_no_permission_public() {
+               wp_set_current_user( 0 );
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name'         => 'Test sidebar',
+                               'show_in_rest' => true,
+                       )
+               );
+
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/sidebars/sidebar-1' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $data     = $this->remove_links( $data );
+               $this->assertSame(
+                       array(
+                               'id'            => 'sidebar-1',
+                               'name'          => 'Test sidebar',
+                               'description'   => '',
+                               'class'         => '',
+                               'before_widget' => '',
+                               'after_widget'  => '',
+                               'before_title'  => '',
+                               'after_title'   => '',
+                               'status'        => 'active',
+                               'widgets'       => array(),
+                       ),
+                       $data
+               );
+       }
+
+       /**
+        * @ticket 41683
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_wrong_permission_author() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$author_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->setup_sidebar(
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestwidgetscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php    2021-11-04 23:55:21 UTC (rev 52015)
+++ trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php      2021-11-05 02:14:07 UTC (rev 52016)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -241,6 +241,100 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 53915
+        */
+       public function test_get_items_no_permission_show_in_rest() {
+               $this->setup_widget(
+                       'text',
+                       1,
+                       array(
+                               'text' => 'Custom text test',
+                       )
+               );
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name'         => 'Test sidebar',
+                               'show_in_rest' => true,
+                       ),
+                       array( 'text-1', 'testwidget' )
+               );
+
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/widgets' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $data     = $this->remove_links( $data );
+               $this->assertSameIgnoreEOL(
+                       array(
+                               array(
+                                       'id'       => 'text-1',
+                                       'id_base'  => 'text',
+                                       'sidebar'  => 'sidebar-1',
+                                       'rendered' => '<div class="textwidget">Custom text test</div>',
+                               ),
+                               array(
+                                       'id'       => 'testwidget',
+                                       'id_base'  => 'testwidget',
+                                       'sidebar'  => 'sidebar-1',
+                                       'rendered' => '<h1>Default id</h1><span>Default text</span>',
+                               ),
+                       ),
+                       $data
+               );
+       }
+
+       /**
+        * @ticket 53915
+        */
+       public function test_get_items_without_show_in_rest_are_removed_from_the_list() {
+               wp_set_current_user( self::$author_id );
+               $this->setup_widget(
+                       'text',
+                       1,
+                       array(
+                               'text' => 'Custom text test',
+                       )
+               );
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name'         => 'Test sidebar 1',
+                               'show_in_rest' => true,
+                       ),
+                       array( 'text-1', 'testwidget' )
+               );
+               $this->setup_sidebar(
+                       'sidebar-2',
+                       array(
+                               'name'         => 'Test sidebar 2',
+                               'show_in_rest' => false,
+                       ),
+                       array( 'text-1', 'testwidget' )
+               );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/widgets' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $data     = $this->remove_links( $data );
+               $this->assertSameIgnoreEOL(
+                       array(
+                               array(
+                                       'id'       => 'text-1',
+                                       'id_base'  => 'text',
+                                       'sidebar'  => 'sidebar-1',
+                                       'rendered' => '<div class="textwidget">Custom text test</div>',
+                               ),
+                               array(
+                                       'id'       => 'testwidget',
+                                       'id_base'  => 'testwidget',
+                                       'sidebar'  => 'sidebar-1',
+                                       'rendered' => '<h1>Default id</h1><span>Default text</span>',
+                               ),
+                       ),
+                       $data
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 41683
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_items_wrong_permission_author() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -295,25 +389,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'id_base'  => 'block',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'sidebar'  => 'sidebar-1',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'rendered' => '<p>Block test</p>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'instance' => array(
-                                               'encoded' => base64_encode(
-                                                       serialize(
-                                                               array(
-                                                                       'content' => $block_content,
-                                                               )
-                                                       )
-                                               ),
-                                               'hash'    => wp_hash(
-                                                       serialize(
-                                                               array(
-                                                                       'content' => $block_content,
-                                                               )
-                                                       )
-                                               ),
-                                               'raw'     => array(
-                                                       'content' => $block_content,
-                                               ),
-                                       ),
</del><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'id'       => 'rss-1',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -320,24 +395,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'id_base'  => 'rss',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'sidebar'  => 'sidebar-1',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpr
 ess.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/n
 ews/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'instance' => array(
-                                               'encoded' => base64_encode(
-                                                       serialize(
-                                                               array(
-                                                                       'title' => 'RSS test',
-                                                                       'url'   => 'https://wordpress.org/news/feed',
-                                                               )
-                                                       )
-                                               ),
-                                               'hash'    => wp_hash(
-                                                       serialize(
-                                                               array(
-                                                                       'title' => 'RSS test',
-                                                                       'url'   => 'https://wordpress.org/news/feed',
-                                                               )
-                                                       )
-                                               ),
-                                       ),
</del><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'id'       => 'testwidget',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,7 +401,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'id_base'  => 'testwidget',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'sidebar'  => 'sidebar-1',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'rendered' => '<h1>Default id</h1><span>Default text</span>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'instance' => null,
</del><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $data
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -469,25 +525,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'id_base'  => 'text',
</span><span class="cx" style="display: block; padding: 0 10px">                                'sidebar'  => 'sidebar-1',
</span><span class="cx" style="display: block; padding: 0 10px">                                'rendered' => '<div class="textwidget">Custom text test</div>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'instance' => array(
-                                       'encoded' => base64_encode(
-                                               serialize(
-                                                       array(
-                                                               'text' => 'Custom text test',
-                                                       )
-                                               )
-                                       ),
-                                       'hash'    => wp_hash(
-                                               serialize(
-                                                       array(
-                                                               'text' => 'Custom text test',
-                                                       )
-                                               )
-                                       ),
-                                       'raw'     => array(
-                                               'text' => 'Custom text test',
-                                       ),
-                               ),
</del><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $data
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -544,6 +581,42 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 53915
+        */
+       public function test_get_item_no_permission_show_in_rest() {
+               wp_set_current_user( 0 );
+
+               $this->setup_widget(
+                       'text',
+                       1,
+                       array(
+                               'text' => 'Custom text test',
+                       )
+               );
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name'         => 'Test sidebar',
+                               'show_in_rest' => true,
+                       ),
+                       array( 'text-1' )
+               );
+
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/widgets/text-1' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $this->assertSameSets(
+                       array(
+                               'id'       => 'text-1',
+                               'id_base'  => 'text',
+                               'sidebar'  => 'sidebar-1',
+                               'rendered' => '<div class="textwidget">Custom text test</div>',
+                       ),
+                       $data
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 41683
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_create_item() {
</span></span></pre></div>
<a id="trunktestsqunitfixtureswpapigeneratedjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/fixtures/wp-api-generated.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/fixtures/wp-api-generated.js    2021-11-04 23:55:21 UTC (rev 52015)
+++ trunk/tests/qunit/fixtures/wp-api-generated.js      2021-11-05 02:14:07 UTC (rev 52016)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7135,9 +7135,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                     "description": "Base64 encoded representation of the instance settings.",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "context": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        "view",
-                                        "edit",
-                                        "embed"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        "edit"
</ins><span class="cx" style="display: block; padding: 0 10px">                                     ]
</span><span class="cx" style="display: block; padding: 0 10px">                                 },
</span><span class="cx" style="display: block; padding: 0 10px">                                 "hash": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7144,9 +7142,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                     "description": "Cryptographic hash of the instance settings.",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "context": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        "view",
-                                        "edit",
-                                        "embed"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        "edit"
</ins><span class="cx" style="display: block; padding: 0 10px">                                     ]
</span><span class="cx" style="display: block; padding: 0 10px">                                 },
</span><span class="cx" style="display: block; padding: 0 10px">                                 "raw": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7153,9 +7149,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                     "description": "Unencoded instance settings, if supported.",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "type": "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "context": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        "view",
-                                        "edit",
-                                        "embed"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        "edit"
</ins><span class="cx" style="display: block; padding: 0 10px">                                     ]
</span><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                             },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7235,9 +7229,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                     "description": "Base64 encoded representation of the instance settings.",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "context": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        "view",
-                                        "edit",
-                                        "embed"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        "edit"
</ins><span class="cx" style="display: block; padding: 0 10px">                                     ]
</span><span class="cx" style="display: block; padding: 0 10px">                                 },
</span><span class="cx" style="display: block; padding: 0 10px">                                 "hash": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7244,9 +7236,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                     "description": "Cryptographic hash of the instance settings.",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "context": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        "view",
-                                        "edit",
-                                        "embed"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        "edit"
</ins><span class="cx" style="display: block; padding: 0 10px">                                     ]
</span><span class="cx" style="display: block; padding: 0 10px">                                 },
</span><span class="cx" style="display: block; padding: 0 10px">                                 "raw": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7253,9 +7243,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                     "description": "Unencoded instance settings, if supported.",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "type": "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                     "context": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        "view",
-                                        "edit",
-                                        "embed"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        "edit"
</ins><span class="cx" style="display: block; padding: 0 10px">                                     ]
</span><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                             },
</span></span></pre>
</div>
</div>

</body>
</html>