Taxonomy: Fix strtolower() deprecation in WP_Term_Query::parse_orderby()#12622
Taxonomy: Fix strtolower() deprecation in WP_Term_Query::parse_orderby()#12622Adi-ty wants to merge 2 commits into
Conversation
…y(). Guard null 'orderby' the same way parse_order() already does. https://core.trac.wordpress.org/ticket/65679
|
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. |
There was a problem hiding this comment.
Pull request overview
Addresses a PHP 8.1+ deprecation in WP_Term_Query::parse_orderby() by ensuring the orderby query var is a string before calling strtolower(), preventing notices when callers pass orderby => null. Adds a PHPUnit regression test covering the null orderby case.
Changes:
- Guard
WP_Term_Query::parse_orderby()against non-stringorderbyvalues before lowercasing. - Add a term query test for
orderby => nullto ensure no PHP deprecation and that ordering falls back as expected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/wp-includes/class-wp-term-query.php |
Adds a type guard to prevent strtolower(null) deprecation on PHP 8.1+. |
tests/phpunit/tests/term/query.php |
Adds a regression test for orderby => null behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) ); | ||
|
|
||
| $q = new WP_Term_Query( | ||
| array( | ||
| 'taxonomy' => 'wptests_tax_1', | ||
| 'orderby' => null, | ||
| 'hide_empty' => false, | ||
| 'fields' => 'ids', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertSame( $terms, $q->terms ); | ||
| } |
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. |
|
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters |
| * @param string $orderby_raw Alias for the field to order by. | ||
| * @return string|false Value to used in the ORDER clause. False otherwise. | ||
| */ | ||
| protected function parse_orderby( $orderby_raw ) { | ||
| if ( ! is_string( $orderby_raw ) ) { |
WP_Term_Query::parse_orderby()passes theorderbyquery var straight intostrtolower(). If a caller explicitly passes'orderby' => null, this triggers aDeprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecatednotice on PHP 8.1+.parse_order()in the same class already guards against this with anis_string()check; this PR adds the same guard toparse_orderby(). Anullvalue now falls through to the existing empty-string handling, preserving the currentORDER BY t.term_idfallback behavior with no notice.Adds a test asserting no deprecation is thrown and that ordering falls back to
term_idas before.Trac ticket: https://core.trac.wordpress.org/ticket/65679
Use of AI Tools
AI assistance: Yes
Tool(s): Opencode
Model(s): DeepSeek V4 Flash
Used for: Diagnosing the issue.
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.