From f8b436bb20943592cb25d2ebfa1c748238b1d235 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Mon, 17 Jun 2024 18:03:13 +0000 Subject: [PATCH] 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()` ([https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php?annotate=blame#L4952 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** [https://developer.wordpress.org/apis/options/#writing 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 ([https://core.trac.wordpress.org/browser/tags/6.5.4/src/wp-admin/options-writing.php#L233 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 [https://core.trac.wordpress.org/browser/trunk/src/wp-admin/options.php#L333 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. Built from https://develop.svn.wordpress.org/trunk@58425 git-svn-id: http://core.svn.wordpress.org/trunk@57874 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/options.php | 4 +++- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-admin/options.php b/wp-admin/options.php index 34b98ae294..6916e2e25c 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -181,7 +181,9 @@ if ( ! is_multisite() ) { $allowed_options['general'][] = 'default_role'; $allowed_options['writing'] = array_merge( $allowed_options['writing'], $mail_options ); - $allowed_options['writing'][] = 'ping_sites'; + if ( '1' === get_option( 'blog_public' ) ) { + $allowed_options['writing'][] = 'ping_sites'; + } $allowed_options['media'][] = 'uploads_use_yearmonth_folders'; diff --git a/wp-includes/version.php b/wp-includes/version.php index 0e994d8bd0..3691c5f740 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-beta2-58424'; +$wp_version = '6.6-beta2-58425'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.