[wp-trac] [WordPress Trac] #63252: $tax_url with no path not accounted for in /wp-includes/canonical.php

WordPress Trac noreply at wordpress.org
Tue Apr 8 11:28:51 UTC 2025


#63252: $tax_url with no path not accounted for in /wp-includes/canonical.php
-------------------------------+-----------------------------
 Reporter:  domainsupport      |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Canonical          |    Version:  6.7.2
 Severity:  normal             |   Keywords:  needs-patch
  Focuses:  php-compatibility  |
-------------------------------+-----------------------------
 In the `redirect_canonical()` function in `/wp-includes/canonical.php`, on
 line 346 the `$tax_url` is obtained by ...

 {{{#!php
 <?php
 $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy );
 }}}

 ... which can then be filtered with the `term_link` hook.

 The `$tax_url` is then parsed on line 375 with ...

 {{{#!php
 <?php
 $tax_url = parse_url( $tax_url );
 }}}

 So, if the `$tax_url` is filtered with the `term_link` hook such as the
 new URL doesn't have a path (such as "https://example.com") then the
 following errors are observed ...

 {{{
 [07-Apr-2025 19:45:25 UTC] E_WARNING: Undefined array key "path" in /wp-
 includes/canonical.php on line 383
 [07-Apr-2025 19:45:25 UTC] E_DEPRECATED: basename(): Passing null to
 parameter #1 ($path) of type string is deprecated in /wp-
 includes/canonical.php on line 537
 [07-Apr-2025 19:45:25 UTC] E_DEPRECATED: preg_replace(): Passing null to
 parameter #3 ($subject) of type array|string is deprecated in /wp-
 includes/canonical.php on line 619
 }}}

 To fix this, line 377 needs to be changed from ...

 {{{#!php
 <?php
                                                         if ( ! empty(
 $tax_url['query'] ) ) {
                                                                 //
 Taxonomy accessible via ?taxonomy=...&term=... or any custom query var.
                                                                 parse_str(
 $tax_url['query'], $query_vars );
 $redirect['query'] = add_query_arg( $query_vars, $redirect['query'] );
                                                         } else {
                                                                 //
 Taxonomy is accessible via a "pretty URL".
 $redirect['path'] = $tax_url['path'];
                                                         }
 }}}

 ... to ...

 {{{#!php
 <?php
                                                         if ( ! empty(
 $tax_url['query'] ) ) {
                                                                 //
 Taxonomy accessible via ?taxonomy=...&term=... or any custom query var.
                                                                 parse_str(
 $tax_url['query'], $query_vars );
 $redirect['query'] = add_query_arg( $query_vars, $redirect['query'] );
                                                         } elseif
 (isset($tax_url['path'])) {
                                                                 //
 Taxonomy is accessible via a "pretty URL".
 $redirect['path'] = $tax_url['path'];
                                                         } else {
 $redirect['path'] = '';
                                                         }
 }}}

 This is observed with PHP v8.1 onwards.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63252>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list