From 4fc5f0e58063922635e38e8973ef36efa978b7b3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 12 Sep 2022 21:48:59 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@54135 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-customize-manager.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index e53a6ec477..fe03a93c1e 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -4686,6 +4686,21 @@ final class WP_Customize_Manager { if ( $this->return_url ) { $return_url = $this->return_url; + + $return_url_basename = wp_basename( parse_url( $this->return_url, PHP_URL_PATH ) ); + $return_url_query = parse_url( $this->return_url, PHP_URL_QUERY ); + + if ( 'themes.php' === $return_url_basename && $return_url_query ) { + parse_str( $return_url_query, $query_vars ); + + /* + * If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(), + * verify that it belongs to the active theme, otherwise fall back to the Themes screen. + */ + if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) { + $return_url = admin_url( 'themes.php' ); + } + } } elseif ( $referer && ! in_array( wp_basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) { $return_url = $referer; } elseif ( $this->preview_url ) { @@ -4694,21 +4709,6 @@ final class WP_Customize_Manager { $return_url = home_url( '/' ); } - $return_url_basename = wp_basename( parse_url( $this->return_url, PHP_URL_PATH ) ); - $return_url_query = parse_url( $this->return_url, PHP_URL_QUERY ); - - if ( 'themes.php' === $return_url_basename && $return_url_query ) { - parse_str( $return_url_query, $query_vars ); - - /* - * If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(), - * verify that it belongs to the active theme, otherwise fall back to the Themes screen. - */ - if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) { - $return_url = admin_url( 'themes.php' ); - } - } - return $return_url; }