Skip to content

Commit 6bc26d5

Browse files
Users: Set correct default value for $user_login in retrieve_password().
This resolves a "passing null to non-nullable" deprecation notice on PHP 8.1+: {{{ Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated }}} Follow-up to [50129], [54477]. Props afragen, peterwilsoncc, SergeyBiryukov. Fixes #62298. git-svn-id: https://develop.svn.wordpress.org/trunk@59312 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 58b5c63 commit 6bc26d5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/wp-includes/user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,7 @@ function check_password_reset_key( $key, $login ) {
31063106
* Defaults to `$_POST['user_login']` if not set.
31073107
* @return true|WP_Error True when finished, WP_Error object on error.
31083108
*/
3109-
function retrieve_password( $user_login = null ) {
3109+
function retrieve_password( $user_login = '' ) {
31103110
$errors = new WP_Error();
31113111
$user_data = false;
31123112

tests/phpunit/tests/user/retrievePassword.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,17 @@ public function test_retrieve_password_should_fetch_user_by_login_if_not_found_b
7474
$this->assertTrue( retrieve_password( '[email protected]' ), 'Fetching user by login failed.' );
7575
$this->assertTrue( retrieve_password( '[email protected]' ), 'Fetching user by email failed.' );
7676
}
77+
78+
/**
79+
* Tests that PHP 8.1 "passing null to non-nullable" deprecation notice
80+
* is not thrown when the `$user_login` parameter is empty.
81+
*
82+
* The notice that we should not see:
83+
* `Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated`.
84+
*
85+
* @ticket 62298
86+
*/
87+
public function test_retrieve_password_does_not_throw_deprecation_notice_with_default_parameters() {
88+
$this->assertWPError( retrieve_password() );
89+
}
7790
}

0 commit comments

Comments
 (0)