Skip to content

Commit 4fc5f0e

Browse files
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
1 parent 2d98ba4 commit 4fc5f0e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/wp-includes/class-wp-customize-manager.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,6 +4686,21 @@ public function get_return_url() {
46864686

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;
46914706
} elseif ( $this->preview_url ) {
@@ -4694,21 +4709,6 @@ public function get_return_url() {
46944709
$return_url = home_url( '/' );
46954710
}
46964711

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-
}
4710-
}
4711-
47124712
return $return_url;
47134713
}
47144714

0 commit comments

Comments
 (0)