PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9.1
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / emails / class-lp-email-hooks.php

class-lp-email-hooks.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9.1, at inc/emails/class-lp-email-hooks.php

142 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use LearnPress\Background\LPBackgroundAjax;
4 use LearnPress\Models\UserItems\UserCourseModel;
5
6 defined( 'ABSPATH' ) || exit();
7
8 if ( ! class_exists( 'LP_Email_Hooks' ) ) {
9
10 /**
11 * Class LP_Email_Hooks
12 *
13 * @uses SendEmailAjax::send_mail_order_status_pending_to_processing
14 * @uses SendEmailAjax::send_mail_order_status_pending_to_completed
15 * @uses SendEmailAjax::send_mail_order_status_update_to_completed
16 * @uses SendEmailAjax::send_mail_order_status_update_to_cancelled
17 * @uses SendEmailAjax::send_mail_user_course_finished
18 */
19 class LP_Email_Hooks {
20 protected static $instance;
21 protected $actions;
22
23 protected function __construct() {
24 // Define class handle send email with hook corresponding
25 $this->actions = apply_filters(
26 'learn-press/email-actions-hooks',
27 [
28 // preview course
29 'learn_press_course_submit_rejected',
30 'learn_press_course_submit_approved',
31 'learn_press_course_submit_for_reviewer',
32
33 // New order
34 'learn-press/order/status-pending-to-processing' => 'send_mail_order_status_pending_to_processing',
35 'learn-press/order/status-pending-to-completed' => 'send_mail_order_status_pending_to_completed',
36 // Completed order
37 'learn-press/order/status-completed' => 'send_mail_order_status_update_to_completed',
38 // Cancelled order
39 'learn-press/order/status-cancelled' => 'send_mail_order_status_update_to_cancelled',
40 // Finished course
41 'learn-press/user-course-finished' => 'send_mail_user_course_finished',
42 ]
43 );
44
45 foreach ( $this->actions as $tag_hook => $action ) {
46 add_action( $tag_hook, array( $this, 'handle_send_email_on_background' ), 11, 10 );
47 }
48
49 // Override message change password
50 add_filter( 'retrieve_password_notification_email', array( $this, 'retrieve_password_message' ), 11, 4 );
51 }
52
53 /**
54 * Call background email
55 * Check hook and call class email corresponding
56 *
57 * @author tungnx
58 * @since 4.1.1
59 * @version 1.0.0
60 */
61 public function handle_send_email_on_background() {
62 $args = func_get_args();
63 $args = array_merge( $args, [ 'params_request' => $_REQUEST ] );
64 $email_bg = LP_Background_Single_Email::instance();
65 $current_filter = current_filter();
66
67 try {
68 if ( isset( $this->actions[ $current_filter ] ) ) {
69 if ( is_string( $this->actions[ $current_filter ] ) ) { // For new declaration, only string callback
70 $data_send = [
71 'params' => $args,
72 'lp-load-ajax' => $this->actions[ $current_filter ],
73 ];
74 LPBackgroundAjax::handle( $data_send );
75 } elseif ( is_array( $this->actions[ $current_filter ] ) ) { // For old declaration, has array
76 foreach ( $this->actions[ $current_filter ] as $class_email => $path_file ) {
77 $data_send = [
78 'params' => $args,
79 'class_name' => $class_email,
80 ];
81 $email_bg->data( $data_send )->dispatch();
82 }
83 }
84 }
85 } catch ( Throwable $e ) {
86 error_log( $e->getMessage() );
87 }
88 }
89
90 /**
91 * Override message reset password
92 *
93 * @param array $data_mail
94 * @param string $key
95 * @param string $user_login
96 * @param WP_User $user_data
97 *
98 * @return array
99 * @version 1.0.1
100 * @since 4.2.6.9
101 */
102 public function retrieve_password_message( $data_mail, $key, $user_login, $user_data ) {
103 try {
104 include_once LP_PLUGIN_PATH . 'inc/emails/types/class-lp-email-reset-password.php';
105 $email_reset_pass = new LP_Email_Reset_Password();
106 if ( ! $email_reset_pass->enable ) {
107 return $data_mail;
108 }
109
110 $email_reset_pass = new LP_Email_Reset_Password();
111 $params = [
112 'user_login' => $user_login,
113 'reset_key' => $key,
114 ];
115 $email_reset_pass->set_data_content( $params );
116 $message = $email_reset_pass->get_content();
117 $message = apply_filters( 'learn-press/email-content', $email_reset_pass->apply_style_inline( $message ), $this );
118 $data_mail['message'] = $message;
119 $data_mail['subject'] = $email_reset_pass->get_subject();
120 $data_mail['headers'] = $email_reset_pass->get_headers();
121 } catch ( Throwable $e ) {
122 error_log( $e->getMessage() );
123 }
124
125 return $data_mail;
126 }
127
128 /**
129 * @return LP_Email_Hooks
130 */
131 public static function instance(): self {
132 if ( is_null( self::$instance ) ) {
133 self::$instance = new self();
134 }
135
136 return self::$instance;
137 }
138 }
139
140 LP_Email_Hooks::instance();
141 }
142