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. Built from https://develop.svn.wordpress.org/trunk@52376 git-svn-id: http://core.svn.wordpress.org/trunk@51968 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b3c06d8bb1
commit
84d67f77f6
|
@ -41,7 +41,7 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
// List themes global styles.
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)',
|
||||
'/' . $this->rest_base . '/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
|
@ -49,18 +49,19 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
'permission_callback' => array( $this, 'get_theme_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'stylesheet' => array(
|
||||
'description' => __( 'The theme identifier' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'The theme identifier' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => array( $this, '_sanitize_global_styles_callback' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Lists/updates a single gloval style variation based on the given id.
|
||||
// Lists/updates a single global style variation based on the given id.
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
|
||||
'/' . $this->rest_base . '/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
|
@ -68,8 +69,9 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'The id of a template' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'The id of a template' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => array( $this, '_sanitize_global_styles_callback' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -84,6 +86,20 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the global styles ID or stylesheet to decode endpoint.
|
||||
* For example, `wp/v2/global-styles/templatetwentytwo%200.4.0`
|
||||
* would be decoded to `templatetwentytwo 0.4.0`.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $id_or_stylesheet Global styles ID or stylesheet.
|
||||
* @return string Sanitized global styles ID or stylesheet.
|
||||
*/
|
||||
public function _sanitize_global_styles_callback( $id_or_stylesheet ) {
|
||||
return urldecode( $id_or_stylesheet );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given request has access to read a single global style.
|
||||
*
|
||||
|
@ -519,7 +535,6 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
* @since 5.9.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request instance.
|
||||
*
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_theme_item( $request ) {
|
||||
|
|
|
@ -68,7 +68,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
|||
// Lists/updates a single template based on the given id.
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
|
||||
'/' . $this->rest_base . '/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)',
|
||||
array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
|
@ -149,6 +149,9 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
|||
* @return string Sanitized template ID.
|
||||
*/
|
||||
public function _sanitize_template_id( $id ) {
|
||||
// Decode empty space.
|
||||
$id = urldecode( $id );
|
||||
|
||||
$last_slash_pos = strrpos( $id, '/' );
|
||||
if ( false === $last_slash_pos ) {
|
||||
return $id;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-beta2-52375';
|
||||
$wp_version = '5.9-beta2-52376';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue