Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the wp_set_password action to match WordPress core since 6.2.0 #40

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ The `check_password` filter is available just like the default WP function.

This function is included here verbatim but with the addition of returning the hash. The default WP function does not return anything which means you end up hashing it twice for no reason.

The `wp_set_password` action is available just like the default WP function.

## FAQ

**What happens to existing passwords when I install the plugin?**
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/UserPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Filters\expectApplied;
use function Brain\Monkey\Actions\expectDone;

class UserPasswordTest extends TestCase
{
Expand Down Expand Up @@ -37,6 +38,20 @@ public function hashing_password_applies_filter()
->andReturn(Constants::BCRYPT_HASH);
}

/** @test */
public function setting_password_does_action()
{
expect('clean_user_cache')
->once()
->andReturn(true);

expectDone('wp_set_password')
->once()
->with(Constants::PASSWORD, Constants::USER_ID);

wp_set_password(Constants::PASSWORD, Constants::USER_ID);
}

/** @test */
public function bcrypt_passwords_should_be_verified()
{
Expand Down
8 changes: 8 additions & 0 deletions wp-password-bcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ function wp_set_password($password, $user_id)

clean_user_cache($user_id);

/**
* Fires after the user password is set.
*
* @param string $password The plaintext password just set.
* @param int $user_id The ID of the user whose password was just set.
*/
do_action('wp_set_password', $password, $user_id);

return $hash;
}

Expand Down
Loading