PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.11
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.11
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 3 months ago agent_helper.php 3 months ago analytics_helper.php 4 months ago auth_helper.php 3 months ago blocks_helper.php 3 months ago booking_helper.php 3 months ago bricks_helper.php 3 months ago bundles_helper.php 3 months ago calendar_helper.php 3 months ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 3 months ago debug_helper.php 3 months ago defaults_helper.php 3 months ago elementor_helper.php 3 months ago email_helper.php 3 months ago encrypt_helper.php 3 months ago events_helper.php 3 months ago form_helper.php 3 months ago icalendar_helper.php 3 months ago image_helper.php 3 months ago invoices_helper.php 3 months ago license_helper.php 3 months ago location_helper.php 3 months ago marketing_systems_helper.php 3 months ago meeting_systems_helper.php 3 months ago menu_helper.php 3 months ago meta_helper.php 3 months ago migrations_helper.php 3 months ago money_helper.php 3 months ago notifications_helper.php 3 months ago nps_survey_helper.php 3 months ago order_intent_helper.php 3 months ago orders_helper.php 3 months ago otp_helper.php 3 months ago pages_helper.php 3 months ago params_helper.php 3 months ago payments_helper.php 3 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago replacer_helper.php 3 months ago resource_helper.php 3 months ago roles_helper.php 3 months ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 3 months ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 months ago sms_helper.php 3 months ago steps_helper.php 3 months ago stripe_connect_helper.php 3 months ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 3 months ago timeline_helper.php 3 months ago transaction_helper.php 3 months ago transaction_intent_helper.php 3 months ago util_helper.php 3 months ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 3 months ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
email_helper.php
142 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'] ) ) {
53 $data = array_merge( $data, $result['extra_data']['activity_data'] );
54 }
55 $activity = OsActivitiesHelper::create_activity( $data );
56 return $activity;
57 }
58
59
60 /**
61 *
62 * Sends email using WordPress wp_mail function
63 *
64 * @param string $to Email address(es) of the receiver
65 * @param string $subject Subject of the email
66 * @param string $content Contents of the email
67 * @param array $headers
68 * @return array
69 */
70 public static function send_email( string $to, string $subject, string $content, array $headers = [], $activity_data = [], $attachments = [] ): array {
71 $processor_code = 'wp_mail';
72 $result = [
73 'status' => LATEPOINT_STATUS_ERROR,
74 'message' => __( 'No email processor is selected.', 'latepoint' ),
75 'to' => $to,
76 'content' => $content,
77 'processor_code' => $processor_code,
78 'processor_name' => 'WordPress Mailer',
79 'processed_datetime' => '',
80 'extra_data' => [
81 'activity_data' => $activity_data,
82 ],
83 'errors' => [],
84 ];
85
86 if ( empty( $to ) ) {
87 $errors[] = __( 'Email address of the recipient can not be blank', 'latepoint' );
88 }
89 if ( empty( $subject ) ) {
90 $errors[] = __( 'Subject of the email can not be blank', 'latepoint' );
91 }
92 if ( empty( $content ) ) {
93 $errors[] = __( 'Content of the email can not be blank', 'latepoint' );
94 }
95
96 if ( ! empty( $errors ) ) {
97 $result['status'] = LATEPOINT_STATUS_ERROR;
98 $result['message'] = implode( ', ', $errors );
99 $result['errors'] = $errors;
100 return $result;
101 }
102
103 if ( OsSettingsHelper::is_email_allowed() && OsNotificationsHelper::is_notification_type_enabled( 'email' ) ) {
104
105 if ( OsNotificationsHelper::get_selected_processor_code_by_type( 'email' ) == $processor_code ) {
106 if ( wp_mail( $to, $subject, $content, $headers, $attachments ) ) {
107 $result['status'] = LATEPOINT_STATUS_SUCCESS;
108 $result['message'] = __( 'Email was sent successfully', 'latepoint' );
109 $result['processed_datetime'] = OsTimeHelper::now_datetime_in_db_format();
110 $result['extra_data']['subject'] = $subject;
111 } else {
112 $result['status'] = LATEPOINT_STATUS_ERROR;
113 $result['errors'] = __( 'Error sending email', 'latepoint' );
114 $result['message'] = __( 'Error sending email, email address invalid or email processor not setup', 'latepoint' );
115 }
116 }
117
118 /**
119 * Result of sending an email
120 *
121 * @since 4.7.0
122 * @hook latepoint_notifications_send_email
123 *
124 * @param {array} $result The array of data describing the result of operation
125 * @param {string} $to
126 * @param {string} $subject
127 * @param {string} $content
128 * @param {array} $headers
129 *
130 * @returns {array} The array of data describing the result of operation
131 */
132 $result = apply_filters( 'latepoint_notifications_send_email', $result, $to, $subject, $content, $headers );
133
134 } else {
135 $result['message'] = __( 'Email notifications are disabled. Enable email processor in Settings - Notifications.', 'latepoint' );
136 $result['errors'][] = __( 'Email notifications are disabled. Enable email processor in Settings - Notifications.', 'latepoint' );
137 }
138 OsEmailHelper::log_email( $result );
139 return $result;
140 }
141 }
142