Make WordPress Core


Ignore:
Timestamp:
12/14/2021 06:22:07 PM (3 years ago)
Author:
hellofromTonya
Message:

REST API: Add block theme support for valid non-alphanumeric characters in theme's directory name.

Themes whose wp-content/themes/<dirname> include valid non-alphanumeric (cross-platform) characters work for non-block themes, but did not previously resolve for block themes. For example, a block theme in wp-content/themes/twentytwentytwo-0.4.0/ directory resulted a 404 "No route was found matching the URL and request method" response when attempting to customize it in the Site Editor.

This commit adds support for the following characters in a theme's root directory: _, ., @, [, ], (, and ). Subdirectory themes and - are already supported.

Follow-up to [51003], [52051], [52275].

Props mkaz, costdev, hellofromTonya, jffng, justinahinon, peterwilsoncc, spacedmonkey, TimothyBlynJacobs.
Fixes #54596.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

    r52374 r52376  
    4242        register_rest_route(
    4343            $this->namespace,
    44             '/' . $this->rest_base . '/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)',
     44            '/' . $this->rest_base . '/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)',
    4545            array(
    4646                array(
     
    5050                    'args'                => array(
    5151                        'stylesheet' => array(
    52                             'description' => __( 'The theme identifier' ),
    53                             'type'        => 'string',
     52                            'description'       => __( 'The theme identifier' ),
     53                            'type'              => 'string',
     54                            'sanitize_callback' => array( $this, '_sanitize_global_styles_callback' ),
    5455                        ),
    5556                    ),
     
    5859        );
    5960
    60         // Lists/updates a single gloval style variation based on the given id.
     61        // Lists/updates a single global style variation based on the given id.
    6162        register_rest_route(
    6263            $this->namespace,
    63             '/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
     64            '/' . $this->rest_base . '/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)',
    6465            array(
    6566                array(
     
    6970                    'args'                => array(
    7071                        'id' => array(
    71                             'description' => __( 'The id of a template' ),
    72                             'type'        => 'string',
     72                            'description'       => __( 'The id of a template' ),
     73                            'type'              => 'string',
     74                            'sanitize_callback' => array( $this, '_sanitize_global_styles_callback' ),
    7375                        ),
    7476                    ),
     
    8385            )
    8486        );
     87    }
     88
     89    /**
     90     * Sanitize the global styles ID or stylesheet to decode endpoint.
     91     * For example, `wp/v2/global-styles/templatetwentytwo%200.4.0`
     92     * would be decoded to `templatetwentytwo 0.4.0`.
     93     *
     94     * @since 5.9.0
     95     *
     96     * @param string $id_or_stylesheet Global styles ID or stylesheet.
     97     * @return string Sanitized global styles ID or stylesheet.
     98     */
     99    public function _sanitize_global_styles_callback( $id_or_stylesheet ) {
     100        return urldecode( $id_or_stylesheet );
    85101    }
    86102
     
    520536     *
    521537     * @param WP_REST_Request $request The request instance.
    522      *
    523538     * @return WP_REST_Response|WP_Error
    524539     */
Note: See TracChangeset for help on using the changeset viewer.