Ensure WP_Theme::$template is not null - #10837
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
My first thought was that the wordpress-develop/src/wp-includes/class-wp-theme.php Lines 158 to 167 in 905ce8f But I see that it should indeed be left unset/null in the case of an error, where previously it short-circuits: wordpress-develop/src/wp-includes/class-wp-theme.php Lines 287 to 295 in 905ce8f But I see you addressed this in the ticket description 👍🏻 |
Cover the `theme_child_invalid` branch of `WP_Theme::__construct()`, which previously returned early without initializing `$this->template`. The first test asserts the behaviors described on the ticket: `get_template()` returns the stylesheet rather than `null`, and `get_template_directory()` and `get_template_directory_uri()` resolve to the theme's own directory rather than to the theme root. Before the fix the URI method also emitted a `rawurlencode(): Passing null to parameter WordPress#1 ($string) of type string is deprecated` notice. The second test constructs the theme twice so the second instance is read back from the themes cache, covering the `template` key added to the `cache_add()` call. That path returns early on `$this->errors`, so without the cached value the property would still be `null`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
In cdb05c8 I added tests to cover the issues you covered in the "Resulting behaviour" section of the ticket. Without the fixes you've added, there are test failures: And with your changes, they are fixed. |
When a theme's `Template` header names the theme's own directory, `WP_Theme::__construct()` recorded the `theme_child_invalid` error and returned before assigning `$this->template`, leaving the property unset. As a result `WP_Theme::get_template()` returned `null` despite being documented as returning a string. That error scenario now assigns the stylesheet to `$this->template` and stores it in the theme cache, matching how the `theme_no_stylesheet` and `theme_no_parent` errors are already handled. The invalid-theme error itself is unchanged, and tests cover both the fresh and the cached construction paths. Developed in #10837. Follow-up to r41601. Props marian1, westonruter. See #40820. Fixes #64582. git-svn-id: https://develop.svn.wordpress.org/trunk@63507 602fd350-edb4-49c9-b593-d223f7449a82
When a theme's `Template` header names the theme's own directory, `WP_Theme::__construct()` recorded the `theme_child_invalid` error and returned before assigning `$this->template`, leaving the property unset. As a result `WP_Theme::get_template()` returned `null` despite being documented as returning a string. That error scenario now assigns the stylesheet to `$this->template` and stores it in the theme cache, matching how the `theme_no_stylesheet` and `theme_no_parent` errors are already handled. The invalid-theme error itself is unchanged, and tests cover both the fresh and the cached construction paths. Developed in WordPress/wordpress-develop#10837. Follow-up to r41601. Props marian1, westonruter. See #40820. Fixes #64582. Built from https://develop.svn.wordpress.org/trunk@63507 git-svn-id: http://core.svn.wordpress.org/trunk@62683 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/64582
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.