mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API: Support subdirectory themes in the Themes controller.
This allows for themes that are included inside of a subdirectory, for example `subdir/my-theme`, to be accessed via the single item route of the `/wp/v2/themes` controller. Fixes #54349. git-svn-id: https://develop.svn.wordpress.org/trunk@52017 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -137,7 +137,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
|
||||
'/wp/v2/templates/(?P<parent>[\d]+)/revisions',
|
||||
'/wp/v2/templates/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
|
||||
'/wp/v2/themes',
|
||||
'/wp/v2/themes/(?P<stylesheet>[\w-]+)',
|
||||
'/wp/v2/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)',
|
||||
'/wp/v2/plugins',
|
||||
'/wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?)',
|
||||
'/wp/v2/block-directory/search',
|
||||
|
||||
@@ -151,7 +151,10 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
public function test_register_routes() {
|
||||
$routes = rest_get_server()->get_routes();
|
||||
$this->assertArrayHasKey( self::$themes_route, $routes );
|
||||
$this->assertArrayHasKey( self::$themes_route . '/(?P<stylesheet>[\\w-]+)', $routes );
|
||||
$this->assertArrayHasKey(
|
||||
sprintf( '%s/(?P<stylesheet>%s)', self::$themes_route, WP_REST_Themes_Controller::PATTERN ),
|
||||
$routes
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1281,6 +1284,42 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 54349
|
||||
*/
|
||||
public function test_get_item_subdirectory_theme() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
$request = new WP_REST_Request( 'GET', self::$themes_route . '/subdir/theme2' );
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSame( 'My Subdir Theme', $response->get_data()['name']['raw'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 54349
|
||||
*/
|
||||
public function test_can_support_further_routes() {
|
||||
register_rest_route(
|
||||
'wp/v2',
|
||||
sprintf( '/themes/(?P<stylesheet>%s)//test', WP_REST_Themes_Controller::PATTERN ),
|
||||
array(
|
||||
'callback' => function ( WP_REST_Request $request ) {
|
||||
return $request['stylesheet'];
|
||||
},
|
||||
'permission_callback' => '__return_true',
|
||||
)
|
||||
);
|
||||
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
$response = rest_do_request( self::$themes_route . '/default//test' );
|
||||
$this->assertSame( 'default', $response->get_data() );
|
||||
|
||||
$response = rest_do_request( self::$themes_route . '/subdir/theme2//test' );
|
||||
$this->assertSame( 'subdir/theme2', $response->get_data() );
|
||||
}
|
||||
|
||||
/**
|
||||
* The delete_item() method does not exist for themes.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user