PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.4
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.4
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 / email_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 9 months 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 9 months 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
email_helper.php
133 lines
1 <?php
2
3 class OsEmailHelper{
4
5 public static function get_default_headers(){
6 $headers = [];
7 $headers[] = 'Content-Type: text/html; charset=UTF-8';
8 $headers[] = 'From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>';
9
10 /**
11 * Default headers for sending email
12 *
13 * @since 4.7.0
14 * @hook latepoint_default_email_headers
15 *
16 * @param {array} $headers The array of headers for email
17 *
18 * @returns {array} The array of headers for email
19 */
20 return apply_filters('latepoint_default_email_headers', $headers);
21 }
22
23 public static function get_email_layout($insert_content = false): string{
24
25 require_once ABSPATH . 'wp-admin/includes/file.php';
26 if ( ! WP_Filesystem() ) {
27 OsDebugHelper::log( __( 'Failed to initialise WC_Filesystem API while trying to show notification templates.', 'latepoint' ) );
28 return '';
29 }
30 global $wp_filesystem;
31
32 $html = OsSettingsHelper::get_settings_value('email_layout_template', $wp_filesystem->get_contents(LATEPOINT_VIEWS_ABSPATH.'mailers/layouts/default.html'));
33 if($insert_content){
34 $html = str_replace('{{content}}', $insert_content, $html);
35 }
36 return $html;
37 }
38
39 /**
40 * @param array $result
41 *
42 * @return OsActivityModel
43 */
44 public static function log_email( array $result ) {
45 if ( empty( $result['processed_datetime'] ) ) {
46 $result['processed_datetime'] = OsTimeHelper::now_datetime_in_db_format();
47 }
48 $data = [
49 'code' => 'email_sent',
50 'description' => wp_json_encode($result)
51 ];
52 if(!empty($result['extra_data']['activity_data'])) $data = array_merge($data, $result['extra_data']['activity_data']);
53 $activity = OsActivitiesHelper::create_activity( $data );
54 return $activity;
55 }
56
57
58 /**
59 *
60 * Sends email using WordPress wp_mail function
61 *
62 * @param string $to Email address(es) of the receiver
63 * @param string $subject Subject of the email
64 * @param string $content Contents of the email
65 * @param array $headers
66 * @return array
67 */
68 public static function send_email(string $to, string $subject, string $content, array $headers = [], $activity_data = [], $attachments = []): array{
69 $processor_code = 'wp_mail';
70 $result = [
71 'status' => LATEPOINT_STATUS_ERROR,
72 'message' => __('No email processor is selected.', 'latepoint'),
73 'to' => $to,
74 'content' => $content,
75 'processor_code' => $processor_code,
76 'processor_name' => 'WordPress Mailer',
77 'processed_datetime' => '',
78 'extra_data' => [
79 'activity_data' => $activity_data
80 ],
81 'errors' => [],
82 ];
83
84 if(empty($to)) $errors[] = __('Email address of the recipient can not be blank', 'latepoint');
85 if(empty($subject)) $errors[] = __('Subject of the email can not be blank', 'latepoint');
86 if(empty($content)) $errors[] = __('Content of the email can not be blank', 'latepoint');
87
88 if(!empty($errors)){
89 $result['status'] = LATEPOINT_STATUS_ERROR;
90 $result['message'] = implode(', ', $errors);
91 $result['errors'] = $errors;
92 return $result;
93 }
94
95 if(OsSettingsHelper::is_email_allowed() && OsNotificationsHelper::is_notification_type_enabled('email')) {
96
97 if(OsNotificationsHelper::get_selected_processor_code_by_type('email') == $processor_code){
98 if(wp_mail($to, $subject, $content, $headers, $attachments)){
99 $result['status'] = LATEPOINT_STATUS_SUCCESS;
100 $result['message'] = __('Email was sent successfully', 'latepoint');
101 $result['processed_datetime'] = OsTimeHelper::now_datetime_in_db_format();
102 $result['extra_data']['subject'] = $subject;
103 }else{
104 $result['status'] = LATEPOINT_STATUS_ERROR;
105 $result['errors'] = __('Error sending email', 'latepoint');
106 $result['message'] = __('Error sending email, email address invalid or email processor not setup', 'latepoint');
107 }
108 }
109
110 /**
111 * Result of sending an email
112 *
113 * @since 4.7.0
114 * @hook latepoint_notifications_send_email
115 *
116 * @param {array} $result The array of data describing the result of operation
117 * @param {string} $to
118 * @param {string} $subject
119 * @param {string} $content
120 * @param {array} $headers
121 *
122 * @returns {array} The array of data describing the result of operation
123 */
124 $result = apply_filters('latepoint_notifications_send_email', $result, $to, $subject, $content, $headers);
125
126 }else{
127 $result['message'] = __('Email notifications are disabled. Enable email processor in Settings - Notifications.', 'latepoint');
128 $result['errors'][] = __('Email notifications are disabled. Enable email processor in Settings - Notifications.', 'latepoint');
129 }
130 OsEmailHelper::log_email($result);
131 return $result;
132 }
133 }