mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-15 20:53:39 +09:00
Refactor Action Scheduler for not only email handling.
Updated the Action Scheduler implementation to improve flexibility and clarity. Replaced the 'enable_action_scheduler' option with 'enable_as_email_sending' for better specificity. Introduced hook-based checks to selectively enable email scheduling, ensuring compatibility and optimized performance.
This commit is contained in:
@@ -17,10 +17,18 @@ if ( ! class_exists( 'um\common\actions\Emails' ) ) {
|
||||
class Emails {
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'um_action_scheduler_is_hook_enabled', array( $this, 'is_enabled' ), 10, 2 );
|
||||
add_action( 'um_dispatch_email', array( $this, 'send' ), 10, 3 );
|
||||
add_action( 'um_before_email_notification_sending', array( $this, 'before_email_send' ), 10, 2 );
|
||||
}
|
||||
|
||||
public function is_enabled( $is_enabled, $hook ) {
|
||||
if ( 'um_dispatch_email' === $hook ) {
|
||||
$is_enabled = UM()->options()->get( 'enable_as_email_sending' );
|
||||
}
|
||||
return $is_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email
|
||||
*
|
||||
@@ -36,7 +44,7 @@ if ( ! class_exists( 'um\common\actions\Emails' ) ) {
|
||||
// @todo Workaround for now. Maybe we need to put base $user_id everytime
|
||||
if ( array_key_exists( 'fetch_user_id', $args ) ) {
|
||||
// When Action Scheduler is enabled, email sending script is located out of basic functionality, so we need to fetch the user for replace placeholders.
|
||||
if ( UM()->maybe_action_scheduler()->is_enabled() ) {
|
||||
if ( UM()->maybe_action_scheduler()->is_hook_enabled( 'um_dispatch_email' ) ) {
|
||||
um_fetch_user( $args['fetch_user_id'] );
|
||||
}
|
||||
unset( $args['fetch_user_id'] );
|
||||
@@ -56,7 +64,7 @@ if ( ! class_exists( 'um\common\actions\Emails' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function before_email_send( $email, $template ) {
|
||||
if ( ! UM()->maybe_action_scheduler()->is_enabled() ) {
|
||||
if ( ! UM()->maybe_action_scheduler()->is_hook_enabled( 'um_dispatch_email' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user