Refactor password reset URL handling and email dispatch.

Added optional parameter to `reset_url` for user-specific handling. Updated email dispatch logic to include dynamic generation of the password reset link with proper placeholder replacements.
This commit is contained in:
Mykyta Synelnikov
2025-04-23 14:35:38 +03:00
parent 54deffd244
commit db0da58351
2 changed files with 17 additions and 6 deletions
+7 -3
View File
@@ -36,12 +36,16 @@ if ( ! class_exists( 'um\core\Password' ) ) {
/**
* Get Reset URL
*
* @return bool|string
* @param int|null $user_id
*
* @return string
*/
public function reset_url() {
public function reset_url( $user_id = null ) {
static $reset_key = null;
$user_id = um_user( 'ID' );
if ( is_null( $user_id ) ) {
$user_id = um_user( 'ID' );
}
delete_option( "um_cache_userdata_{$user_id}" );
+10 -3
View File
@@ -1499,10 +1499,17 @@ if ( ! class_exists( 'um\core\User' ) ) {
$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' ) );
$mail_args = array(
'fetch_user_id' => $user_id,
'tags' => array(
'{password_reset_link}',
),
'tags_replace' => array(
UM()->password()->reset_url( $user_id ),
),
);
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', array( 'fetch_user_id' => $user_id ) ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', $mail_args ) );
}
/**