Fixes 'um_dispatch_email' action #1589

* Sending email notifications directly (without Action Scheduler) on user delete action;
* Changed activation handler priority for integration with Action Scheduler
* Added 'fetch_user_id' argument for fetching the necessary user before email sending when Action Scheduler is active.
This commit is contained in:
Mykyta Synelnikov
2024-11-19 17:48:10 +02:00
parent 1a11581d12
commit 8d33c43130
7 changed files with 59 additions and 19 deletions
+2 -1
View File
@@ -31,7 +31,8 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
add_action( 'init', array( &$this, 'check_for_querystrings' ), 1 );
add_action( 'init', array( &$this, 'activate_account_via_email_link' ), 1 );
// don't use lower than 2 priority because there is sending email inside, but Action Scheduler is init on 1st priority.
add_action( 'init', array( &$this, 'activate_account_via_email_link' ), 2 );
}
/**
+10 -9
View File
@@ -153,9 +153,9 @@ if ( ! class_exists( 'um\core\User' ) ) {
add_action( 'init', array( &$this, 'check_membership' ), 10 );
if ( is_multisite() ) {
add_action( 'wpmu_delete_user', array( &$this, 'delete_user_handler' ), 10, 1 );
add_action( 'wpmu_delete_user', array( &$this, 'delete_user_handler' ) );
} else {
add_action( 'delete_user', array( &$this, 'delete_user_handler' ), 10, 1 );
add_action( 'delete_user', array( &$this, 'delete_user_handler' ) );
}
add_action( 'updated_user_meta', array( &$this, 'on_update_usermeta' ), 10, 4 );
@@ -623,14 +623,15 @@ if ( ! class_exists( 'um\core\User' ) ) {
// send email notifications
if ( $this->send_mail_on_delete ) {
$user_email = um_user( 'user_email' );
$template = 'deletion_email';
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $user_email, $template ) );
// Sending without Action Scheduler, because in the scheduled event the user is already deleted.
UM()->mail()->send( $user_email, 'deletion_email' );
$emails = um_multi_admin_email();
if ( ! empty( $emails ) ) {
foreach ( $emails as $email ) {
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_deletion', array( 'admin' => true ) ) );
// Sending without Action Scheduler, because in the scheduled event the user is already deleted.
UM()->mail()->send( $email, 'notification_deletion', array( 'admin' => true ) );
}
}
}
@@ -1517,10 +1518,10 @@ 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' ), 10, 1 );
add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ), 10, 1 );
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' ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', array( 'fetch_user_id' => um_user( 'ID' ) ) ) );
}
@@ -1534,7 +1535,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
um_fetch_user( $user_id );
}
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( um_user( 'user_email' ), 'changedpw_email' ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( um_user( 'user_email' ), 'changedpw_email', array( 'fetch_user_id' => $user_id ) ) );
if ( ! empty( $user_id ) ) {
um_reset_user();
+1 -1
View File
@@ -593,7 +593,7 @@ function um_account_updated_notification( $user_id, $changed ) {
if ( 'password' !== $_POST['_um_account_tab'] || ! UM()->options()->get( 'changedpw_email_on' ) ) {
// Avoid email duplicates (account changed and password changed) on the password change tab.
um_fetch_user( $user_id );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( um_user( 'user_email' ), 'changedaccount_email' ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( um_user( 'user_email' ), 'changedaccount_email', array( 'fetch_user_id' => $user_id ) ) );
}
// phpcs:enable WordPress.Security.NonceVerification
}
+2 -2
View File
@@ -120,9 +120,9 @@ function um_send_registration_notification( $user_id ) {
if ( ! empty( $emails ) ) {
foreach ( $emails as $email ) {
if ( 'pending' !== $registration_status ) {
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_new_user', array( 'admin' => true ) ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_new_user', array( 'admin' => true, 'fetch_user_id' => $user_id ) ) );
} else {
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_review', array( 'admin' => true ) ) );
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_review', array( 'admin' => true, 'fetch_user_id' => $user_id ) ) );
}
}
}