Make WordPress Core


Ignore:
Timestamp:
07/04/2023 01:40:55 PM (14 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/tests/phpunit/tests/option/sanitizeOption.php

    r55562 r56132  
    3737            array( 'blog_charset', 'UTF-8', 'UTF-8' ),
    3838            array( 'blog_charset', 'charset', '">charset<"' ),
     39            array( 'blog_charset', '', null ),
    3940            array( 'blog_public', 1, null ),
    4041            array( 'blog_public', 1, '1' ),
     
    4647            array( 'gmt_offset', '0', 0 ),
    4748            array( 'gmt_offset', '1.5', '1.5' ),
     49            array( 'gmt_offset', '', null ),
    4850            array( 'siteurl', 'http://example.org', 'http://example.org' ),
    4951            array( 'siteurl', 'http://example.org/subdir', 'http://example.org/subdir' ),
Note: See TracChangeset for help on using the changeset viewer.