From 67863b9fb7cfe47149ccde5ae383208b7e0949eb Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 4 Jul 2023 13:42:24 +0000 Subject: [PATCH] Options, Meta APIs: Check if the `gmt_offset` value is numeric in `sanitize_option()`. When saving the settings via the admin UI, the default value for any options not passed in the current `$_POST` request is set to `null` in `wp-admin/options.php`. Some options, e.g. `blog_public`, then rely on `null` being passed to `update_option()` to determine whether the value was changed or not. This commit resolves a PHP 8.1 deprecation notice when saving the `gmt_offset` option without any changes: {{{ Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated }}} Includes a similar fix for the `blog_charset` option. Follow-up to [4112], [4329], [5541], [21849]. Props adi3890, dhrupo, hrdelwar, hasanmisbah, oglekler, mukesh27, SergeyBiryukov. Fixes #57728. Built from https://develop.svn.wordpress.org/trunk@56132 git-svn-id: http://core.svn.wordpress.org/trunk@55644 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 12 ++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 956e8290e2..50b43a5175 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -4883,7 +4883,11 @@ function sanitize_option( $option, $value ) { break; case 'blog_charset': - $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes. + if ( is_string( $value ) ) { + $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes. + } else { + $value = ''; + } break; case 'blog_public': @@ -4918,7 +4922,11 @@ function sanitize_option( $option, $value ) { break; case 'gmt_offset': - $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes. + if ( is_numeric( $value ) ) { + $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes. + } else { + $value = ''; + } break; case 'siteurl': diff --git a/wp-includes/version.php b/wp-includes/version.php index 88957605b1..54baec6059 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-beta3-56131'; +$wp_version = '6.3-beta3-56132'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.