customer_mailer.php
69 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly. |
| 4 | } |
| 5 | |
| 6 | |
| 7 | if ( ! class_exists( 'OsCustomerMailer' ) ) : |
| 8 | |
| 9 | |
| 10 | class OsCustomerMailer extends OsMailer { |
| 11 | |
| 12 | |
| 13 | function __construct() { |
| 14 | parent::__construct(); |
| 15 | $this->views_folder = LATEPOINT_VIEWS_MAILERS_ABSPATH . 'customer/'; |
| 16 | } |
| 17 | |
| 18 | |
| 19 | // PASSWORD RESET TOKEN |
| 20 | |
| 21 | function password_reset_request( $customer, $token ) { |
| 22 | $this->vars['customer'] = $customer; |
| 23 | $to = $customer->email; |
| 24 | $subject = $this->password_reset_request_subject(); |
| 25 | $message = $this->password_reset_request_content(); |
| 26 | $subject = OsReplacerHelper::replace_all_vars( |
| 27 | $subject, |
| 28 | array( |
| 29 | 'customer' => $customer, |
| 30 | 'other_vars' => [ 'token' => $token ], |
| 31 | ) |
| 32 | ); |
| 33 | $message = OsReplacerHelper::replace_all_vars( |
| 34 | $message, |
| 35 | array( |
| 36 | 'customer' => $customer, |
| 37 | 'other_vars' => [ 'token' => $token ], |
| 38 | ) |
| 39 | ); |
| 40 | |
| 41 | return wp_mail( $to, $subject, $message, $this->headers ); |
| 42 | } |
| 43 | |
| 44 | function password_reset_request_subject() { |
| 45 | $default = __( 'Reset Your Password', 'latepoint' ); |
| 46 | |
| 47 | return OsSettingsHelper::get_settings_value( 'email_customer_password_reset_request_subject', $default ); |
| 48 | } |
| 49 | |
| 50 | function password_reset_request_content() { |
| 51 | $content = OsSettingsHelper::get_settings_value( 'email_customer_password_reset_request_content' ); |
| 52 | if ( ! $content ) { |
| 53 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 54 | if ( ! WP_Filesystem() ) { |
| 55 | OsDebugHelper::log( __( 'Failed to initialise WC_Filesystem API while trying to show notification templates.', 'latepoint' ) ); |
| 56 | |
| 57 | return ''; |
| 58 | } |
| 59 | global $wp_filesystem; |
| 60 | |
| 61 | return $wp_filesystem->get_contents( LATEPOINT_VIEWS_ABSPATH . 'mailers/customer/password_reset_request.html' ); |
| 62 | } else { |
| 63 | return $content; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | endif; |
| 69 |