From db0da58351e39af71dfb6c4f8639be2c918a725a Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Wed, 23 Apr 2025 14:35:38 +0300 Subject: [PATCH] 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. --- includes/core/class-password.php | 10 +++++++--- includes/core/class-user.php | 13 ++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/includes/core/class-password.php b/includes/core/class-password.php index fcecc441..355f9183 100644 --- a/includes/core/class-password.php +++ b/includes/core/class-password.php @@ -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}" ); diff --git a/includes/core/class-user.php b/includes/core/class-user.php index 6053eefd..630bc515 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -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 ) ); } /**