PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.2
EmailKit – Email Customizer for WooCommerce & WP v1.5.2
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / Emails / Woocommerce / NewAccount.php

NewAccount.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.2, at includes/Admin/Emails/Woocommerce/NewAccount.php

117 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\Emails\Woocommerce;
4
5 use WP_Query;
6 use WP_User;
7 use EmailKit\Admin\Emails\EmailLists;
8
9 defined('ABSPATH') || exit;
10
11 class NewAccount
12 {
13 public $user_login;
14 public $user_email;
15 public $user_pass;
16 public $password_generated;
17 public $set_password_url;
18 public $recipient;
19 public $object;
20
21 private $db_query_class = null;
22
23 public function __construct()
24 {
25 $args = array(
26 'post_type' => 'emailkit',
27 'meta_query' => array(
28 array(
29 'key' => 'emailkit_template_type',
30 'value' => EmailLists::NEW_ACCOUNT,
31 ),
32 array(
33 'key' => 'emailkit_template_status',
34 'value' => 'Active',
35 ),
36 ),
37 );
38
39
40 $this->db_query_class = new WP_Query($args);
41
42 if (isset($this->db_query_class->posts[0])) {
43
44 add_filter('woocommerce_email_enabled_customer_new_account', '__return_false');
45 }
46
47 add_filter('woocommerce_created_customer_notification', [$this, 'newAccountMail'], 10, 3);
48 }
49
50 public function newAccountMail($user_id, $user_pass = '', $password_generated = false)
51 {
52
53
54 $query = $this->db_query_class;
55 $email = get_option('admin_email');
56
57 if ($user_id) {
58 $this->object = new WP_User($user_id);
59 $this->user_pass = $user_pass;
60 $this->user_login = stripslashes($this->object->user_login);
61 $this->user_email = stripslashes($this->object->user_email);
62 $this->recipient = $this->user_email;
63 $this->password_generated = $password_generated;
64 $this->set_password_url = $this->generate_set_password_url();
65 }
66 if (isset($query->posts[0])) {
67 $html = get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true);
68 $tbody = substr($html, strpos($html, '<tbody'));
69 $row = strpos($tbody, '</tbody>');
70 $rows = '';
71 $html = str_replace($row, $rows, $html);
72
73
74 $details = [
75 "{{user_login}}" => $this->user_login,
76 "{{user_email}}" => $this->user_email,
77 "{{set_password_url}}" => $this->set_password_url,
78 "{{app_name}}" => get_bloginfo('name'), // Get the blog name
79 "{{site_url}}" => get_site_url(), // Get the site URL
80 "{{display_name}}" => $this->object->display_name,
81 ];
82
83 $message = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', $html));
84
85 $to = $this->user_email;
86
87 $pre_header = get_post_meta($query->posts[0]->ID, 'emailkit_email_preheader', true);
88 $pre_header = !empty($pre_header) ? $pre_header : esc_html__("Customer registered", 'emailkit');
89 $subject = str_replace(array_keys($details), array_values($details), get_post_meta($query->posts[0]->ID, 'emailkit_email_subject', true));
90 $subject = !empty($subject) ? $subject . ' - ' . $pre_header : esc_html__("Your account has been created on ", 'emailkit') ." ". esc_attr(get_bloginfo('name')). ' - ' . $pre_header;
91
92
93
94
95 $headers = [
96 'From: ' . $email . "\r\n",
97 'Reply-To: ' . $email . "\r\n",
98 'Content-Type: text/html; charset=UTF-8',
99 ];
100
101 wp_mail($to, $subject, $message, $headers);
102 }
103 }
104
105 protected function generate_set_password_url()
106 {
107 // Generate a magic link so user can set initial password.
108 $key = get_password_reset_key($this->object);
109 if (!is_wp_error($key)) {
110 $action = 'newaccount';
111 return wc_get_account_endpoint_url('lost-password') . "?action=$action&key=$key&login=" . rawurlencode($this->object->user_login);
112 } else {
113 // Something went wrong while getting the key for new password URL, send customer to the generic password reset.
114 return wc_get_account_endpoint_url('lost-password');
115 }
116 }
117 }