Skip to content

Commit

Permalink
Code Modernization: Fix "passing null to non-nullable" deprecation no…
Browse files Browse the repository at this point in the history
…tice in `WP_Comment_Query::get_comment_ids()`.

The `WP_Comment_Query::get_comment_ids()` method is supposed to handle `null` as a search query, but was throwing a `strlen(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1.

Discovered via and already covered via the pre-existing `Tests_Comment_Query::test_search_null_should_be_ignored()` test method.

Follow-up to [36345], [48275].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51806 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
hellofromtonya committed Sep 13, 2021
1 parent 092ee0f commit 08fe046
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-comment-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ protected function get_comment_ids() {
}

// Falsey search strings are ignored.
if ( strlen( $this->query_vars['search'] ) ) {
if ( isset( $this->query_vars['search'] ) && strlen( $this->query_vars['search'] ) ) {
$search_sql = $this->get_search_sql(
$this->query_vars['search'],
array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )
Expand Down

0 comments on commit 08fe046

Please sign in to comment.