HEX
Server: Apache/2
System: Linux server-80-13-140-150.da.direct 5.14.0-362.24.1.el9_3.0.1.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 4 22:31:43 UTC 2024 x86_64
User: cpt (1004)
PHP: 8.1.24
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/cpt/public_html/wp-content/plugins/ultimate-member/includes/common/actions/class-emails.php
<?php
namespace um\common\actions;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'um\common\actions\Emails' ) ) {

	/**
	 * Class Emails
	 *
	 * @since 2.9.0
	 *
	 * @package um\common\actions
	 */
	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
		 *
		 * @param string $user_email User email.
		 * @param string $template   Template name.
		 * @param array  $args       Email additional arguments.
		 */
		public function send( $user_email, $template, $args = array() ) {
			if ( empty( $user_email ) && empty( $template ) ) {
				return;
			}

			// @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_hook_enabled( 'um_dispatch_email' ) ) {
					um_fetch_user( $args['fetch_user_id'] );
				}
				unset( $args['fetch_user_id'] );
			}

			UM()->mail()->send( $user_email, $template, $args );
		}

		/**
		 * Add some custom placeholders when sending via Action Scheduler.
		 *
		 * @todo Workaround for now. Maybe we need to handle email placeholders in email class where $user_id is fetched everytime
		 *
		 * @param string $email
		 * @param string $template
		 *
		 * @return void
		 */
		public function before_email_send( $email, $template ) {
			if ( ! UM()->maybe_action_scheduler()->is_hook_enabled( 'um_dispatch_email' ) ) {
				return;
			}

			if ( 'checkmail_email' === $template ) {
				add_filter( 'um_template_tags_patterns_hook', array( UM()->user(), 'add_activation_placeholder' ) );
				add_filter( 'um_template_tags_replaces_hook', array( UM()->user(), 'add_activation_replace_placeholder' ) );
			} elseif ( 'welcome_email' === $template || 'approved_email' === $template || 'resetpw_email' === $template ) {
				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' ) );
			}
		}
	}
}