[wp-trac] [WordPress Trac] #54666: Numeric theme not work
WordPress Trac
noreply at wordpress.org
Mon Dec 20 08:52:40 UTC 2021
#54666: Numeric theme not work
-------------------------------------+-------------------------------------
Reporter: winterpsv | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 5.7
Severity: normal | Keywords: needs-patch needs-unit-
Focuses: administration, | tests
template, multisite, rest-api |
-------------------------------------+-------------------------------------
A template with a numeric name is not displayed in the list of active
templates.
How to reproduce the problem:
- Create a template with a numeric name (example 123456).
- Activate the template in the list of templates on your site
The selected template will not appear as active in the list of templates.
Also, it will not be in the list of active templates in the REST API /wp-
json/wp/v2/themes?status=active
This problem also affects the call of functions in the Gutenberg editor
(add_theme_support does not work).
This problem may be related to the fact that when forming an array of
templates, the key is the name of the template, and according to the
documentation, the PHP converts the keys of the array
(https://www.php.net/manual/en/language.types.array.php)
{{{
Additionally the following key casts will occur:
Strings containing valid decimal ints, unless the number is preceded by a
+ sign, will be cast to the int type. E.g. the key "8" will actually be
stored under 8. On the other hand "08" will not be cast, as it isn't a
valid decimal integer.
Floats are also cast to ints, which means that the fractional part will be
truncated. E.g. the key 8.7 will actually be stored under 8.
Bools are cast to ints, too, i.e. the key true will actually be stored
under 1 and the key false under 0.
Null will be cast to the empty string, i.e. the key null will actually be
stored under "".
Arrays and objects can not be used as keys. Doing so will result in a
warning: Illegal offset type.
}}}
Possible suggestions for solving the problem:
File in wp-icnludes/rest-api/endpoints/class-wp-rest-themes-controller.php
replace this
{{{#!php
<?php
/**
* Helper function to compare two themes.
*
* @since 5.7.0
*
* @param WP_Theme $theme_a First theme to compare.
* @param WP_Theme $theme_b Second theme to compare.
* @return bool
*/
protected function is_same_theme( $theme_a, $theme_b ) {
return $theme_a->get_stylesheet() === $theme_b->get_stylesheet();
}
}}}
with this
{{{#!php
<?php
/**
* Helper function to compare two themes.
*
* @since 5.7.0
*
* @param WP_Theme $theme_a First theme to compare.
* @param WP_Theme $theme_b Second theme to compare.
* @return bool
*/
protected function is_same_theme( $theme_a, $theme_b ) {
return (string)$theme_a->get_stylesheet() ===
(string)$theme_b->get_stylesheet();
}
}}}
or, when forming an array of templates, store the name as a value.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54666>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list