diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 700a758990664..d078d3d0f8a85 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3106,7 +3106,7 @@ function check_password_reset_key( $key, $login ) { * Defaults to `$_POST['user_login']` if not set. * @return true|WP_Error True when finished, WP_Error object on error. */ -function retrieve_password( $user_login = null ) { +function retrieve_password( $user_login = '' ) { $errors = new WP_Error(); $user_data = false; diff --git a/tests/phpunit/tests/user/retrievePassword.php b/tests/phpunit/tests/user/retrievePassword.php index c0f6f28c30322..be77e99187c50 100644 --- a/tests/phpunit/tests/user/retrievePassword.php +++ b/tests/phpunit/tests/user/retrievePassword.php @@ -74,4 +74,17 @@ public function test_retrieve_password_should_fetch_user_by_login_if_not_found_b $this->assertTrue( retrieve_password( 'foo@example.com' ), 'Fetching user by login failed.' ); $this->assertTrue( retrieve_password( 'bar@example.com' ), 'Fetching user by email failed.' ); } + + /** + * Tests that PHP 8.1 "passing null to non-nullable" deprecation notice + * is not thrown when the `$user_login` parameter is empty. + * + * The notice that we should not see: + * `Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated`. + * + * @ticket 62298 + */ + public function test_retrieve_password_does_not_throw_deprecation_notice_with_default_parameters() { + $this->assertWPError( retrieve_password() ); + } }