PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.1.2
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.1.2
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / notifications_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 1 year ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 1 year ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 1 year ago customer_helper.php 1 year ago database_helper.php 1 year ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 1 year ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 1 year ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 1 year ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 1 year ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 1 year ago order_intent_helper.php 1 year ago orders_helper.php 1 year ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 1 year ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 1 year ago shortcodes_helper.php 1 year ago sms_helper.php 1 year ago steps_helper.php 1 year ago stripe_connect_helper.php 1 year ago styles_helper.php 1 year ago support_topics_helper.php 1 year ago time_helper.php 1 year ago timeline_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 1 year ago version_specific_updates_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
notifications_helper.php
299 lines
1 <?php
2
3 class OsNotificationsHelper {
4
5 public static function get_selected_processor_code_by_type(string $type): string{
6 return OsSettingsHelper::get_settings_value('notifications_'.$type.'_processor', '');
7 }
8 public static function get_available_notification_processors_for_type(string $type): array{
9 $notification_types = self::get_available_notification_types();
10 return $notification_types[$type]['processors'] ?? [];
11 }
12
13 public static function is_notification_type_enabled(string $type){
14 return !empty(self::get_selected_processor_code_by_type($type));
15 }
16
17 public static function is_notification_processor_enabled(string $type, string $processor_code){
18 return (self::get_selected_processor_code_by_type($type) == $processor_code);
19 }
20
21 public static function get_email_headers_from(){
22 $from_name = OsSettingsHelper::get_settings_value('notification_email_setting_from_name', get_bloginfo( 'name' ));
23 $from_email = OsSettingsHelper::get_settings_value('notification_email_setting_from_email', get_bloginfo( 'admin_email' ));
24 return (!empty($from_email) && !empty($from_name)) ? ($from_name.' <'.$from_email.'>') : (get_bloginfo( 'name' ).' <'.get_bloginfo( 'admin_email' ).'>');
25 }
26
27 public static function get_available_notification_types(){
28 $notification_types = [];
29 $notification_types['email'] = [
30 'code' => 'email',
31 'label' => __('Email', 'latepoint'),
32 'processors' => [
33 [
34 'label' => __('Default WordPress Mailer', 'latepoint'),
35 'code' => 'wp_mail',
36 'image_url' => ''
37 ]
38 ]
39 ];
40 $notification_types['sms'] = [
41 'code' => 'sms',
42 'label' => __('SMS', 'latepoint'),
43 'processors' => OsSmsHelper::get_sms_processors()
44 ];
45 /**
46 *
47 * Returns notification types with processors
48 *
49 * @since 4.7.0
50 * @hook latepoint_available_notification_types
51 *
52 * @param {array} notification types with processors
53 * @returns {array} list of notification types with processors
54 */
55 return apply_filters('latepoint_available_notification_types', $notification_types);
56 }
57
58 /**
59 *
60 * Sends notification based on a type
61 *
62 * @param string $type
63 * @param array $notification_settings
64 *
65 * @return array
66 */
67 public static function send(string $type, array $notification_settings = []): array{
68 $result = [
69 'status' => LATEPOINT_STATUS_ERROR,
70 'message' => __('Nothing to run', 'latepoint')
71 ];
72 if(!OsNotificationsHelper::is_notification_type_enabled($type)){
73 $type_label = self::get_available_notification_types()[$type]['label'] ?? $type;
74 // translators: %s is the type of notification
75 $result['message'] = sprintf(__('%s notifications are disabled', 'latepoint'), $type_label);
76 return $result;
77 }
78 switch ($type){
79 case 'email':
80 $to = $notification_settings['to'] ?? '';
81 $subject = $notification_settings['subject'] ?? '';
82 $content = $notification_settings['content'] ?? '';
83 $mailer = new OsMailer();
84 $result = OsEmailHelper::send_email($to, $subject, $content, $mailer->get_headers(), ($notification_settings['activity_data'] ?? []));
85 break;
86 case 'sms':
87 $to = $notification_settings['to'] ?? '';
88 $content = $notification_settings['content'] ?? '';
89 $result = OsSmsHelper::send_sms($to, $content, ($notification_settings['activity_data'] ?? []));
90 break;
91 }
92
93 /**
94 * Send a notification based on type
95 *
96 * @since 4.7.0
97 * @hook latepoint_notifications_send
98 *
99 * @param {array} $result The array of data describing the send operation
100 * @param {string} $type Type of notificaiton to send
101 * @param {array} $notification_settings Settings for notification
102 *
103 * @returns {array} The array of descriptive data, possibly transformed by hooks
104 */
105 return apply_filters('latepoint_notifications_send', $result, $type, $notification_settings);
106 }
107
108
109 public static function load_templates_for_action_type(string $action_type) : array{
110 $templates = [];
111
112 require_once ABSPATH . 'wp-admin/includes/file.php';
113 if ( ! WP_Filesystem() ) {
114 OsDebugHelper::log( __( 'Failed to initialise WC_Filesystem API while trying to show notification templates.', 'latepoint' ) );
115 return $templates;
116 }
117 global $wp_filesystem;
118
119 switch($action_type){
120 case 'send_email':
121 $templates[] = [
122 'id' => 'booking__created__to_agent',
123 'to_user_type' => 'agent',
124 'name' => "New Appointment",
125 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
126 'subject' => "New Appointment Received",
127 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_created.html'))
128 ];
129 $templates[] = [
130 'id' => 'booking__created__to_customer',
131 'to_user_type' => 'customer',
132 'name' => "New Appointment",
133 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
134 'subject' => "Appointment Confirmation",
135 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_created.html'))
136 ];
137 $templates[] = [
138 'id' => 'booking__updated__to_customer',
139 'to_user_type' => 'customer',
140 'name' => "Appointment Updated",
141 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
142 'subject' => "Appointment Updated",
143 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_updated.html'))
144 ];
145 $templates[] = [
146 'id' => 'booking__updated__to_agent',
147 'to_user_type' => 'agent',
148 'name' => "Appointment Updated",
149 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
150 'subject' => "Appointment Updated",
151 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_updated.html'))
152 ];
153 $templates[] = [
154 'id' => 'customer__created__to_customer',
155 'to_user_type' => 'customer',
156 'name' => "Customer Created",
157 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
158 'subject' => "Your New Account",
159 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/customer_created.html'))
160 ];
161 $templates[] = [
162 'id' => 'booking__start__to_customer',
163 'to_user_type' => 'customer',
164 'name' => "Appointment Reminder",
165 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
166 'subject' => "Appointment Reminder",
167 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_start.html'))
168 ];
169 $templates[] = [
170 'id' => 'booking__start__to_agent',
171 'to_user_type' => 'agent',
172 'name' => "Appointment Reminder",
173 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
174 'subject' => "Appointment Reminder",
175 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_start.html'))
176 ];
177 $templates[] = [
178 'id' => 'booking__end__to_customer',
179 'to_user_type' => 'customer',
180 'name' => "After Appointment Feedback",
181 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
182 'subject' => "Appointment Feedback",
183 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_end.html'))
184 ];
185 $templates[] = [
186 'id' => 'booking__end__to_agent',
187 'to_user_type' => 'agent',
188 'name' => "After Appointment Feedback",
189 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
190 'subject' => "Appointment Feedback",
191 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_end.html'))
192 ];
193 $templates[] = [
194 'id' => 'order__created__to_agent',
195 'to_user_type' => 'agent',
196 'name' => "New Order",
197 'to_email' => '{{order_agents_emails}}',
198 'subject' => "New Order Received",
199 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/order_created.html'))
200 ];
201 $templates[] = [
202 'id' => 'order__created__to_customer',
203 'to_user_type' => 'customer',
204 'name' => "New Order",
205 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
206 'subject' => "Order Confirmation",
207 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/order_created.html'))
208 ];
209 $templates[] = [
210 'id' => 'payment_request__created__to_customer',
211 'to_user_type' => 'customer',
212 'name' => "New Payment Request",
213 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
214 'subject' => "Payment Request for Order {{order_confirmation_code}}",
215 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/payment_request_created.html'))
216 ];
217 if(OsSettingsHelper::is_env_dev()){
218
219 $templates[] = [
220 'id' => 'booking__test__to_agent',
221 'to_user_type' => 'agent',
222 'name' => "Test Booking variables",
223 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
224 'subject' => "Test Booking variables",
225 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_test.html'))
226 ];
227 }
228 break;
229 case 'send_sms':
230 $templates[] = [
231 'id' => 'booking__created__to_agent',
232 'to_user_type' => 'agent',
233 'name' => "New Appointment",
234 'to_phone' => '{{agent_phone}}',
235 'content' => 'Hi {{agent_first_name}}, your {{service_name}} appointment with {{customer_full_name}} is coming on {{start_date}} at {{start_time}}'
236 ];
237 $templates[] = [
238 'id' => 'booking__updated__to_agent',
239 'to_user_type' => 'agent',
240 'name' => "Appointment Updated",
241 'to_phone' => '{{agent_phone}}',
242 'content' => 'Hi {{agent_first_name}}, appointment with ID {{booking_id}} was updated. Date/Time: {{start_date}} at {{start_time}}'
243 ];
244 $templates[] = [
245 'id' => 'booking__created__to_customer',
246 'to_user_type' => 'customer',
247 'name' => "New Appointment",
248 'to_phone' => '{{customer_phone}}',
249 'content' => 'Hi {{customer_first_name}}, your {{service_name}} appointment is coming on {{start_date}} at {{start_time}}'
250 ];
251 $templates[] = [
252 'id' => 'booking__updated__to_customer',
253 'to_user_type' => 'customer',
254 'name' => "Appointment Updated",
255 'to_phone' => '{{customer_phone}}',
256 'content' => 'Hi {{customer_first_name}}, your {{service_name}} appointment was updated. Date/Time: {{start_date}} at {{start_time}}'
257 ];
258 $templates[] = [
259 'id' => 'customer__created__to_customer',
260 'to_user_type' => 'customer',
261 'name' => "Customer Created",
262 'to_phone' => '{{customer_phone}}',
263 'content' => 'Thank you for creating an account. Visit {{customer_dashboard_url}} to manage your appointments.'
264 ];
265 break;
266 }
267
268 /**
269 * Get list of templates for action type
270 *
271 * @since 5.1.0
272 * @hook latepoint_load_templates_for_action_type
273 *
274 * @param {array} $templates array of templates for action type
275 * @param {string} $action_type type of action
276 * @param {WpFilesystem} $action_type type of action
277 *
278 * @returns {array} The filtered array of templates
279 */
280 $templates = apply_filters('latepoint_load_templates_for_action_type', $templates, $action_type, $wp_filesystem);
281 return $templates;
282 }
283
284
285 // Password Reset Request
286 public static function customer_password_reset_request_subject(){
287 $customer_mailer = new OsCustomerMailer();
288 return $customer_mailer->password_reset_request_subject();
289 }
290
291 public static function customer_password_reset_request_content(){
292 $customer_mailer = new OsCustomerMailer();
293 return $customer_mailer->password_reset_request_content();
294 }
295
296
297
298
299 }