Make WordPress Core


Ignore:
Timestamp:
11/05/2021 02:29:32 AM (2 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r51568 r52017  
    152152        $routes = rest_get_server()->get_routes();
    153153        $this->assertArrayHasKey( self::$themes_route, $routes );
    154         $this->assertArrayHasKey( self::$themes_route . '/(?P<stylesheet>[\\w-]+)', $routes );
     154        $this->assertArrayHasKey(
     155            sprintf( '%s/(?P<stylesheet>%s)', self::$themes_route, WP_REST_Themes_Controller::PATTERN ),
     156            $routes
     157        );
    155158    }
    156159
     
    12831286
    12841287    /**
     1288     * @ticket 54349
     1289     */
     1290    public function test_get_item_subdirectory_theme() {
     1291        wp_set_current_user( self::$admin_id );
     1292        $request  = new WP_REST_Request( 'GET', self::$themes_route . '/subdir/theme2' );
     1293        $response = rest_do_request( $request );
     1294
     1295        $this->assertSame( 200, $response->get_status() );
     1296        $this->assertSame( 'My Subdir Theme', $response->get_data()['name']['raw'] );
     1297    }
     1298
     1299    /**
     1300     * @ticket 54349
     1301     */
     1302    public function test_can_support_further_routes() {
     1303        register_rest_route(
     1304            'wp/v2',
     1305            sprintf( '/themes/(?P<stylesheet>%s)//test', WP_REST_Themes_Controller::PATTERN ),
     1306            array(
     1307                'callback'            => function ( WP_REST_Request $request ) {
     1308                    return $request['stylesheet'];
     1309                },
     1310                'permission_callback' => '__return_true',
     1311            )
     1312        );
     1313
     1314        wp_set_current_user( self::$admin_id );
     1315
     1316        $response = rest_do_request( self::$themes_route . '/default//test' );
     1317        $this->assertSame( 'default', $response->get_data() );
     1318
     1319        $response = rest_do_request( self::$themes_route . '/subdir/theme2//test' );
     1320        $this->assertSame( 'subdir/theme2', $response->get_data() );
     1321    }
     1322
     1323    /**
    12851324     * The delete_item() method does not exist for themes.
    12861325     */
Note: See TracChangeset for help on using the changeset viewer.