diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
index 87051db58e..1c97a9f9d0 100644
a
|
b
|
class WP_REST_Themes_Controller extends WP_REST_Controller { |
58 | 58 | * @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object. |
59 | 59 | */ |
60 | 60 | public function get_items_permissions_check( $request ) { |
61 | | if ( ! is_user_logged_in() || ! current_user_can( 'edit_posts' ) ) { |
| 61 | if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'upload_files' ) ) { |
62 | 62 | return new WP_Error( |
63 | 63 | 'rest_user_cannot_view', |
64 | 64 | __( 'Sorry, you are not allowed to view themes.' ), |
diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php
index 931b479572..5fecbd5077 100644
a
|
b
|
class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { |
155 | 155 | $this->assertEqualSets( $fields, array_keys( $data[0] ) ); |
156 | 156 | } |
157 | 157 | |
| 158 | /** |
| 159 | * @ticket 46723 |
| 160 | */ |
| 161 | public function test_get_items_logged_out() { |
| 162 | wp_set_current_user( 0 ); |
| 163 | $response = self::perform_active_theme_request(); |
| 164 | $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); |
| 165 | } |
| 166 | |
158 | 167 | /** |
159 | 168 | * An error should be returned when the user does not have the edit_posts capability. |
160 | 169 | * |
… |
… |
class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { |
166 | 175 | $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 ); |
167 | 176 | } |
168 | 177 | |
| 178 | /** |
| 179 | * @ticket 46723 |
| 180 | */ |
| 181 | public function test_get_item_upload_files() { |
| 182 | $user = self::factory()->user->create_and_get(); |
| 183 | $user->add_cap( 'upload_files' ); |
| 184 | wp_set_current_user( $user->ID ); |
| 185 | |
| 186 | $response = self::perform_active_theme_request(); |
| 187 | $this->assertEquals( 200, $response->get_status() ); |
| 188 | } |
| 189 | |
169 | 190 | /** |
170 | 191 | * Test an item is prepared for the response. |
171 | 192 | * |