From eb9aaa5f9ea1b0d3e343dcea35669a27ebc9f42b Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Tue, 10 Oct 2023 12:52:25 +0000 Subject: [PATCH] Options, Meta APIs: Check setting group exists before search in unregister_setting(). Checks if the given `$option_group` exists before searching for the `$option_name`. Sets the `$pos` to `false`, as `array_search()` returns `false` if the option name (needle) does not exist. This changeset fixes 2 different PHP Warning|Notice scenarios: 1. When the global `$new_allowed_options` is `null`, fixes raising `Trying to access array offset on value of type null` PHP Notice (PHP 7.4) | Warning (on PHP 8). 2. When the global `$new_allowed_options` is an `array` and the setting group key does not exist, fixes raising "Undefined index: unknown_setting_group" PHP Notice (PHP 7) | Warning (on PHP 8). For both scenarios, the `array_search()` is skipped and the `$pos` is set to a default of `false`, i.e. which is the value returned when `array_search()` is unsuccessful. Props xknown, hellofromTonya, nicolefurlan, oglekler, SergeyBiryukov, shailu25. Fixes #57674. Built from https://develop.svn.wordpress.org/trunk@56817 git-svn-id: http://core.svn.wordpress.org/trunk@56329 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/option.php | 5 ++++- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index c813695030..4df0b81458 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -2903,7 +2903,10 @@ function unregister_setting( $option_group, $option_name, $deprecated = '' ) { $option_group = 'reading'; } - $pos = array_search( $option_name, (array) $new_allowed_options[ $option_group ], true ); + $pos = false; + if ( isset( $new_allowed_options[ $option_group ] ) ) { + $pos = array_search( $option_name, (array) $new_allowed_options[ $option_group ], true ); + } if ( false !== $pos ) { unset( $new_allowed_options[ $option_group ][ $pos ] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 0b8b50392f..aa4d904018 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta2-56816'; +$wp_version = '6.4-beta2-56817'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.