PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 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 All 140 releases
← All changes | inc/emails/class-lp-email-hooks.php +147 -141 4.3.9 → 4.4.9 View file →
@@ -1,141 +1,147 @@
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 -}
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_order_status_update_to_refunded
18 + * @uses SendEmailAjax::send_mail_order_refund_requested
19 + * @uses SendEmailAjax::send_mail_user_course_finished
20 + */
21 + class LP_Email_Hooks {
22 + protected static $instance;
23 + protected $actions;
24 +
25 + protected function __construct() {
26 + // Define class handle send email with hook corresponding
27 + $this->actions = apply_filters(
28 + 'learn-press/email-actions-hooks',
29 + [
30 + // preview course
31 + 'learn_press_course_submit_rejected',
32 + 'learn_press_course_submit_approved',
33 + 'learn_press_course_submit_for_reviewer',
34 +
35 + // New order
36 + 'learn-press/order/status-pending-to-processing' => 'send_mail_order_status_pending_to_processing',
37 + 'learn-press/order/status-pending-to-completed' => 'send_mail_order_status_pending_to_completed',
38 + // Completed order
39 + 'learn-press/order/status-completed' => 'send_mail_order_status_update_to_completed',
40 + // Cancelled order
41 + 'learn-press/order/status-cancelled' => 'send_mail_order_status_update_to_cancelled',
42 + // Refunded order
43 + 'learn-press/order/status-refunded' => 'send_mail_order_status_update_to_refunded',
44 + // Refund requested
45 + 'learn-press/order/refund-requested' => 'send_mail_order_refund_requested',
46 + // Finished course
47 + 'learn-press/user-course-finished' => 'send_mail_user_course_finished',
48 + ]
49 + );
50 +
51 + foreach ( $this->actions as $tag_hook => $action ) {
52 + add_action( $tag_hook, array( $this, 'handle_send_email_on_background' ), 11, 10 );
53 + }
54 +
55 + // Override message change password
56 + add_filter( 'retrieve_password_notification_email', array( $this, 'retrieve_password_message' ), 11, 4 );
57 + }
58 +
59 + /**
60 + * Call background email
61 + * Check hook and call class email corresponding
62 + *
63 + * @author tungnx
64 + * @since 4.1.1
65 + * @version 1.0.0
66 + */
67 + public function handle_send_email_on_background() {
68 + $args = func_get_args();
69 + $args = array_merge( $args, [ 'params_request' => $_REQUEST ] );
70 + $email_bg = LP_Background_Single_Email::instance();
71 + $current_filter = current_filter();
72 +
73 + try {
74 + if ( isset( $this->actions[ $current_filter ] ) ) {
75 + if ( is_string( $this->actions[ $current_filter ] ) ) { // For new declaration, only string callback
76 + $data_send = [
77 + 'params' => $args,
78 + 'lp-load-ajax' => $this->actions[ $current_filter ],
79 + ];
80 + LPBackgroundAjax::handle( $data_send );
81 + } elseif ( is_array( $this->actions[ $current_filter ] ) ) { // For old declaration, has array
82 + foreach ( $this->actions[ $current_filter ] as $class_email => $path_file ) {
83 + $data_send = [
84 + 'params' => $args,
85 + 'class_name' => $class_email,
86 + ];
87 + $email_bg->data( $data_send )->dispatch();
88 + }
89 + }
90 + }
91 + } catch ( Throwable $e ) {
92 + error_log( $e->getMessage() );
93 + }
94 + }
95 +
96 + /**
97 + * Override message reset password
98 + *
99 + * @param array $data_mail
100 + * @param string $key
101 + * @param string $user_login
102 + * @param WP_User $user_data
103 + *
104 + * @return array
105 + * @version 1.0.1
106 + * @since 4.2.6.9
107 + */
108 + public function retrieve_password_message( $data_mail, $key, $user_login, $user_data ) {
109 + try {
110 + include_once LP_PLUGIN_PATH . 'inc/emails/types/class-lp-email-reset-password.php';
111 + $email_reset_pass = new LP_Email_Reset_Password();
112 + if ( ! $email_reset_pass->enable ) {
113 + return $data_mail;
114 + }
115 +
116 + $email_reset_pass = new LP_Email_Reset_Password();
117 + $params = [
118 + 'user_login' => $user_login,
119 + 'reset_key' => $key,
120 + ];
121 + $email_reset_pass->set_data_content( $params );
122 + $message = $email_reset_pass->get_content();
123 + $message = apply_filters( 'learn-press/email-content', $email_reset_pass->apply_style_inline( $message ), $this );
124 + $data_mail['message'] = $message;
125 + $data_mail['subject'] = $email_reset_pass->get_subject();
126 + $data_mail['headers'] = $email_reset_pass->get_headers();
127 + } catch ( Throwable $e ) {
128 + error_log( $e->getMessage() );
129 + }
130 +
131 + return $data_mail;
132 + }
133 +
134 + /**
135 + * @return LP_Email_Hooks
136 + */
137 + public static function instance(): self {
138 + if ( is_null( self::$instance ) ) {
139 + self::$instance = new self();
140 + }
141 +
142 + return self::$instance;
143 + }
144 + }
145 +
146 + LP_Email_Hooks::instance();
147 +}