Enhance password reset logic and add Action Scheduler filter

Ensure proper handling of user data in password reset functions by adding checks and updating parameter handling. Introduce a new filter to extend site health information and include a setting for enabling email sending via Action Scheduler. Improve code clarity with updated comments and function annotations.
This commit is contained in:
Mykyta Synelnikov
2025-04-22 17:16:55 +03:00
parent 5fdf822183
commit 54deffd244
4 changed files with 41 additions and 7 deletions
+10 -5
View File
@@ -1484,22 +1484,27 @@ if ( ! class_exists( 'um\core\User' ) ) {
return get_password_reset_key( $userdata );
}
/**
* Password reset email
*
* @param int|null $user_id
*
* @return void
*/
function password_reset() {
$userdata = get_userdata( um_user( 'ID' ) );
public function password_reset( $user_id = null ) {
if ( is_null( $user_id ) ) {
$user_id = um_user( 'ID' );
}
$userdata = get_userdata( $user_id );
$this->maybe_generate_password_reset_key( $userdata );
add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ) );
add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', array( 'fetch_user_id' => um_user( 'ID' ) ) ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', array( 'fetch_user_id' => $user_id ) ) );
}
/**
* Password changed email
*