Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#54666 closed defect (bug) (duplicate)

Numeric theme not work

Reported by: winterpsv's profile winterpsv Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.7
Component: REST API Keywords: needs-patch needs-unit-tests
Focuses: administration, template, multisite, rest-api Cc:

Description

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
/**
 * 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
/**
 * 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.

Change History (1)

#1 @SergeyBiryukov
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #54645.

Note: See TracTickets for help on using tickets.