<!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>[49925] trunk: REST API: Expose all themes in the themes controller.</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/49925">49925</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/49925","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-01-03 21:45:42 +0000 (Sun, 03 Jan 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: Expose all themes in the themes controller.

Previously, only the active theme was made available. This commit allows for all themes to be queried if the user has the `switch_themes` or `manage_network_themes` capabilities.

This commit also no longer exposes the `page`, `per_page`, `search` and `context` query parameters since they are not supported by this controller.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiclasswprestserverphp">trunk/src/wp-includes/rest-api/class-wp-rest-server.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestthemescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestschemasetupphp">trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestserverphp">trunk/tests/phpunit/tests/rest-api/rest-server.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestthemescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-themes-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="trunksrcwpincludesrestapiclasswprestserverphp"></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/class-wp-rest-server.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/class-wp-rest-server.php   2021-01-03 17:54:48 UTC (rev 49924)
+++ trunk/src/wp-includes/rest-api/class-wp-rest-server.php     2021-01-03 21:45:42 UTC (rev 49925)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1244,8 +1244,8 @@
</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">                $response = new WP_REST_Response( $available );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">                 $response->add_link( 'help', 'http://v2.wp-api.org/' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->add_active_theme_link_to_index( $response );
</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">                 * Filters the REST API root index data.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1262,6 +1262,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">+         * Adds a link to the active theme for users who have proper permissions.
+        *
+        * @since 5.7.0
+        *
+        * @param WP_REST_Response $response REST API response.
+        */
+       protected function add_active_theme_link_to_index( WP_REST_Response $response ) {
+               $should_add = current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' );
+
+               if ( ! $should_add && current_user_can( 'edit_posts' ) ) {
+                       $should_add = true;
+               }
+
+               if ( ! $should_add ) {
+                       foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
+                               if ( current_user_can( $post_type->cap->edit_posts ) ) {
+                                       $should_add = true;
+                                       break;
+                               }
+                       }
+               }
+
+               if ( $should_add ) {
+                       $theme = wp_get_theme();
+                       $response->add_link( 'https://api.w.org/active-theme', rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ) );
+               }
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Retrieves the index for a namespace.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.4.0
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestthemescontrollerphp"></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-themes-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-themes-controller.php      2021-01-03 17:54:48 UTC (rev 49924)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php        2021-01-03 21:45:42 UTC (rev 49925)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -47,6 +47,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'schema' => array( $this, 'get_item_schema' ),
</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">+
+               register_rest_route(
+                       $this->namespace,
+                       '/' . $this->rest_base . '/(?P<stylesheet>[\w-]+)',
+                       array(
+                               'args'   => array(
+                                       'stylesheet' => array(
+                                               'description' => __( "The theme's stylesheet. This uniquely identifies the theme." ),
+                                               'type'        => 'string',
+                                       ),
+                               ),
+                               array(
+                                       'methods'             => WP_REST_Server::READABLE,
+                                       'callback'            => array( $this, 'get_item' ),
+                                       'permission_callback' => array( $this, 'get_item_permissions_check' ),
+                               ),
+                               'schema' => array( $this, 'get_public_item_schema' ),
+                       )
+               );
</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">@@ -58,6 +77,57 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object.
</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">+                if ( current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' ) ) {
+                       return true;
+               }
+
+               $registered = $this->get_collection_params();
+               if ( isset( $registered['status'], $request['status'] ) && is_array( $request['status'] ) && array( 'active' ) === $request['status'] ) {
+                       return $this->check_read_active_theme_permission();
+               }
+
+               return new WP_Error(
+                       'rest_cannot_view_themes',
+                       __( 'Sorry, you are not allowed to view themes.' ),
+                       array( 'status' => rest_authorization_required_code() )
+               );
+       }
+
+       /**
+        * Checks if a given request has access to read the theme.
+        *
+        * @since 5.7.0
+        *
+        * @param WP_REST_Request $request Full details about the request.
+        * @return bool|WP_Error True if the request has read access for the item, otherwise WP_Error object.
+        */
+       public function get_item_permissions_check( $request ) {
+               if ( current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' ) ) {
+                       return true;
+               }
+
+               $wp_theme      = wp_get_theme( $request['stylesheet'] );
+               $current_theme = wp_get_theme();
+
+               if ( $this->is_same_theme( $wp_theme, $current_theme ) ) {
+                       return $this->check_read_active_theme_permission();
+               }
+
+               return new WP_Error(
+                       'rest_cannot_view_themes',
+                       __( 'Sorry, you are not allowed to view themes.' ),
+                       array( 'status' => rest_authorization_required_code() )
+               );
+       }
+
+       /**
+        * Checks if a theme can be read.
+        *
+        * @since 5.7.0
+        *
+        * @return bool|WP_Error Whether the theme can be read.
+        */
+       protected function check_read_active_theme_permission() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( current_user_can( 'edit_posts' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return true;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,13 +139,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">                return new WP_Error(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'rest_user_cannot_view',
-                       __( 'Sorry, you are not allowed to view themes.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'rest_cannot_view_active_theme',
+                       __( 'Sorry, you are not allowed to view the active theme.' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         array( 'status' => rest_authorization_required_code() )
</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><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Retrieves a single theme.
+        *
+        * @since 5.7.0
+        *
+        * @param WP_REST_Request $request Full details about the request.
+        * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
+        */
+       public function get_item( $request ) {
+               $wp_theme = wp_get_theme( $request['stylesheet'] );
+               if ( ! $wp_theme->exists() ) {
+                       return new WP_Error(
+                               'rest_theme_not_found',
+                               __( 'Theme not found.' ),
+                               array( 'status' => 404 )
+                       );
+               }
+               $data = $this->prepare_item_for_response( $wp_theme, $request );
+
+               return rest_ensure_response( $data );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Retrieves a collection of themes.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -84,20 +176,26 @@
</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 the list of registered collection query parameters.
-               $registered = $this->get_collection_params();
-               $themes     = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $themes = array();
</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 ( isset( $registered['status'], $request['status'] ) && in_array( 'active', $request['status'], true ) ) {
-                       $active_theme = wp_get_theme();
-                       $active_theme = $this->prepare_item_for_response( $active_theme, $request );
-                       $themes[]     = $this->prepare_response_for_collection( $active_theme );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $active_themes = wp_get_themes();
+               $current_theme = wp_get_theme();
+               $status        = $request['status'];
+
+               foreach ( $active_themes as $theme_name => $theme ) {
+                       $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive';
+                       if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) {
+                               continue;
+                       }
+
+                       $prepared = $this->prepare_item_for_response( $theme, $request );
+                       $themes[] = $this->prepare_response_for_collection( $prepared );
</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">                $response = rest_ensure_response( $themes );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-Total', count( $themes ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->header( 'X-WP-TotalPages', count( $themes ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response->header( 'X-WP-TotalPages', 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $response;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -166,7 +264,12 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( rest_is_field_included( 'theme_supports', $fields ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $current_theme = wp_get_theme();
+               if ( rest_is_field_included( 'status', $fields ) ) {
+                       $data['status'] = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive';
+               }
+
+               if ( rest_is_field_included( 'theme_supports', $fields ) && $this->is_same_theme( $theme, $current_theme ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         foreach ( get_registered_theme_features() as $feature => $config ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( ! is_array( $config['show_in_rest'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        continue;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -206,6 +309,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">+                $response->add_links( $this->prepare_links( $theme ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters theme data returned from the REST API.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -219,6 +324,39 @@
</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">+         * Prepares links for the request.
+        *
+        * @since 5.7.0
+        *
+        * @param WP_Theme $theme Theme data.
+        * @return array Links for the given block type.
+        */
+       protected function prepare_links( $theme ) {
+               return array(
+                       'self'       => array(
+                               'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $theme->get_stylesheet() ) ),
+                       ),
+                       'collection' => array(
+                               'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
+                       ),
+               );
+       }
+
+       /**
+        * Helper function to compare two themes.
+        *
+        * @since 5.7.0
+        *
+        * @param WP_Theme $theme_a First theme to compare.
+        * @param WP_Theme $theme_b Second theme to compare.
+        *
+        * @return bool
+        */
+       protected function is_same_theme( $theme_a, $theme_b ) {
+               return $theme_a->get_stylesheet() === $theme_b->get_stylesheet();
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Prepares the theme support value for inclusion in the REST API response.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.5.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -399,6 +537,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => 'string',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'readonly'    => true,
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'status'         => array(
+                                       'description' => __( 'A named status for the theme.' ),
+                                       'type'        => 'string',
+                                       'enum'        => array( 'inactive', 'active' ),
+                               ),
</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">@@ -425,17 +568,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array Collection parameters.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_collection_params() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $query_params = parent::get_collection_params();
-
-               $query_params['status'] = array(
-                       'description'       => __( 'Limit result set to themes assigned one or more statuses.' ),
-                       'type'              => 'array',
-                       'items'             => array(
-                               'enum' => array( 'active' ),
-                               'type' => 'string',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $query_params = array(
+                       'status' => array(
+                               'description' => __( 'Limit result set to themes assigned one or more statuses.' ),
+                               'type'        => 'array',
+                               'items'       => array(
+                                       'enum' => array( 'active', 'inactive' ),
+                                       'type' => 'string',
+                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'required'          => true,
-                       'sanitize_callback' => array( $this, 'sanitize_theme_status' ),
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -452,6 +593,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Sanitizes and validates the list of theme status.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @deprecated 5.7.0
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string|array    $statuses  One or more theme statuses.
</span><span class="cx" style="display: block; padding: 0 10px">         * @param WP_REST_Request $request   Full details about the request.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -459,6 +601,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array|WP_Error A list of valid statuses, otherwise WP_Error object.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function sanitize_theme_status( $statuses, $request, $parameter ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                _deprecated_function( __METHOD__, '5.7.0' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $statuses = wp_parse_slug_list( $statuses );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $statuses as $status ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestschemasetupphp"></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-schema-setup.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php  2021-01-03 17:54:48 UTC (rev 49924)
+++ trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php    2021-01-03 21:45:42 UTC (rev 49925)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,6 +129,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        '/wp/v2/block-types/(?P<namespace>[a-zA-Z0-9_-]+)/(?P<name>[a-zA-Z0-9_-]+)',
</span><span class="cx" style="display: block; padding: 0 10px">                        '/wp/v2/settings',
</span><span class="cx" style="display: block; padding: 0 10px">                        '/wp/v2/themes',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        '/wp/v2/themes/(?P<stylesheet>[\w-]+)',
</ins><span class="cx" style="display: block; padding: 0 10px">                         '/wp/v2/plugins',
</span><span class="cx" style="display: block; padding: 0 10px">                        '/wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?)',
</span><span class="cx" style="display: block; padding: 0 10px">                        '/wp/v2/block-directory/search',
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestserverphp"></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-server.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-server.php        2021-01-03 17:54:48 UTC (rev 49924)
+++ trunk/tests/phpunit/tests/rest-api/rest-server.php  2021-01-03 21:45:42 UTC (rev 49925)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -959,6 +959,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertContains( 'GET', $route['methods'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertContains( 'DELETE', $route['methods'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( '_links', $route );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->assertArrayHasKey( 'help', $index->get_links() );
+               $this->assertArrayNotHasKey( 'wp:active-theme', $index->get_links() );
</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">        public function test_get_namespace_index() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1996,6 +1999,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSetsWithIndex( $expected, $args['param'] );
</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 50152
+        */
+       public function test_index_includes_link_to_active_theme_if_authenticated() {
+               wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+
+               $index = rest_do_request( '/' );
+               $this->assertArrayHasKey( 'https://api.w.org/active-theme', $index->get_links() );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function _validate_as_integer_123( $value, $request, $key ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! is_int( $value ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'some-error', 'This is not valid!' );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestthemescontrollerphp"></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-themes-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-themes-controller.php     2021-01-03 17:54:48 UTC (rev 49924)
+++ trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php       2021-01-03 21:45:42 UTC (rev 49925)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,6 +30,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">        protected static $contributor_id;
</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">+         * Admin user ID.
+        *
+        * @since 5.7.0
+        *
+        * @var int $admin_id
+        */
+       protected static $admin_id;
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * The current theme object.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,6 +100,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param WP_UnitTest_Factory $factory WordPress unit test factory.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                self::$admin_id       = $factory->user->create(
+                       array(
+                               'role' => 'administrator',
+                       )
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">                 self::$subscriber_id  = $factory->user->create(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'role' => 'subscriber',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -114,6 +128,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public static function wpTearDownAfterClass() {
</span><span class="cx" style="display: block; padding: 0 10px">                self::delete_user( self::$subscriber_id );
</span><span class="cx" style="display: block; padding: 0 10px">                self::delete_user( self::$contributor_id );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                self::delete_user( self::$admin_id );
</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">@@ -136,6 +151,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_register_routes() {
</span><span class="cx" style="display: block; padding: 0 10px">                $routes = rest_get_server()->get_routes();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( self::$themes_route, $routes );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertArrayHasKey( self::$themes_route . '/(?P<stylesheet>[\\w-]+)', $routes );
</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">@@ -151,6 +167,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_get_theme_response( $response );
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        '_links',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'author',
</span><span class="cx" style="display: block; padding: 0 10px">                        'author_uri',
</span><span class="cx" style="display: block; padding: 0 10px">                        'description',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -158,6 +175,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'requires_php',
</span><span class="cx" style="display: block; padding: 0 10px">                        'requires_wp',
</span><span class="cx" style="display: block; padding: 0 10px">                        'screenshot',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'status',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'stylesheet',
</span><span class="cx" style="display: block; padding: 0 10px">                        'tags',
</span><span class="cx" style="display: block; padding: 0 10px">                        'template',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -170,12 +188,74 @@
</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">+         * Test retrieving a collection of inactive themes.
+        *
+        * @ticket 50152
+        */
+       public function test_get_items_inactive() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'GET', self::$themes_route );
+               $request->set_param( 'status', 'inactive' );
+
+               $response = rest_get_server()->dispatch( $request );
+
+               $this->assertEquals( 200, $response->get_status() );
+               $data = $response->get_data();
+
+               $fields = array(
+                       '_links',
+                       'author',
+                       'author_uri',
+                       'description',
+                       'name',
+                       'requires_php',
+                       'requires_wp',
+                       'screenshot',
+                       'status',
+                       'stylesheet',
+                       'tags',
+                       'template',
+                       'textdomain',
+                       'theme_uri',
+                       'version',
+               );
+               $this->assertEqualSets( $fields, array_keys( $data[0] ) );
+
+               $this->assertContains( 'twentytwenty', wp_list_pluck( $data, 'stylesheet' ) );
+               $this->assertNotContains( get_stylesheet(), wp_list_pluck( $data, 'stylesheet' ) );
+       }
+
+       /**
+        * Test retrieving a collection of inactive themes.
+        *
+        * @ticket 50152
+        */
+       public function test_get_items_active_and_inactive() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'GET', self::$themes_route );
+               $request->set_param( 'status', array( 'active', 'inactive' ) );
+
+               $response = rest_get_server()->dispatch( $request );
+
+               $this->assertEquals( 200, $response->get_status() );
+               $data = $response->get_data();
+
+               $this->assertContains( 'twentytwenty', wp_list_pluck( $data, 'stylesheet' ) );
+               $this->assertContains( get_stylesheet(), wp_list_pluck( $data, 'stylesheet' ) );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 46723
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 50152
+        * @dataProvider data_get_items_by_status
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_get_items_logged_out() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_get_items_logged_out( $status, $error_code ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_set_current_user( 0 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = self::perform_active_theme_request();
-               $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $request = new WP_REST_Request( 'GET', self::$themes_route );
+               $request->set_param( 'status', $status );
+
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( $error_code, $response, 401 );
</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">@@ -182,14 +262,55 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * An error should be returned when the user does not have the edit_posts capability.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 45016
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 50152
+        * @dataProvider data_get_items_by_status
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_get_items_no_permission() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_get_items_no_permission( $status, $error_code ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_set_current_user( self::$subscriber_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = self::perform_active_theme_request();
-               $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $request = new WP_REST_Request( 'GET', self::$themes_route );
+               $request->set_param( 'status', $status );
+
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( $error_code, $response, 403 );
</ins><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">+        public function data_get_items_by_status() {
+               return array(
+                       array( 'active', 'rest_cannot_view_active_theme' ),
+                       array( 'active, inactive', 'rest_cannot_view_themes' ),
+                       array( 'inactive', 'rest_cannot_view_themes' ),
+                       array( '', 'rest_cannot_view_themes' ),
+               );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 50152
+        * @dataProvider data_get_items_by_status_for_contributor
+        */
+       public function test_get_items_contributor( $status, $error_code ) {
+               wp_set_current_user( self::$contributor_id );
+               $request = new WP_REST_Request( 'GET', self::$themes_route );
+               $request->set_param( 'status', $status );
+
+               $response = rest_get_server()->dispatch( $request );
+
+               if ( $error_code ) {
+                       $this->assertErrorResponse( $error_code, $response, 403 );
+               } else {
+                       $this->assertEquals( 200, $response->get_status() );
+               }
+       }
+
+       public function data_get_items_by_status_for_contributor() {
+               return array(
+                       array( 'active', '' ),
+                       array( 'active, inactive', 'rest_cannot_view_themes' ),
+                       array( 'inactive', 'rest_cannot_view_themes' ),
+                       array( '', 'rest_cannot_view_themes' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 46723
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_item_single_post_type_cap() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -221,7 +342,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = self::perform_active_theme_request( 'OPTIONS' );
</span><span class="cx" style="display: block; padding: 0 10px">                $data       = $response->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">                $properties = $data['schema']['properties'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertSame( 14, count( $properties ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( 15, count( $properties ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'author', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'raw', $properties['author']['properties'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -242,6 +363,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'requires_php', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'requires_wp', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'screenshot', $properties );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertArrayHasKey( 'status', $properties );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertArrayHasKey( 'stylesheet', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'tags', $properties );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1083,11 +1205,83 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_update_item() {}
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * The get_item() method does not exist for themes.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Test single theme
+        *
+        * @ticket 50152
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_get_item() {}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_get_item() {
+               wp_set_current_user( self::$admin_id );
+               $route    = sprintf( '%s/%s', self::$themes_route, WP_DEFAULT_THEME );
+               $request  = new WP_REST_Request( 'GET', $route );
+               $response = rest_get_server()->dispatch( $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( 200, $response->get_status() );
+               $data         = $response->get_data();
+               $links        = $response->get_links();
+               $fields       = array(
+                       'author',
+                       'author_uri',
+                       'description',
+                       'name',
+                       'requires_php',
+                       'requires_wp',
+                       'screenshot',
+                       'status',
+                       'stylesheet',
+                       'tags',
+                       'template',
+                       'textdomain',
+                       'theme_uri',
+                       'version',
+               );
+               $fields_links = array( 'collection', 'self' );
+
+               $this->assertEqualSets( $fields, array_keys( $data ) );
+               $this->assertEqualSets( $fields_links, array_keys( $links ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 50152
+        */
+       public function test_get_item_no_permission() {
+               wp_set_current_user( self::$subscriber_id );
+               $request  = new WP_REST_Request( 'GET', self::$themes_route . '/' . WP_DEFAULT_THEME );
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( 'rest_cannot_view_themes', $response, 403 );
+       }
+
+       /**
+        * @ticket 50152
+        */
+       public function test_get_active_item_no_permission() {
+               wp_set_current_user( self::$subscriber_id );
+               $request  = new WP_REST_Request( 'GET', self::$themes_route . '/' . get_stylesheet() );
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( 'rest_cannot_view_active_theme', $response, 403 );
+       }
+
+       /**
+        * @ticket 50152
+        */
+       public function test_get_item_invalid() {
+               wp_set_current_user( self::$admin_id );
+               $request  = new WP_REST_Request( 'GET', self::$themes_route . '/invalid' );
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( 'rest_theme_not_found', $response, 404 );
+       }
+
+       /**
+        * @ticket 50152
+        */
+       public function test_get_active_item_as_contributor() {
+               $route    = sprintf( '%s/%s', self::$themes_route, get_stylesheet() );
+               $request  = new WP_REST_Request( 'GET', $route );
+               $response = rest_get_server()->dispatch( $request );
+
+               $this->assertEquals( 200, $response->get_status() );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * The delete_item() method does not exist for themes.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_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-01-03 17:54:48 UTC (rev 49924)
+++ trunk/tests/qunit/fixtures/wp-api-generated.js      2021-01-03 21:45:42 UTC (rev 49925)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5784,41 +5784,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "GET"
</span><span class="cx" style="display: block; padding: 0 10px">                     ],
</span><span class="cx" style="display: block; padding: 0 10px">                     "args": {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        "context": {
-                            "description": "Scope under which the request is made; determines fields present in response.",
-                            "type": "string",
-                            "required": false
-                        },
-                        "page": {
-                            "description": "Current page of the collection.",
-                            "type": "integer",
-                            "default": 1,
-                            "minimum": 1,
-                            "required": false
-                        },
-                        "per_page": {
-                            "description": "Maximum number of items to be returned in result set.",
-                            "type": "integer",
-                            "default": 10,
-                            "minimum": 1,
-                            "maximum": 100,
-                            "required": false
-                        },
-                        "search": {
-                            "description": "Limit results to those matching a string.",
-                            "type": "string",
-                            "required": false
-                        },
</del><span class="cx" style="display: block; padding: 0 10px">                         "status": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Limit result set to themes assigned one or more statuses.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "array",
</span><span class="cx" style="display: block; padding: 0 10px">                             "items": {
</span><span class="cx" style="display: block; padding: 0 10px">                                 "enum": [
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                    "active"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                    "active",
+                                    "inactive"
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ],
</span><span class="cx" style="display: block; padding: 0 10px">                                 "type": "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                            "required": true
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "required": 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">@@ -5827,6 +5803,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 "self": "http://example.org/index.php?rest_route=/wp/v2/themes"
</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">+        "/wp/v2/themes/(?P<stylesheet>[\\w-]+)": {
+            "namespace": "wp/v2",
+            "methods": [
+                "GET"
+            ],
+            "endpoints": [
+                {
+                    "methods": [
+                        "GET"
+                    ],
+                    "args": {
+                        "stylesheet": {
+                            "description": "The theme's stylesheet. This uniquely identifies the theme.",
+                            "type": "string",
+                            "required": false
+                        }
+                    }
+                }
+            ]
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "/wp/v2/plugins": {
</span><span class="cx" style="display: block; padding: 0 10px">             "namespace": "wp/v2",
</span><span class="cx" style="display: block; padding: 0 10px">             "methods": [
</span></span></pre>
</div>
</div>

</body>
</html>