PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7
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 4.2.1 All 138 releases
learnpress / inc / class-lp-emails.php

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

185 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Base class of LearnPress emails and helper functions.
4 *
5 * @author ThimPress
6 * @package LearnPress/Classes
7 * @version 3.0.1
8 * @editor tungnx
9 * @modify 4.1.3
10 */
11
12 /**
13 * Prevent loading this file directly
14 */
15 defined( 'ABSPATH' ) || exit();
16
17 if ( ! class_exists( 'LP_Emails' ) ) {
18 /**
19 * Class LP_Emails
20 */
21 class LP_Emails {
22
23 /**
24 * List of all email actions.
25 *
26 * @var array
27 */
28 public $emails = array();
29
30 /**
31 * The single instance of the class
32 *
33 * @var LP_Emails
34 */
35 protected static $_instance = null;
36
37 /**
38 * @var LP_Email
39 */
40 protected $_current = null;
41
42 /**
43 * @var null
44 */
45 protected $_last_current = null;
46
47 /**
48 * LP_Emails constructor.
49 */
50 protected function __construct() {
51 if ( did_action( 'learn-press/emails-init' ) ) {
52 return;
53 }
54 include_once LP_PLUGIN_PATH . 'inc/emails/class-lp-email.php';
55
56 $this->register_emails();
57
58 do_action( 'learn-press/emails-init', $this );
59 }
60
61 public function register_emails() {
62 include_once 'emails/types/class-lp-email-type-order.php';
63 include_once 'emails/types/class-lp-email-type-order-student.php';
64 include_once 'emails/types/class-lp-email-type-order-guest.php';
65 include_once 'emails/types/class-lp-email-type-order-admin.php';
66 include_once 'emails/types/class-lp-email-type-order-instructor.php';
67 include_once 'emails/types/class-lp-email-type-enrolled-course.php';
68 include_once 'emails/types/class-lp-email-type-finished-course.php';
69 include_once 'emails/types/class-lp-email-type-become-an-instructor.php';
70
71 // New order
72 $this->emails['LP_Email_New_Order_Admin'] = include_once 'emails/admin/class-lp-email-new-order-admin.php';
73 $this->emails['LP_Email_New_Order_User'] = include_once 'emails/student/class-lp-email-new-order-user.php';
74 $this->emails['LP_Email_New_Order_Instructor'] = include_once 'emails/instructor/class-lp-email-new-order-instructor.php';
75 $this->emails['LP_Email_New_Order_Guest'] = include_once 'emails/guest/class-lp-email-new-order-guest.php';
76
77 // Processing order
78 $this->emails['LP_Email_Processing_Order_User'] = include_once 'emails/student/class-lp-email-processing-order-user.php';
79 $this->emails['LP_Email_Processing_Order_Guest'] = include_once 'emails/guest/class-lp-email-processing-order-guest.php';
80
81 // Completed order
82 $this->emails['LP_Email_Completed_Order_Admin'] = include_once 'emails/admin/class-lp-email-completed-order-admin.php';
83 $this->emails['LP_Email_Completed_Order_User'] = include_once 'emails/student/class-lp-email-completed-order-user.php';
84 $this->emails['LP_Email_Completed_Order_Guest'] = include_once 'emails/guest/class-lp-email-completed-order-guest.php';
85
86 // Cancelled order
87 $this->emails['LP_Email_Cancelled_Order_Admin'] = include_once 'emails/admin/class-lp-email-cancelled-order-admin.php';
88 $this->emails['LP_Email_Cancelled_Order_Instructor'] = include_once 'emails/instructor/class-lp-email-cancelled-order-instructor.php';
89 $this->emails['LP_Email_Cancelled_Order_User'] = include_once 'emails/student/class-lp-email-cancelled-order-user.php';
90 $this->emails['LP_Email_Cancelled_Order_Guest'] = include_once 'emails/guest/class-lp-email-cancelled-order-guest.php';
91
92 // Enrolled course
93 $this->emails['LP_Email_Enrolled_Course_Admin'] = include_once 'emails/admin/class-lp-email-enrolled-course-admin.php';
94 $this->emails['LP_Email_Enrolled_Course_Instructor'] = include_once 'emails/instructor/class-lp-email-enrolled-course-instructor.php';
95 $this->emails['LP_Email_Enrolled_Course_User'] = include_once 'emails/student/class-lp-email-enrolled-course-user.php';
96
97 // Finished course
98 $this->emails['LP_Email_Finished_Course_Admin'] = include_once 'emails/admin/class-lp-email-finished-course-admin.php';
99 $this->emails['LP_Email_Finished_Course_Instructor'] = include_once 'emails/instructor/class-lp-email-finished-course-instructor.php';
100 $this->emails['LP_Email_Finished_Course_User'] = include_once 'emails/student/class-lp-email-finished-course-user.php';
101
102 // Become An Instructor
103 $this->emails['LP_Email_Become_An_Instructor'] = include_once 'emails/admin/class-lp-email-become-an-instructor.php';
104 $this->emails['LP_Email_Instructor_Accepted'] = include_once 'emails/instructor/class-lp-email-instructor-accepted.php';
105 $this->emails['LP_Email_Instructor_Denied'] = include_once 'emails/instructor/class-lp-email-instructor-denied.php';
106
107 // Forgot Password
108 $this->emails['LP_Email_Reset_Password'] = include_once 'emails/types/class-lp-email-reset-password.php';
109
110 do_action( 'learnpress/emails/register', $this->emails );
111 }
112
113 public function set_current( $id ) {
114 $this->_last_current = $this->_current;
115
116 if ( $id instanceof LP_Email ) {
117 $this->_current = $id->id;
118 } else {
119 $this->_current = $id;
120 }
121 }
122
123 /**
124 * @return bool|LP_Email
125 */
126 public function get_current() {
127 return self::get_email( $this->_current );
128 }
129
130 public function reset_current() {
131 $this->_current = $this->_last_current;
132 }
133
134 /**
135 * @param string $id
136 *
137 * @return LP_Email|bool
138 */
139 public static function get_email( $id ) {
140 static $emails = array();
141
142 if ( ! $emails || empty( $emails[ $id ] ) ) {
143 foreach ( self::instance()->emails as $class => $email ) {
144 $emails[ $email->id ] = $class;
145 }
146 }
147
148 return ! empty( $emails[ $id ] ) ? self::instance()->emails[ $emails[ $id ] ] : false;
149 }
150
151 /**
152 * Get image header in general settings.
153 *
154 * @return string
155 */
156 public function get_image_header() {
157 $image = LP_Settings::instance()->get( 'emails_general.header_image' );
158
159 if ( ! empty( $image ) ) {
160 $image = wp_get_attachment_image_url( $image, 'full' );
161 }
162
163 return $image;
164 }
165
166 /**
167 * Main LP_Mail Instance, ensures only one instance of LP_Mail is loaded or can be loaded.
168 *
169 * @since 3.0.0
170 *
171 * @return LP_Emails
172 */
173 public static function instance() {
174
175 if ( is_null( self::$_instance ) ) {
176 self::$_instance = new self();
177 }
178
179 return self::$_instance;
180 }
181
182 }
183
184 }
185