From 59e1077010faa3d88c486dba07705c035b13923e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 12 Sep 2022 21:50:14 +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. Built from https://develop.svn.wordpress.org/trunk@54135 git-svn-id: http://core.svn.wordpress.org/trunk@53694 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-manager.php | 30 +++++++++++----------- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index e53a6ec477..fe03a93c1e 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index ac3f007365..062b451610 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54134'; +$wp_version = '6.1-alpha-54135'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.