PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.1.3
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.1.3
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 / trunk / lib / helpers / notifications_helper.php
latepoint / trunk / 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 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
308 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 $mailer = new OsMailer();
89 $result = OsEmailHelper::send_email($to, $subject, $content, $mailer->get_headers(), ($notification_settings['activity_data'] ?? []));
90 break;
91 case 'sms':
92 $to = $notification_settings['to'] ?? '';
93 $content = $notification_settings['content'] ?? '';
94 $result = OsSmsHelper::send_sms($to, $content, ($notification_settings['activity_data'] ?? []));
95 break;
96 case 'whatsapp':
97 $to = $notification_settings['to'] ?? '';
98 $result = OsWhatsappHelper::send_whatsapp($to, $notification_settings['data'], ($notification_settings['activity_data'] ?? []));
99 break;
100 }
101
102 /**
103 * Send a notification based on type
104 *
105 * @since 4.7.0
106 * @hook latepoint_notifications_send
107 *
108 * @param {array} $result The array of data describing the send operation
109 * @param {string} $type Type of notificaiton to send
110 * @param {array} $notification_settings Settings for notification
111 *
112 * @returns {array} The array of descriptive data, possibly transformed by hooks
113 */
114 return apply_filters('latepoint_notifications_send', $result, $type, $notification_settings);
115 }
116
117
118 public static function load_templates_for_action_type(string $action_type) : array{
119 $templates = [];
120
121 require_once ABSPATH . 'wp-admin/includes/file.php';
122 if ( ! WP_Filesystem() ) {
123 OsDebugHelper::log( __( 'Failed to initialise WC_Filesystem API while trying to show notification templates.', 'latepoint' ) );
124 return $templates;
125 }
126 global $wp_filesystem;
127
128 switch($action_type){
129 case 'send_email':
130 $templates[] = [
131 'id' => 'booking__created__to_agent',
132 'to_user_type' => 'agent',
133 'name' => "New Appointment",
134 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
135 'subject' => "New Appointment Received",
136 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_created.html'))
137 ];
138 $templates[] = [
139 'id' => 'booking__created__to_customer',
140 'to_user_type' => 'customer',
141 'name' => "New Appointment",
142 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
143 'subject' => "Appointment Confirmation",
144 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_created.html'))
145 ];
146 $templates[] = [
147 'id' => 'booking__updated__to_customer',
148 'to_user_type' => 'customer',
149 'name' => "Appointment Updated",
150 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
151 'subject' => "Appointment Updated",
152 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_updated.html'))
153 ];
154 $templates[] = [
155 'id' => 'booking__updated__to_agent',
156 'to_user_type' => 'agent',
157 'name' => "Appointment Updated",
158 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
159 'subject' => "Appointment Updated",
160 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_updated.html'))
161 ];
162 $templates[] = [
163 'id' => 'customer__created__to_customer',
164 'to_user_type' => 'customer',
165 'name' => "Customer Created",
166 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
167 'subject' => "Your New Account",
168 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/customer_created.html'))
169 ];
170 $templates[] = [
171 'id' => 'booking__start__to_customer',
172 'to_user_type' => 'customer',
173 'name' => "Appointment Reminder",
174 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
175 'subject' => "Appointment Reminder",
176 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_start.html'))
177 ];
178 $templates[] = [
179 'id' => 'booking__start__to_agent',
180 'to_user_type' => 'agent',
181 'name' => "Appointment Reminder",
182 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
183 'subject' => "Appointment Reminder",
184 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_start.html'))
185 ];
186 $templates[] = [
187 'id' => 'booking__end__to_customer',
188 'to_user_type' => 'customer',
189 'name' => "After Appointment Feedback",
190 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
191 'subject' => "Appointment Feedback",
192 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/booking_end.html'))
193 ];
194 $templates[] = [
195 'id' => 'booking__end__to_agent',
196 'to_user_type' => 'agent',
197 'name' => "After Appointment Feedback",
198 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
199 'subject' => "Appointment Feedback",
200 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_end.html'))
201 ];
202 $templates[] = [
203 'id' => 'order__created__to_agent',
204 'to_user_type' => 'agent',
205 'name' => "New Order",
206 'to_email' => '{{order_agents_emails}}',
207 'subject' => "New Order Received",
208 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/order_created.html'))
209 ];
210 $templates[] = [
211 'id' => 'order__created__to_customer',
212 'to_user_type' => 'customer',
213 'name' => "New Order",
214 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
215 'subject' => "Order Confirmation",
216 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/order_created.html'))
217 ];
218 $templates[] = [
219 'id' => 'payment_request__created__to_customer',
220 'to_user_type' => 'customer',
221 'name' => "New Payment Request",
222 'to_email' => '{{customer_full_name}} <{{customer_email}}>',
223 'subject' => "Payment Request for Order {{order_confirmation_code}}",
224 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/customer/payment_request_created.html'))
225 ];
226 if(OsSettingsHelper::is_env_dev()){
227
228 $templates[] = [
229 'id' => 'booking__test__to_agent',
230 'to_user_type' => 'agent',
231 'name' => "Test Booking variables",
232 'to_email' => '{{agent_full_name}} <{{agent_email}}>',
233 'subject' => "Test Booking variables",
234 'content' => OsEmailHelper::get_email_layout($wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/agent/booking_test.html'))
235 ];
236 }
237 break;
238 case 'send_sms':
239 $templates[] = [
240 'id' => 'booking__created__to_agent',
241 'to_user_type' => 'agent',
242 'name' => "New Appointment",
243 'to_phone' => '{{agent_phone}}',
244 'content' => 'Hi {{agent_first_name}}, your {{service_name}} appointment with {{customer_full_name}} is coming on {{start_date}} at {{start_time}}'
245 ];
246 $templates[] = [
247 'id' => 'booking__updated__to_agent',
248 'to_user_type' => 'agent',
249 'name' => "Appointment Updated",
250 'to_phone' => '{{agent_phone}}',
251 'content' => 'Hi {{agent_first_name}}, appointment with ID {{booking_id}} was updated. Date/Time: {{start_date}} at {{start_time}}'
252 ];
253 $templates[] = [
254 'id' => 'booking__created__to_customer',
255 'to_user_type' => 'customer',
256 'name' => "New Appointment",
257 'to_phone' => '{{customer_phone}}',
258 'content' => 'Hi {{customer_first_name}}, your {{service_name}} appointment is coming on {{start_date}} at {{start_time}}'
259 ];
260 $templates[] = [
261 'id' => 'booking__updated__to_customer',
262 'to_user_type' => 'customer',
263 'name' => "Appointment Updated",
264 'to_phone' => '{{customer_phone}}',
265 'content' => 'Hi {{customer_first_name}}, your {{service_name}} appointment was updated. Date/Time: {{start_date}} at {{start_time}}'
266 ];
267 $templates[] = [
268 'id' => 'customer__created__to_customer',
269 'to_user_type' => 'customer',
270 'name' => "Customer Created",
271 'to_phone' => '{{customer_phone}}',
272 'content' => 'Thank you for creating an account. Visit {{customer_dashboard_url}} to manage your appointments.'
273 ];
274 break;
275 }
276
277 /**
278 * Get list of templates for action type
279 *
280 * @since 5.1.0
281 * @hook latepoint_load_templates_for_action_type
282 *
283 * @param {array} $templates array of templates for action type
284 * @param {string} $action_type type of action
285 * @param {WpFilesystem} $action_type type of action
286 *
287 * @returns {array} The filtered array of templates
288 */
289 $templates = apply_filters('latepoint_load_templates_for_action_type', $templates, $action_type, $wp_filesystem);
290 return $templates;
291 }
292
293
294 // Password Reset Request
295 public static function customer_password_reset_request_subject(){
296 $customer_mailer = new OsCustomerMailer();
297 return $customer_mailer->password_reset_request_subject();
298 }
299
300 public static function customer_password_reset_request_content(){
301 $customer_mailer = new OsCustomerMailer();
302 return $customer_mailer->password_reset_request_content();
303 }
304
305
306
307
308 }