Make WordPress Core


Ignore:
Timestamp:
07/04/2023 01:40:55 PM (8 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r56031 r56132  
    48844884
    48854885        case 'blog_charset':
    4886             $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes.
     4886            if ( is_string( $value ) ) {
     4887                $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes.
     4888            } else {
     4889                $value = '';
     4890            }
    48874891            break;
    48884892
     
    49194923
    49204924        case 'gmt_offset':
    4921             $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes.
     4925            if ( is_numeric( $value ) ) {
     4926                $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes.
     4927            } else {
     4928                $value = '';
     4929            }
    49224930            break;
    49234931
Note: See TracChangeset for help on using the changeset viewer.