mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
Merge pull request #1680 from ultimatemember/fix/rp_email
Fixes reset password email for different cases
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,26 @@ 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}" );
|
||||
|
||||
// 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 +474,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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1484,22 +1484,34 @@ 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' ) );
|
||||
$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' => um_user( 'ID' ) ) ) );
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', $mail_args ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Password changed email
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user