PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.2.0
EmailKit – Email Customizer for WooCommerce & WP v1.2.0
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 / ResetPassword.php

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

108 lines 2.9 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
7 defined("ABSPATH") || exit;
8
9 class ResetPassword
10 {
11
12 public $user_id;
13 public $user_login;
14 public $user_email;
15 public $reset_key;
16 public $object;
17
18 private $db_query_class = null;
19
20 public function __construct()
21 {
22 $args = array(
23 'post_type' => 'emailkit',
24 'meta_query' => array(
25 array(
26 'key' => 'emailkit_template_type',
27 'value' => 'Reset Password',
28 ),
29 array(
30 'key' => 'emailkit_template_status',
31 'value' => 'Active',
32 ),
33 ),
34 );
35
36 $this->db_query_class = new WP_Query($args);
37
38 if (isset($this->db_query_class->posts[0])) {
39 add_action('woocommerce_email', [$this, 'remove_woocommerce_emails']);
40 }
41
42 add_filter('woocommerce_reset_password_notification', [$this, 'passwordReset'], 10, 2);
43 }
44
45 public function remove_woocommerce_emails($email_class)
46 {
47 remove_action('woocommerce_reset_password_notification', array($email_class->emails['WC_Email_Customer_Reset_Password'], 'trigger'));
48 }
49
50 public function passwordReset($user_login, $reset_key)
51 {
52
53
54 $query = $this->db_query_class;
55 $email = get_option('admin_email');
56
57 if ($user_login && $reset_key) {
58 $this->object = get_user_by('login', $user_login);
59 $this->user_id = $this->object->ID;
60 $this->user_login = $user_login;
61 $this->reset_key = $reset_key;
62 $this->user_email = stripslashes($this->object->user_email);
63 }
64
65 if (isset($query->posts[0])) {
66 $html = get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true);
67 $tbody = substr($html, strpos($html, '<tbody'));
68 $row = strpos($tbody, '</tbody>');
69 $rows = '';
70 $html = str_replace($row, $rows, $html);
71
72
73 $details = [
74 "{{user_login}}" => $user_login,
75 "{{user_email}}" => $this->user_email,
76 "{{reset_url}}" => $this->generate_set_password_url(),
77 ];
78
79 $message = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', $html));
80 $to = get_option('admin_email');
81 $subject = "Hi " . esc_attr($user_login) . "Your password reset requested on " . esc_attr(get_bloginfo('name'));
82 $headers = [
83 'From: ' . $email . "\r\n",
84 'Reply-To: ' . $email . "\r\n",
85 'Content-Type: text/html; charset=UTF-8'
86 ];
87
88 wp_mail($to, $subject, $message, $headers);
89 }
90 }
91
92 protected function generate_set_password_url()
93 {
94 // Generate a magic link so user can set initial password.
95 $key = get_password_reset_key($this->object);
96
97 if (!is_wp_error($key)) {
98 $action = 'newaccount';
99 $reset_url = wc_get_account_endpoint_url('lost-password') . "?action=$action&key=$key&login=" . rawurlencode($this->object->user_login) . "&show-reset-form=true";
100
101 return $reset_url;
102 } else {
103 // Something went wrong while getting the key for a new password URL,
104 // send the customer to the generic password reset.
105 return wc_get_account_endpoint_url('lost-password') . '?show-reset-form=true&action';
106 }
107 }
108 }