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
+13
View File
@@ -43,6 +43,7 @@ if ( ! class_exists( 'um\action_scheduler\Init' ) ) {
public function __construct() {
if ( ! $this->can_be_active() ) {
add_action( 'init', array( $this, 'add_notice' ) );
add_filter( 'um_site_health_extend', array( $this, 'change_site_health' ) );
} else {
add_filter( 'um_settings_structure', array( $this, 'add_setting' ) );
// Since 2.10.3 we load library as soon as there are required library files.
@@ -67,6 +68,18 @@ if ( ! class_exists( 'um\action_scheduler\Init' ) ) {
);
}
/**
* Adds the Action Scheduler setting to Ultimate Member feature settings
*
* @param array $settings
*
* @return array
*/
public function change_site_health( $site_health ) {
$site_health['ultimate-member']['fields']['enable_as_email_sending']['value'] = __( 'No', 'ultimate-member' );
return $site_health;
}
/**
* Adds the Action Scheduler setting to Ultimate Member feature settings
*
+13 -1
View File
@@ -1238,6 +1238,10 @@ class Site_Health {
'label' => __( 'Remove Data on Uninstall?', 'ultimate-member' ),
'value' => UM()->options()->get( 'uninstall_on_delete' ) ? $labels['yes'] : $labels['no'],
),
'enable_as_email_sending' => array(
'label' => __( 'Email sending by Action Scheduler', 'ultimate-member' ),
'value' => UM()->options()->get( 'enable_as_email_sending' ) ? $labels['yes'] : $labels['no'],
),
);
// Secure settings
@@ -2549,6 +2553,14 @@ class Site_Health {
}
}
return $info;
/**
* Filters the site health information.
* @hook um_site_health_extend
* @since 2.10.3
* @param {array} info - The site health info to be filtered.
*
* @return {array} The filtered site health info.
*/
return apply_filters( 'um_site_health_extend', $info );
}
}
+5 -1
View File
@@ -48,6 +48,10 @@ if ( ! class_exists( 'um\core\Password' ) ) {
// New reset password key via WordPress native field. It maybe already exists here but generated twice to make sure that emailed with a proper and fresh hash.
// But doing that only once in 1 request using static variable. Different email placeholders can use reset_url() and we have to use 1 time generated to avoid invalid keys.
$user_data = get_userdata( $user_id );
if ( empty( $user_data ) ) {
return '';
}
if ( empty( $reset_key ) ) {
$reset_key = UM()->user()->maybe_generate_password_reset_key( $user_data );
}
@@ -466,7 +470,7 @@ if ( ! class_exists( 'um\core\Password' ) ) {
um_fetch_user( $data->ID );
if ( false === UM()->options()->get( 'only_approved_user_reset_password' ) || UM()->common()->users()->has_status( $data->ID, 'approved' ) ) {
UM()->user()->password_reset();
UM()->user()->password_reset( $data->ID );
}
}
+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
*