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
This commit is contained in:
Sergey Biryukov 2022-10-03 15:22:10 +00:00
parent a68841201d
commit d83f8e682c
2 changed files with 5 additions and 5 deletions

View File

@ -3427,10 +3427,10 @@ function _close_comments_for_old_post( $open, $post_id ) {
*/ */
function wp_handle_comment_submission( $comment_data ) { function wp_handle_comment_submission( $comment_data ) {
$comment_post_id = 0; $comment_post_id = 0;
$comment_author = null; $comment_author = '';
$comment_author_email = null; $comment_author_email = '';
$comment_author_url = null; $comment_author_url = '';
$comment_content = null; $comment_content = '';
$comment_parent = 0; $comment_parent = 0;
$user_id = 0; $user_id = 0;

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.