From d83f8e682c3847231950ea81afb9dba9f760ed35 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 3 Oct 2022 15:22:10 +0000 Subject: [PATCH] Code Modernization: Correct default values in `wp_handle_comment_submission()`. This affects the following parameters subsequently passed to `wp_new_comment()`: * `comment_author` * `comment_author_email` * `comment_author_url` * `comment_content` The default values for these parameters were previously set to `null`, causing PHP 8.1 "null to non-nullable" deprecation notices when running sanitization filters on them via `wp_filter_comment()`. While the deprecation notices were temporarily silenced in the unit test suite, that caused an unexpected issue in a test for [source:tags/6.0.2/tests/phpunit/tests/comment-submission.php#L202 submitting a comment to a password protected post], where the `$_COOKIE[ 'wp-postpass_' . COOKIEHASH ]` value was no longer unset, as the test stopped any further execution once the deprecation notice was triggered. Due to how WordPress handles password protected posts, once that value is set, it affects all posts protected with the same password, so this resulted in unintentionally affecting [source:tags/6.0.2/tests/phpunit/tests/rest-api/rest-posts-controller.php#L1866 another test] which happened to use the same password. These values are all documented to be a string in various related filters, and core also expects them to be a string, so there is no reason for these defaults to be set to `null`. Setting them to an empty string instead resolves the issues. This commit includes: * Setting the defaults in `wp_handle_comment_submission()` to an empty string. * Adding a dedicated unit test to verify the type of these default values. * Removing the deprecation notice silencing as no longer needed. Follow-up to [34799], [34801], [51968]. Props jrf, desrosj, mukesh27, SergeyBiryukov. Fixes #56712. See #56681, #55656. Built from https://develop.svn.wordpress.org/trunk@54368 git-svn-id: http://core.svn.wordpress.org/trunk@53927 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 8 ++++---- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 4777b91dff..77bc6171ee 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -3427,10 +3427,10 @@ function _close_comments_for_old_post( $open, $post_id ) { */ function wp_handle_comment_submission( $comment_data ) { $comment_post_id = 0; - $comment_author = null; - $comment_author_email = null; - $comment_author_url = null; - $comment_content = null; + $comment_author = ''; + $comment_author_email = ''; + $comment_author_url = ''; + $comment_content = ''; $comment_parent = 0; $user_id = 0; diff --git a/wp-includes/version.php b/wp-includes/version.php index 89279208ba..8975750b9d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta2-54367'; +$wp_version = '6.1-beta2-54368'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.