Make WordPress Core

Changeset 54135


Ignore:
Timestamp:
09/12/2022 09:48:59 PM (21 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Pass correct value to parse_url() in WP_Customize_Manager::get_return_url().

This particular code block only makes sense to run when $this->return_url is not null. Previously, it caused a "passing null to non-nullable" deprecation notice on PHP 8.1.

By moving the code into the if ( $this->return_url ) condition block, the code will only be run when $this->return_url contains a non-falsey/non-null value.

No additional tests added as this issue was found via the existing tests for the function containing the bug.

This solves the following two PHP 8.1 test errors:

1) Tests_WP_Customize_Manager::test_return_url
parse_url(): Passing null to parameter #1 ($url) of type string is deprecated

/var/www/src/wp-includes/class-wp-customize-manager.php:4696
/var/www/tests/phpunit/tests/customize/manager.php:2975
/var/www/vendor/bin/phpunit:123

2) Tests_WP_Customize_Manager::test_customize_pane_settings
parse_url(): Passing null to parameter #1 ($url) of type string is deprecated

/var/www/src/wp-includes/class-wp-customize-manager.php:4696
/var/www/src/wp-includes/class-wp-customize-manager.php:4898
/var/www/tests/phpunit/tests/customize/manager.php:3085
/var/www/vendor/bin/phpunit:123

Follow-up to [46754].

Props jrf, costdev.
See #55656.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r54133 r54135  
    46874687        if ( $this->return_url ) {
    46884688            $return_url = $this->return_url;
     4689
     4690            $return_url_basename = wp_basename( parse_url( $this->return_url, PHP_URL_PATH ) );
     4691            $return_url_query    = parse_url( $this->return_url, PHP_URL_QUERY );
     4692
     4693            if ( 'themes.php' === $return_url_basename && $return_url_query ) {
     4694                parse_str( $return_url_query, $query_vars );
     4695
     4696                /*
     4697                 * If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(),
     4698                 * verify that it belongs to the active theme, otherwise fall back to the Themes screen.
     4699                 */
     4700                if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) {
     4701                    $return_url = admin_url( 'themes.php' );
     4702                }
     4703            }
    46894704        } elseif ( $referer && ! in_array( wp_basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
    46904705            $return_url = $referer;
     
    46934708        } else {
    46944709            $return_url = home_url( '/' );
    4695         }
    4696 
    4697         $return_url_basename = wp_basename( parse_url( $this->return_url, PHP_URL_PATH ) );
    4698         $return_url_query    = parse_url( $this->return_url, PHP_URL_QUERY );
    4699 
    4700         if ( 'themes.php' === $return_url_basename && $return_url_query ) {
    4701             parse_str( $return_url_query, $query_vars );
    4702 
    4703             /*
    4704              * If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(),
    4705              * verify that it belongs to the active theme, otherwise fall back to the Themes screen.
    4706              */
    4707             if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) {
    4708                 $return_url = admin_url( 'themes.php' );
    4709             }
    47104710        }
    47114711
Note: See TracChangeset for help on using the changeset viewer.