| 1 |
<?php |
| 2 |
|
| 3 |
namespace EmailKit\Admin\Emails\WordPress; |
| 4 |
|
| 5 |
use WP_Query; |
| 6 |
use EmailKit\Admin\Emails\EmailLists; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
class NewUserRegister { |
| 11 |
|
| 12 |
private $db_query_class = null; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
|
| 16 |
$args = array( |
| 17 |
'post_type' => 'emailkit', |
| 18 |
'meta_query' => array( |
| 19 |
array( |
| 20 |
'key' => 'emailkit_template_type', |
| 21 |
'value' => EmailLists::WP_NEW_REGISTER, |
| 22 |
), |
| 23 |
array( |
| 24 |
'key' => 'emailkit_template_status', |
| 25 |
'value' => 'Active', |
| 26 |
), |
| 27 |
), |
| 28 |
); |
| 29 |
|
| 30 |
$this->db_query_class = new WP_Query($args); |
| 31 |
if (isset($this->db_query_class->posts[0])) { |
| 32 |
|
| 33 |
add_filter('wp_new_user_notification_email', [$this, 'newUserMail'], 10, 3); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
public function newUserMail($new_user_notification_email, $user, $blogname) |
| 39 |
{ |
| 40 |
|
| 41 |
$query = $this->db_query_class; |
| 42 |
$key = get_password_reset_key($user); |
| 43 |
|
| 44 |
$recipient_email = $user->user_email; |
| 45 |
|
| 46 |
$details = [ |
| 47 |
"{{app_name}}" => $blogname, |
| 48 |
"{{reset_url}}" => network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login'), |
| 49 |
"{{display_name}}" => $user->display_name, |
| 50 |
"{{user_url}}" => $user->user_url, |
| 51 |
"{{user_email}}" => $recipient_email, |
| 52 |
]; |
| 53 |
|
| 54 |
$new_user_notification_email['from'] = get_option('admin_email'); |
| 55 |
if (isset($query->posts[0])) { |
| 56 |
$new_user_notification_email['message'] = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true))); |
| 57 |
} |
| 58 |
|
| 59 |
$pre_header = get_post_meta($query->posts[0]->ID, 'emailkit_email_preheader', true); |
| 60 |
$pre_header = !empty( $pre_header) ? $pre_header : esc_html__('user registration', 'emailkit'); |
| 61 |
$new_user_notification_email['subject'] = str_replace(array_keys($details), array_values($details), get_post_meta($query->posts[0]->ID, 'emailkit_email_subject', true)); |
| 62 |
$new_user_notification_email['subject'] = !empty( $new_user_notification_email['subject']) ? $new_user_notification_email['subject'] . ' - ' . $pre_header : esc_html__(' Welcome! New User Added to', 'emailkit') . ' ' . $blogname . ' - ' . $pre_header; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
$new_user_notification_email['headers'] = [ |
| 67 |
'From: ' . $blogname . ' <' . $new_user_notification_email['from'] . "> \r\n", |
| 68 |
'Reply-To: <' . $new_user_notification_email['from'], |
| 69 |
'Content-Type: text/html; charset=UTF-8', |
| 70 |
]; |
| 71 |
|
| 72 |
$new_user_notification_email['to'] = $recipient_email; |
| 73 |
|
| 74 |
return $new_user_notification_email; |
| 75 |
} |
| 76 |
|
| 77 |
} |