Make WordPress Core

Changeset 58425

Timestamp:
06/17/2024 06:01:02 PM (7 weeks ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix 'ping_sites' non-nullable deprecation.

When saving options from the Settings page, include the 'ping_sites' option in the allowed "writing" options list only when the 'blog_public' option is '1'.

Fixes a PHP 8.1 and above "null to non-nullable" deprecation notice in sanitize_option() (which happens when here as part of [22255]):

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in .../wp-includes/formatting.php

Explanation

Per the documentation, the ping_sites option requires the 'blog_public' option to have a value of '1' and must be a string data type. null is not valid for this option.

The relationship between the 2 options shows itself in the options-writing.php code (shown here and in [4326]), as the textarea#ping_sites only renders when '1' === get_option( 'blog_public' ).

What happens if 'blog_public' is not '1'?

The 'ping_sites' option will not be a field on the page. Upon saving:

  • HTTP POST ($_POST) does not include 'ping_sites'.
  • Before this commit:
    • The option's value was set to null before being passed to update_option().
    • update_option() invokes sanitize_option().
    • A null value for the 'ping_sites' case was passed to explode(), which threw a deprecation notice on PHP 8.1 and above.
  • With this commit, the 'ping_sites' option is no longer included in the allow list and thus will not be passed to update_options() > sanitize_option() > explode().

Follow-up to [22255], [12825], [4326], [949].

Props kitchin, SergeyBiryukov, swissspidy, devmuhib, rajinsharwar, hellofromTonya.
Fixes #59818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options.php

    r58147 r58425  
    182182
    183183    $allowed_options['writing']   = array_merge( $allowed_options['writing'], $mail_options );
    184     $allowed_options['writing'][] = 'ping_sites';
     184    if ( '1' === get_option( 'blog_public' ) ) {
     185        $allowed_options['writing'][] = 'ping_sites';
     186    }
    185187
    186188    $allowed_options['media'][] = 'uploads_use_yearmonth_folders';
Note: See TracChangeset for help on using the changeset viewer.