Files

638 lines
19 KiB
PHP
Raw Permalink Normal View History

<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
2019-04-01 23:44:21 +03:00
2018-03-26 01:27:46 +03:00
if ( ! class_exists( 'um\core\Mail' ) ) {
2018-03-20 13:24:38 +02:00
/**
* Class Mail
* @package um\core
*/
2017-11-01 13:08:28 +02:00
class Mail {
2018-03-20 13:24:38 +02:00
/**
* @var array
*/
public $email_templates = array();
2018-03-20 13:24:38 +02:00
/**
* @var array
*/
public $path_by_slug = array();
2018-03-20 13:24:38 +02:00
/**
* @var array
*/
public $attachments = array();
/**
* @var string
*/
public $headers = '';
/**
* @var string
*/
public $subject = '';
/**
* @var string
*/
public $message = '';
2018-03-20 13:24:38 +02:00
/**
* Mail constructor.
*/
public function __construct() {
add_action( 'init', array( &$this, 'init_paths' ), 0 ); // init class variables on zero-priority.
2017-11-01 13:08:28 +02:00
add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) );
2018-06-07 01:01:42 +03:00
}
2018-03-20 13:24:38 +02:00
/**
2023-10-03 01:29:19 +03:00
* Init paths for email notifications.
2018-03-20 13:24:38 +02:00
*/
public function init_paths() {
2018-03-02 09:55:49 +02:00
/**
2023-10-02 14:51:23 +03:00
* Filters extend email templates path.
*
2023-10-03 01:29:19 +03:00
* @param {array} $paths Email templates paths.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @return {array} Email templates paths.
2023-10-02 14:51:23 +03:00
*
* @since 2.0
* @hook um_email_templates_path_by_slug
*
2023-10-02 15:20:26 +03:00
* @example <caption>Extends email templates path.</caption>
2018-03-02 09:55:49 +02:00
* function my_email_templates_path_by_slug( $paths ) {
* // your code here
* $paths['template_name'] = 'template_path';
2018-03-02 09:55:49 +02:00
* return $paths;
* }
2023-10-02 14:51:23 +03:00
* add_filter( 'um_email_templates_path_by_slug', 'my_email_templates_path_by_slug' );
2018-03-02 09:55:49 +02:00
*/
2017-11-01 13:08:28 +02:00
$this->path_by_slug = apply_filters( 'um_email_templates_path_by_slug', $this->path_by_slug );
}
/**
* Mandrill compatibility
*
* @param $nl2br
* @return bool
*/
public function mandrill_nl2br( $nl2br ) {
if ( ! UM()->options()->get( 'email_html' ) ) {
$nl2br = true; // nl2br for text emails
}
return $nl2br;
}
2017-11-01 13:08:28 +02:00
/**
2023-10-03 01:29:19 +03:00
* Check blog ID on multisite, return '' if single site.
2017-11-01 13:08:28 +02:00
*
2018-06-07 01:01:42 +03:00
* @return string
2017-11-01 13:08:28 +02:00
*/
public function get_blog_id() {
2018-06-07 01:01:42 +03:00
$blog_id = '';
if ( is_multisite() ) {
$blog_id = '/' . get_current_blog_id();
2017-11-01 13:08:28 +02:00
}
2018-06-07 01:01:42 +03:00
return $blog_id;
2017-11-01 13:08:28 +02:00
}
2017-11-01 13:08:28 +02:00
/**
2018-06-07 01:01:42 +03:00
* Locate a template and return the path for inclusion.
2017-11-01 13:08:28 +02:00
*
2018-06-07 01:01:42 +03:00
* @access public
* @param string $template_name
* @return string
2017-11-01 13:08:28 +02:00
*/
2023-06-05 13:38:10 +03:00
public function locate_template( $template_name ) {
2018-06-07 01:01:42 +03:00
// check if there is template at theme folder
$blog_id = $this->get_blog_id();
2018-06-07 01:01:42 +03:00
//get template file from current blog ID folder
$template = locate_template(
array(
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name . '.php',
)
);
// If there isn't template at theme folder for current blog ID get template file from theme folder
2018-06-07 01:01:42 +03:00
if ( is_multisite() && ! $template ) {
$template = locate_template(
array(
trailingslashit( 'ultimate-member/email' ) . $template_name . '.php',
)
);
2018-06-07 01:01:42 +03:00
}
2023-10-03 01:29:19 +03:00
// If there isn't template at theme folder, get template file from plugin dir.
2018-06-07 01:01:42 +03:00
if ( ! $template ) {
2023-09-13 22:56:32 +03:00
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : UM_PATH . 'templates/email';
2018-06-07 01:01:42 +03:00
$template = trailingslashit( $path ) . $template_name . '.php';
}
2018-03-02 09:55:49 +02:00
/**
2023-10-03 01:29:19 +03:00
* Filters email notification template path.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @param {string} $template Email notification template path.
* @param {string} $template_name Email notification template name.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @return {string} Email notification template path.
2023-10-02 14:51:23 +03:00
*
* @since 2.0
* @hook um_locate_email_template
*
* @example <caption>Change email notification template path.</caption>
* function my_locate_email_template( $template, $template_name ) {
2018-03-02 09:55:49 +02:00
* // your code here
2018-06-07 01:01:42 +03:00
* return $template;
2018-03-02 09:55:49 +02:00
* }
2023-10-02 14:51:23 +03:00
* add_filter( 'um_locate_email_template', 'my_locate_email_template', 10, 2 );
2018-03-02 09:55:49 +02:00
*/
2018-06-07 01:01:42 +03:00
return apply_filters( 'um_locate_email_template', $template, $template_name );
2017-11-01 13:08:28 +02:00
}
2017-11-01 13:08:28 +02:00
/**
* @param $slug
* @param $args
* @return bool|string
*/
public function get_email_template( $slug, $args = array() ) {
2017-11-01 13:08:28 +02:00
$located = $this->locate_template( $slug );
2018-03-02 09:55:49 +02:00
/**
2023-10-03 01:29:19 +03:00
* Filters email template location.
2023-10-02 14:51:23 +03:00
*
2023-10-02 15:20:26 +03:00
* @param {string} $located Email template location.
* @param {string} $slug Email template slug.
* @param {array} $args Email template settings.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @return {string} Email template location.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @since 1.3.x
2023-10-02 14:51:23 +03:00
* @hook um_email_template_path
*
* @example <caption>Change email template location.</caption>
2023-10-02 14:54:45 +03:00
* function my_email_template_path( $located, $slug, $args ) {
2018-03-02 09:55:49 +02:00
* // your code here
* return $located;
* }
2023-10-02 14:54:45 +03:00
* add_filter( 'um_email_template_path', 'my_email_template_path', 10, 3 );
2018-03-02 09:55:49 +02:00
*/
2017-11-01 13:08:28 +02:00
$located = apply_filters( 'um_email_template_path', $located, $slug, $args );
2017-11-01 13:08:28 +02:00
if ( ! file_exists( $located ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
return false;
}
2017-11-01 13:08:28 +02:00
ob_start();
2018-03-05 16:35:51 +02:00
/**
2023-10-03 01:29:19 +03:00
* Fires before email template loading.
2023-10-02 14:51:23 +03:00
*
* @param {string} $slug Email template slug.
* @param {string} $located Email template location.
* @param {array} $args Email template arguments.
*
* @since 2.0
* @hook um_before_email_template_part
*
* @example <caption>Action before email template loading.</caption>
2018-03-05 16:35:51 +02:00
* function my_before_email_template_part( $slug, $located, $args ) {
* // your code here
* }
2023-10-03 01:29:19 +03:00
* add_action( 'um_before_email_template_part', 'my_before_email_template_part', 10, 3 );
2018-03-05 16:35:51 +02:00
*/
2017-11-01 13:08:28 +02:00
do_action( 'um_before_email_template_part', $slug, $located, $args );
2023-10-03 01:29:19 +03:00
include $located;
2023-10-02 14:51:23 +03:00
2018-03-05 16:35:51 +02:00
/**
2023-10-03 01:29:19 +03:00
* Fires after email template loading.
2023-10-02 14:51:23 +03:00
*
* @param {string} $slug Email template slug.
* @param {string} $located Email template location.
* @param {array} $args Email template arguments.
*
* @since 2.0
* @hook um_after_email_template_part
*
* @example <caption>Action after email template loading.</caption>
2018-03-05 16:35:51 +02:00
* function my_after_email_template_part( $slug, $located, $args ) {
* // your code here
* }
2023-10-03 01:29:19 +03:00
* add_action( 'um_after_email_template_part', 'my_after_email_template_part', 10, 3 );
2018-03-05 16:35:51 +02:00
*/
2017-11-01 13:08:28 +02:00
do_action( 'um_after_email_template_part', $slug, $located, $args );
2017-11-01 13:08:28 +02:00
return ob_get_clean();
}
2017-11-01 13:08:28 +02:00
/**
2023-10-03 01:29:19 +03:00
* Prepare email template to send.
2017-11-01 13:08:28 +02:00
*
2023-10-03 01:29:19 +03:00
* @param string $slug
* @param array $args
2017-11-01 13:08:28 +02:00
* @return mixed|string
*/
2023-10-02 14:51:23 +03:00
public function prepare_template( $slug, $args = array() ) {
2017-11-01 13:08:28 +02:00
ob_start();
2017-12-11 09:53:38 +02:00
if ( UM()->options()->get( 'email_html' ) ) {
2018-03-02 09:55:49 +02:00
/**
2023-10-03 01:29:19 +03:00
* Filters email notification template header.
2018-03-02 09:55:49 +02:00
*
2023-10-03 01:29:19 +03:00
* @param {string} $header Email notification header. It equals `<html>` by default.
* @param {string} $slug Email template slug.
* @param {array} $args Email template settings.
2023-10-02 14:51:23 +03:00
*
2023-10-02 15:20:26 +03:00
* @return {string} Email notification header.
2023-10-02 14:51:23 +03:00
*
* @since 2.0
* @hook um_email_template_html_formatting
*
* @example <caption>Change email notification template header.</caption>
2018-03-02 09:55:49 +02:00
* function my_email_template_html_formatting( $header, $slug, $args ) {
* // your code here
* return $header;
* }
2023-10-02 14:51:23 +03:00
* add_filter( 'um_email_template_html_formatting', 'my_email_template_html_formatting', 10, 3 );
2018-03-02 09:55:49 +02:00
*/
echo apply_filters( 'um_email_template_html_formatting', '<html>', $slug, $args );
2018-03-05 16:35:51 +02:00
/**
2023-10-03 01:29:19 +03:00
* Fires before email template body display.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @param {string} $slug Email template slug.
* @param {array} $args Email template settings.
2023-10-02 14:51:23 +03:00
*
* @since 2.0
2023-10-03 01:29:19 +03:00
* @hook um_before_email_template_body
2018-03-05 16:35:51 +02:00
*
2023-10-02 14:51:23 +03:00
* @example <caption>Action before email template body display.</caption>
2018-03-05 16:35:51 +02:00
* function my_before_email_template_body( $slug, $args ) {
* // your code here
* }
2023-10-03 01:29:19 +03:00
* add_action( 'um_before_email_template_body', 'my_before_email_template_body', 10, 2 );
2018-03-05 16:35:51 +02:00
*/
2018-03-02 09:55:49 +02:00
do_action( 'um_before_email_template_body', $slug, $args );
/**
2023-10-03 01:29:19 +03:00
* Filters email notification template body additional attributes.
2018-03-02 09:55:49 +02:00
*
2023-10-03 01:29:19 +03:00
* @param {string} $body_attrs Email notification body attributes.
2023-10-02 15:20:26 +03:00
* @param {string} $slug Email template slug.
* @param {array} $args Email template settings.
2023-10-02 14:51:23 +03:00
*
2023-10-02 15:20:26 +03:00
* @return {string} Email notification body attributes.
2023-10-02 14:51:23 +03:00
*
* @since 2.0
* @hook um_email_template_body_attrs
*
* @example <caption>Change email notification template body additional attributes.</caption>
2023-10-03 01:29:19 +03:00
* function my_email_template_body_attrs( $body_attrs, $slug, $args ) {
2018-03-02 09:55:49 +02:00
* // your code here
2023-10-03 01:29:19 +03:00
* return $body_attrs;
2018-03-02 09:55:49 +02:00
* }
2023-10-02 14:51:23 +03:00
* add_filter( 'um_email_template_body_attrs', 'my_email_template_body_attrs', 10, 3 );
2018-03-02 09:55:49 +02:00
*/
2024-01-03 14:24:40 +02:00
$body_attrs = apply_filters( 'um_email_template_body_attrs', 'style="background: #fff;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;"', $slug, $args );
2018-03-02 09:55:49 +02:00
?>
2023-10-03 01:29:19 +03:00
<body <?php echo $body_attrs; ?>>
2018-03-02 09:55:49 +02:00
2018-06-07 01:01:42 +03:00
<?php echo $this->get_email_template( $slug, $args ); ?>
2017-11-01 13:08:28 +02:00
</body>
</html>
2023-10-02 14:51:23 +03:00
<?php
} else {
2023-10-03 01:29:19 +03:00
// Strip tags in plain text email
// Important don't use HTML in plain text emails!
2023-10-02 14:51:23 +03:00
$raw_email_template = $this->get_email_template( $slug, $args );
2023-10-03 01:29:19 +03:00
$plain_email_template = wp_strip_all_tags( $raw_email_template );
2023-10-02 14:51:23 +03:00
if ( $plain_email_template !== $raw_email_template ) {
$plain_email_template = preg_replace( array( '/&nbsp;/mi', '/^\s+/mi' ), array( ' ', '' ), $plain_email_template );
}
echo $plain_email_template;
2017-11-01 13:08:28 +02:00
}
2017-11-01 13:08:28 +02:00
$message = ob_get_clean();
/**
2023-10-03 01:29:19 +03:00
* Filters email notification message content.
2023-10-02 14:51:23 +03:00
*
2023-10-03 01:29:19 +03:00
* @param {string} $message Message content.
* @param {string} $slug Template slug.
* @param {array} $args Notification arguments.
2023-10-02 14:51:23 +03:00
*
2023-10-02 15:20:26 +03:00
* @return {string} Message Content.
2023-10-02 14:51:23 +03:00
*
* @since 2.0
2023-10-03 01:29:19 +03:00
* @hook um_email_send_message_content
2023-10-02 14:51:23 +03:00
*
* @example <caption>Change email notification message content.</caption>
2023-10-02 15:20:26 +03:00
* function my_email_send_message_content( $message, $slug, $args ) {
* // your code here
* return $message;
* }
2023-10-02 15:20:26 +03:00
* add_filter( 'um_email_send_message_content', 'my_email_send_message_content', 10, 3 );
*/
$message = apply_filters( 'um_email_send_message_content', $message, $slug, $args );
2023-10-03 01:29:19 +03:00
// Convert tags in email template.
2017-11-01 13:08:28 +02:00
return um_convert_tags( $message, $args );
}
2017-11-01 13:08:28 +02:00
/**
2018-06-07 01:01:42 +03:00
* Send Email function
2017-11-01 13:08:28 +02:00
*
2018-06-07 01:01:42 +03:00
* @param string $email
* @param null $template
* @param array $args
2017-11-01 13:08:28 +02:00
*/
public function send( $email, $template, $args = array() ) {
2019-04-01 23:44:21 +03:00
if ( ! is_email( $email ) ) {
return;
}
2023-05-31 10:20:30 +03:00
if ( empty( UM()->options()->get( $template . '_on' ) ) ) {
return;
}
2023-05-23 16:37:20 +03:00
/**
2023-10-02 14:51:23 +03:00
* Filters disabling email notifications programmatically.
2023-05-23 16:37:20 +03:00
*
* @param {bool} $disabled Does an email is disabled programmatically. By default it is false.
* @param {string} $email Email address for sending.
* @param {string} $template Email template key.
* @param {array} $args Arguments for sending email.
*
* @return {bool} `true` if email is disabled programmatically.
2023-10-02 14:51:23 +03:00
*
* @since 2.6.1
* @hook um_disable_email_notification_sending
*
* @example <caption>Disabling email notifications programmatically.</caption>
2023-10-02 15:20:26 +03:00
* function my_disable_email_notification_sending( $disabled, $email, $template, $args ) {
2023-10-02 14:51:23 +03:00
* // your code here
* return $disabled;
* }
2023-10-02 15:20:26 +03:00
* add_filter( 'um_disable_email_notification_sending', 'my_disable_email_notification_sending', 10, 4 );
2023-05-23 16:37:20 +03:00
*/
$hook_disabled = apply_filters( 'um_disable_email_notification_sending', false, $email, $template, $args );
if ( false !== $hook_disabled ) {
2019-04-01 23:44:21 +03:00
return;
}
2023-10-03 01:29:19 +03:00
/**
* Fires before email notification sending.
*
* @param {string} $email Email template slug.
* @param {string} $template Email template settings.
* @param {array} $args Arguments for sending email.
*
* @since 2.0
* @hook um_before_email_notification_sending
*
* @example <caption>Action before email notification sending.</caption>
* function my_before_email_notification_sending( $email, $template, $args ) {
* // your code here
* }
* add_action( 'um_before_email_notification_sending', 'my_before_email_notification_sending', 10, 3 );
*/
do_action( 'um_before_email_notification_sending', $email, $template, $args );
2020-09-21 12:10:29 +03:00
$this->attachments = array();
2023-08-22 16:19:42 +03:00
$mail_from = UM()->options()->get( 'mail_from' ) ? UM()->options()->get( 'mail_from' ) : get_bloginfo( 'name' );
$mail_from_addr = UM()->options()->get( 'mail_from_addr' ) ? UM()->options()->get( 'mail_from_addr' ) : get_bloginfo( 'admin_email' );
$this->headers = 'From: ' . stripslashes( $mail_from ) . ' <' . $mail_from_addr . '>' . "\r\n";
add_filter( 'um_template_tags_patterns_hook', array( $this, 'add_placeholder' ) );
add_filter( 'um_template_tags_replaces_hook', array( $this, 'add_replace_placeholder' ) );
2017-11-01 13:08:28 +02:00
2018-03-02 09:55:49 +02:00
/**
2023-10-02 14:51:23 +03:00
* Filters email notification subject.
*
2023-10-03 01:29:19 +03:00
* @param {string} $subject Email subject.
* @param {string} $key Email template key.
2023-10-02 14:51:23 +03:00
*
2023-10-02 15:20:26 +03:00
* @return {string} Email subject.
2023-10-02 14:51:23 +03:00
*
* @since 2.6.1
* @hook um_email_send_subject
*
* @example <caption>Change email notification subject.</caption>
2018-06-07 01:01:42 +03:00
* function my_email_send_subject( $subject, $key ) {
2018-03-02 09:55:49 +02:00
* // your code here
2023-10-02 14:51:23 +03:00
* return $subject;
2018-03-02 09:55:49 +02:00
* }
2023-10-02 14:51:23 +03:00
* add_filter( 'um_email_send_subject', 'my_email_send_subject', 10, 2 );
2018-03-02 09:55:49 +02:00
*/
2018-06-07 01:01:42 +03:00
$subject = apply_filters( 'um_email_send_subject', UM()->options()->get( $template . '_sub' ), $template );
$subject = wp_unslash( um_convert_tags( $subject, $args ) );
2019-09-19 19:27:34 +08:00
$this->subject = html_entity_decode( $subject, ENT_QUOTES, 'UTF-8' );
2018-06-07 01:01:42 +03:00
$this->message = $this->prepare_template( $template, $args );
if ( UM()->options()->get( 'email_html' ) ) {
$this->headers .= "Content-Type: text/html\r\n";
} else {
$this->headers .= "Content-Type: text/plain\r\n";
}
2023-10-03 01:29:19 +03:00
// Send mail.
2018-06-07 01:01:42 +03:00
wp_mail( $email, $this->subject, $this->message, $this->headers, $this->attachments );
2023-10-03 01:29:19 +03:00
/**
* Fires after email notification sending.
*
* @param {string} $email Email template slug.
* @param {string} $template Email template settings.
* @param {array} $args Arguments for sending email.
*
* @since 2.0
* @hook um_after_email_notification_sending
*
* @example <caption>Action after email notification sending.</caption>
* function my_after_email_notification_sending( $email, $template, $args ) {
* // your code here
* }
* add_action( 'um_after_email_notification_sending', 'my_after_email_notification_sending', 10, 3 );
*/
do_action( 'um_after_email_notification_sending', $email, $template, $args );
2017-11-01 13:08:28 +02:00
}
2018-03-20 13:24:38 +02:00
/**
* @param $template_name
*
* @return mixed|void
*/
public function get_template_filename( $template_name ) {
2018-03-02 09:55:49 +02:00
/**
2023-10-02 14:51:23 +03:00
* Filters email notification template name.
*
2023-10-03 01:29:19 +03:00
* @param {string} $template_name Email template Name.
2023-10-02 14:51:23 +03:00
*
* @return {string} Email template Name.
*
* @since 2.0
* @hook um_change_email_template_file
*
* @example <caption>Change email notification template path.</caption>
* function my_change_email_template_file( $template_name ) {
2018-03-02 09:55:49 +02:00
* // your code here
2023-10-02 14:51:23 +03:00
* return $template_name;
2018-03-02 09:55:49 +02:00
* }
2023-10-02 14:51:23 +03:00
* add_filter( 'um_change_email_template_file', 'my_change_email_template_file' );
2018-03-02 09:55:49 +02:00
*/
return apply_filters( 'um_change_email_template_file', $template_name );
}
2017-11-01 13:08:28 +02:00
/**
* Locate a template and return the path for inclusion.
*
* @access public
* @param string $template_name
* @return string
*/
public function template_in_theme( $template_name ) {
2018-03-02 09:55:49 +02:00
$template_name_file = $this->get_template_filename( $template_name );
2017-11-01 13:08:28 +02:00
2018-05-30 18:34:24 +03:00
$blog_id = $this->get_blog_id();
// check if there is a template at theme blog ID folder
$template = locate_template(
array(
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name_file . '.php',
)
);
2017-11-01 13:08:28 +02:00
// Return what we found.
2019-04-01 23:44:21 +03:00
if ( get_template_directory() === get_stylesheet_directory() ) {
return ! $template ? false : true;
}
2023-10-03 01:29:19 +03:00
return strstr( $template, get_stylesheet_directory() );
2017-11-01 13:08:28 +02:00
}
/**
* Method returns an expected path for template
2017-11-01 13:08:28 +02:00
*
* @access public
2018-06-07 01:01:42 +03:00
*
2017-11-01 13:08:28 +02:00
* @param string $location
* @param string $template_name
2018-06-07 01:01:42 +03:00
*
2017-11-01 13:08:28 +02:00
* @return string
*/
public function get_template_file( $location, $template_name ) {
$template_path = '';
2018-03-02 09:55:49 +02:00
$template_name_file = $this->get_template_filename( $template_name );
switch ( $location ) {
2017-11-01 13:08:28 +02:00
case 'theme':
2018-05-30 18:34:24 +03:00
//save email template in blog ID folder if we use multisite
$blog_id = $this->get_blog_id();
$template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' . $blog_id ) . $template_name_file . '.php';
2017-11-01 13:08:28 +02:00
break;
case 'plugin':
2023-09-13 22:56:32 +03:00
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : UM_PATH . 'templates/email';
2018-06-07 01:01:42 +03:00
$template_path = trailingslashit( $path ) . $template_name . '.php';
2017-11-01 13:08:28 +02:00
break;
}
/**
2023-10-02 14:51:23 +03:00
* Filters expected path for email template in theme or plugin.
*
2023-10-03 01:29:19 +03:00
* @param {string} $template_path Expected template path.
* @param {string} $location Where to search 'theme||plugin'.
* @param {string} $template_name_file Expected filename.
2023-10-02 14:51:23 +03:00
*
* @return {string} Email template path.
*
* @since 2.6.1
* @hook um_email_get_template_file_path
*
2023-10-02 14:51:23 +03:00
* @example <caption>Change expected path for email template in theme or plugin.</caption>
2023-10-02 15:20:26 +03:00
* function my_email_get_template_file_path( $template_path, $location, $template_name_file ) {
2023-10-02 14:51:23 +03:00
* // your code here
* return $template_path;
* }
2023-10-02 15:20:26 +03:00
* add_filter( 'um_email_get_template_file_path', 'my_email_get_template_file_path' );
*/
return apply_filters( 'um_email_get_template_file_path', $template_path, $location, $template_name_file );
2017-11-01 13:08:28 +02:00
}
/**
2023-10-03 01:29:19 +03:00
* Copy template to the theme.
2017-11-01 13:08:28 +02:00
*
2018-06-07 01:01:42 +03:00
* @param string $template
2017-11-01 13:08:28 +02:00
* @return bool
*/
public function copy_email_template( $template ) {
2017-11-01 13:08:28 +02:00
$in_theme = $this->template_in_theme( $template );
if ( $in_theme ) {
return false;
}
2022-12-13 15:52:57 +02:00
$plugin_template_path = wp_normalize_path( $this->get_template_file( 'plugin', $template ) );
$theme_template_path = wp_normalize_path( $this->get_template_file( 'theme', $template ) );
$template_filename = $this->get_template_filename( $template ) . '.php';
$template_dir = wp_normalize_path( str_replace( $template_filename, '', $theme_template_path ) );
$result = wp_mkdir_p( $template_dir );
if ( ! $result ) {
return false;
2017-11-01 13:08:28 +02:00
}
2017-11-12 20:32:17 +02:00
if ( file_exists( $plugin_template_path ) && copy( $plugin_template_path, $theme_template_path ) ) {
2017-11-01 13:08:28 +02:00
return true;
}
2023-10-03 01:29:19 +03:00
return false;
2017-11-01 13:08:28 +02:00
}
2019-05-06 17:22:57 +03:00
/**
2023-10-03 01:29:19 +03:00
* UM Placeholders for site url, admin email, submit registration.
2019-05-06 17:22:57 +03:00
*
2023-10-03 01:29:19 +03:00
* @param array $placeholders
2019-05-06 17:22:57 +03:00
*
* @return array
*/
public function add_placeholder( $placeholders ) {
$placeholders[] = '{user_profile_link}';
2019-05-06 17:22:57 +03:00
$placeholders[] = '{site_url}';
$placeholders[] = '{admin_email}';
$placeholders[] = '{login_url}';
$placeholders[] = '{password}';
return $placeholders;
}
/**
2023-10-03 01:29:19 +03:00
* UM Replace Placeholders for site url, admin email, submit registration.
2019-05-06 17:22:57 +03:00
*
2023-10-03 01:29:19 +03:00
* @param array $replace_placeholders
2019-05-06 17:22:57 +03:00
*
* @return array
*/
public function add_replace_placeholder( $replace_placeholders ) {
$replace_placeholders[] = um_user_profile_url();
2019-05-06 17:22:57 +03:00
$replace_placeholders[] = get_bloginfo( 'url' );
$replace_placeholders[] = um_admin_email();
$replace_placeholders[] = um_get_core_page( 'login' );
$replace_placeholders[] = esc_html__( 'Your set password', 'ultimate-member' );
return $replace_placeholders;
}
2017-11-01 13:08:28 +02:00
}
2022-12-13 15:52:57 +02:00
}