PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.2
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 9 months 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 9 months ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 9 months ago customer_helper.php 9 months ago customer_import_helper.php 9 months ago database_helper.php 9 months ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 9 months ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 9 months ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 9 months 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 9 months ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 9 months ago order_intent_helper.php 9 months ago orders_helper.php 1 year ago otp_helper.php 9 months 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 9 months ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 9 months ago short_links_systems_helper.php 9 months ago shortcodes_helper.php 9 months ago sms_helper.php 1 year ago steps_helper.php 9 months ago stripe_connect_helper.php 9 months ago styles_helper.php 9 months ago support_topics_helper.php 1 year ago time_helper.php 9 months ago timeline_helper.php 9 months ago transaction_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 9 months ago version_specific_updates_helper.php 9 months ago whatsapp_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
311 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 $notification_types['whatsapp'] = [
46 'code' => 'whatsapp',
47 'label' => __('WhatsApp', 'latepoint'),
48 'processors' => OsWhatsappHelper::get_whatsapp_processors()
49 ];
50 /**
51 *
52 * Returns notification types with processors
53 *
54 * @since 4.7.0
55 * @hook latepoint_available_notification_types
56 *
57 * @param {array} notification types with processors
58 * @returns {array} list of notification types with processors
59 */
60 return apply_filters('latepoint_available_notification_types', $notification_types);
61 }
62
63 /**
64 *
65 * Sends notification based on a type
66 *
67 * @param string $type
68 * @param array $notification_settings
69 *
70 * @return array
71 */
72 public static function send(string $type, array $notification_settings = []): array{
73 $result = [
74 'status' => LATEPOINT_STATUS_ERROR,
75 'message' => __('Nothing to run', 'latepoint')
76 ];
77 if(!OsNotificationsHelper::is_notification_type_enabled($type)){
78 $type_label = self::get_available_notification_types()[$type]['label'] ?? $type;
79 // translators: %s is the type of notification
80 $result['message'] = sprintf(__('%s notifications are disabled', 'latepoint'), $type_label);
81 return $result;
82 }
83 switch ($type){
84 case 'email':
85 $to = $notification_settings['to'] ?? '';
86 $subject = $notification_settings['subject'] ?? '';
87 $content = $notification_settings['content'] ?? '';
88 $activity_data = $notification_settings['activity_data'] ?? [];
89 $attachments = $notification_settings['attachments'] ?? [];
90
91 $mailer = new OsMailer();
92 $result = OsEmailHelper::send_email($to, $subject, $content, $mailer->get_headers(), $activity_data, $attachments);
93 break;
94 case 'sms':
95 $to = $notification_settings['to'] ?? '';
96 $content = $notification_settings['content'] ?? '';
97 $result = OsSmsHelper::send_sms($to, $content, ($notification_settings['activity_data'] ?? []));
98 break;
99 case 'whatsapp':
100 $to = $notification_settings['to'] ?? '';
101 $result = OsWhatsappHelper::send_whatsapp($to, $notification_settings['data'], ($notification_settings['activity_data'] ?? []));
102 break;
103 }
104
105 /**
106 * Send a notification based on type
107 *
108 * @since 4.7.0
109 * @hook latepoint_notifications_send
110 *
111 * @param {array} $result The array of data describing the send operation
112 * @param {string} $type Type of notificaiton to send
113 * @param {array} $notification_settings Settings for notification
114 *
115 * @returns {array} The array of descriptive data, possibly transformed by hooks
116 */
117 return apply_filters('latepoint_notifications_send', $result, $type, $notification_settings);
118 }
119
120
121 public static function load_templates_for_action_type(string $action_type) : array{
122 $templates = [];
123
124 require_once ABSPATH . 'wp-admin/includes/file.php';
125 if ( ! WP_Filesystem() ) {
126 OsDebugHelper::log( __( 'Failed to initialise WC_Filesystem API while trying to show notification templates.', 'latepoint' ) );
127 return $templates;
128 }
129 global $wp_filesystem;
130
131 switch($action_type){
132 case 'send_email':
133 $templates[] = [
134 'id' => 'booking__created__to_agent',
135 'to_user_type' => 'agent',
136 'name' => "New Appointment",
137 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
138 'subject' => "New Appointment Received",
139 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_created.html'))
140 ];
141 $templates[] = [
142 'id' => 'booking__created__to_customer',
143 'to_user_type' => 'customer',
144 'name' => "New Appointment",
145 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
146 'subject' => "Appointment Confirmation",
147 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_created.html'))
148 ];
149 $templates[] = [
150 'id' => 'booking__updated__to_customer',
151 'to_user_type' => 'customer',
152 'name' => "Appointment Updated",
153 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
154 'subject' => "Appointment Updated",
155 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_updated.html'))
156 ];
157 $templates[] = [
158 'id' => 'booking__updated__to_agent',
159 'to_user_type' => 'agent',
160 'name' => "Appointment Updated",
161 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
162 'subject' => "Appointment Updated",
163 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_updated.html'))
164 ];
165 $templates[] = [
166 'id' => 'customer__created__to_customer',
167 'to_user_type' => 'customer',
168 'name' => "Customer Created",
169 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
170 'subject' => "Your New Account",
171 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/customer_created.html'))
172 ];
173 $templates[] = [
174 'id' => 'booking__start__to_customer',
175 'to_user_type' => 'customer',
176 'name' => "Appointment Reminder",
177 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
178 'subject' => "Appointment Reminder",
179 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_start.html'))
180 ];
181 $templates[] = [
182 'id' => 'booking__start__to_agent',
183 'to_user_type' => 'agent',
184 'name' => "Appointment Reminder",
185 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
186 'subject' => "Appointment Reminder",
187 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_start.html'))
188 ];
189 $templates[] = [
190 'id' => 'booking__end__to_customer',
191 'to_user_type' => 'customer',
192 'name' => "After Appointment Feedback",
193 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
194 'subject' => "Appointment Feedback",
195 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_end.html'))
196 ];
197 $templates[] = [
198 'id' => 'booking__end__to_agent',
199 'to_user_type' => 'agent',
200 'name' => "After Appointment Feedback",
201 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
202 'subject' => "Appointment Feedback",
203 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_end.html'))
204 ];
205 $templates[] = [
206 'id' => 'order__created__to_agent',
207 'to_user_type' => 'agent',
208 'name' => "New Order",
209 'to_email' => '{{order_agents_emails}}',
210 'subject' => "New Order Received",
211 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/order_created.html'))
212 ];
213 $templates[] = [
214 'id' => 'order__created__to_customer',
215 'to_user_type' => 'customer',
216 'name' => "New Order",
217 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
218 'subject' => "Order Confirmation",
219 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/order_created.html'))
220 ];
221 $templates[] = [
222 'id' => 'payment_request__created__to_customer',
223 'to_user_type' => 'customer',
224 'name' => "New Payment Request",
225 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
226 'subject' => "Payment Request for Order {{order_confirmation_code}}",
227 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/payment_request_created.html'))
228 ];
229 if(OsSettingsHelper::is_env_dev()){
230
231 $templates[] = [
232 'id' => 'booking__test__to_agent',
233 'to_user_type' => 'agent',
234 'name' => "Test Booking variables",
235 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
236 'subject' => "Test Booking variables",
237 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_test.html'))
238 ];
239 }
240 break;
241 case 'send_sms':
242 $templates[] = [
243 'id' => 'booking__created__to_agent',
244 'to_user_type' => 'agent',
245 'name' => "New Appointment",
246 'to_phone' => '{{agent_phone}}',
247 'content' => 'Hi {{agent_first_name}}, your {{service_name}} appointment with {{customer_full_name}} is coming on {{start_date}} at {{start_time}}'
248 ];
249 $templates[] = [
250 'id' => 'booking__updated__to_agent',
251 'to_user_type' => 'agent',
252 'name' => "Appointment Updated",
253 'to_phone' => '{{agent_phone}}',
254 'content' => 'Hi {{agent_first_name}}, appointment with ID {{booking_id}} was updated. Date/Time: {{start_date}} at {{start_time}}'
255 ];
256 $templates[] = [
257 'id' => 'booking__created__to_customer',
258 'to_user_type' => 'customer',
259 'name' => "New Appointment",
260 'to_phone' => '{{customer_phone}}',
261 'content' => 'Hi {{customer_first_name}}, your {{service_name}} appointment is coming on {{start_date}} at {{start_time}}'
262 ];
263 $templates[] = [
264 'id' => 'booking__updated__to_customer',
265 'to_user_type' => 'customer',
266 'name' => "Appointment Updated",
267 'to_phone' => '{{customer_phone}}',
268 'content' => 'Hi {{customer_first_name}}, your {{service_name}} appointment was updated. Date/Time: {{start_date}} at {{start_time}}'
269 ];
270 $templates[] = [
271 'id' => 'customer__created__to_customer',
272 'to_user_type' => 'customer',
273 'name' => "Customer Created",
274 'to_phone' => '{{customer_phone}}',
275 'content' => 'Thank you for creating an account. Visit {{customer_dashboard_url}} to manage your appointments.'
276 ];
277 break;
278 }
279
280 /**
281 * Get list of templates for action type
282 *
283 * @since 5.1.0
284 * @hook latepoint_load_templates_for_action_type
285 *
286 * @param {array} $templates array of templates for action type
287 * @param {string} $action_type type of action
288 * @param {WpFilesystem} $action_type type of action
289 *
290 * @returns {array} The filtered array of templates
291 */
292 $templates = apply_filters('latepoint_load_templates_for_action_type', $templates, $action_type, $wp_filesystem);
293 return $templates;
294 }
295
296
297 // Password Reset Request
298 public static function customer_password_reset_request_subject(){
299 $customer_mailer = new OsCustomerMailer();
300 return $customer_mailer->password_reset_request_subject();
301 }
302
303 public static function customer_password_reset_request_content(){
304 $customer_mailer = new OsCustomerMailer();
305 return $customer_mailer->password_reset_request_content();
306 }
307
308
309
310
311 }