PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / core / wpbm-emails.php

wpbm-emails.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0, at core/wpbm-emails.php

216 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.1
4 * @package Booking Manager
5 * @category Send Emails
6 * @author wpdevelop
7 *
8 * @web-site http://oplugins.com/
9 * @email info@oplugins.com
10 *
11 * @modified 15.09.2015
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16
17 ////////////////////////////////////////////////////////////////////////////////
18 // S u p p o r t E m a i l F u n c t i o n s - Modification Hooks
19 ////////////////////////////////////////////////////////////////////////////////
20
21 /**
22 * Check email and format it
23 *
24 * @param string $emails
25 * @return string
26 */
27 function wpbm_validate_emails( $emails ) {
28
29 $emails = str_replace(';', ',', $emails);
30
31 if ( !is_array( $emails ) )
32 $emails = explode( ',', $emails );
33
34 $emails_list = array();
35 foreach ( (array) $emails as $recipient ) {
36
37 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
38 $recipient_name = '';
39 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
40 if ( count( $matches ) == 3 ) {
41 $recipient_name = $matches[1];
42 $recipient = $matches[2];
43 }
44 } else {
45 // Check about correct format of email
46 if( preg_match( '/([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}/im', $recipient, $matches ) ) {
47 $recipient = $matches[0];
48 }
49 }
50
51 $recipient_name = str_replace('"', '', $recipient_name);
52 $recipient_name = trim( wp_specialchars_decode( esc_html( stripslashes( $recipient_name ) ), ENT_QUOTES ) );
53
54 $emails_list[] = ( empty( $recipient_name ) ? '' : $recipient_name . ' ' )
55 . '<' . sanitize_email( $recipient ) . '>';
56 }
57
58 $emails_list = implode( ',', $emails_list );
59
60 return $emails_list;
61 }
62
63
64 /** Check Email subject about Language sections
65 *
66 * @param string $subject
67 * @param string $email_id
68 * @return string
69 */
70 function wpbm_email_api_get_subject_before( $subject, $email_id ) {
71
72 $subject = apply_wpbm_filter('wpbm_check_for_active_language', $subject );
73
74 return $subject;
75 }
76 add_filter( 'wpbm_email_api_get_subject_before', 'wpbm_email_api_get_subject_before', 10, 2 ); // Hook fire in api-email.php
77
78
79 /** Check Email sections content about Language sections
80 *
81 * @param array $fields_values - list of params to parse: 'content', 'header_content', 'footer_content' for different languges, etc ....
82 * @param string $email_id - Email ID
83 * @param string $email_type - 'plain' | 'html'
84 */
85 function wpbm_email_api_get_content_before( $fields_values, $email_id , $email_type ) {
86
87 if ( isset( $fields_values['content'] ) ) {
88 $fields_values['content'] = apply_wpbm_filter('wpbm_check_for_active_language', $fields_values['content'] );
89 if ($email_type == 'html')
90 $fields_values['content'] = make_clickable( $fields_values['content'] );
91 }
92
93 if ( isset( $fields_values['header_content'] ) )
94 $fields_values['header_content'] = apply_wpbm_filter('wpbm_check_for_active_language', $fields_values['header_content'] );
95
96 if ( isset( $fields_values['footer_content'] ) )
97 $fields_values['footer_content'] = apply_wpbm_filter('wpbm_check_for_active_language', $fields_values['footer_content'] );
98
99 return $fields_values;
100 }
101 add_filter( 'wpbm_email_api_get_content_before', 'wpbm_email_api_get_content_before', 10, 3 ); // Hook fire in api-email.php
102
103
104 /** Modify email content, if needed. - In HTML mail content, make links clickable.
105 *
106 * @param array $email_content - content of Email
107 * @param string $email_id - Email ID
108 * @param string $email_type - 'plain' | 'html'
109 */
110 function wpbm_email_api_get_content_after( $email_content, $email_id , $email_type ) {
111
112 if ( ( $email_type == 'html' ) || ( $email_type == 'multipart' ) )
113 $email_content = make_clickable( $email_content );
114
115 return $email_content;
116 }
117 add_filter( 'wpbm_email_api_get_content_after', 'wpbm_email_api_get_content_after', 10, 3 ); // Hook fire in api-email.php
118
119
120 /** Check Email Headers - in New item Email (to admin) set Reply-To header to visitor email.
121 *
122 * @param string $headers
123 * @param string $email_id - Email ID
124 * @param array $fields_values - list of params to parse: 'content', 'header_content', 'footer_content' for different languges, etc ....
125 * @param array $replace_array - list of relpaced shortcodes
126 * @return string
127 */
128 function wpbm_email_api_get_headers_after( $mail_headers, $email_id , $fields_values , $replace_array, $additional_params = array() ) {
129
130 /*
131 // Default in api-emails.php:
132 // $mail_headers = 'From: ' . $this->get_from__name() . ' <' . $this->get_from__email_address() . '> ' . "\r\n" ;
133 // $mail_headers .= 'Content-Type: ' . $this->get_content_type() . "\r\n" ;
134 //
135 // $mail_headers = "From: $mail_sender\n";
136 // preg_match('/<(.*)>/', $mail_sender, $simple_email_matches );
137 // $reply_to_email = ( count( $simple_email_matches ) > 1 ) ? $simple_email_matches[1] : $mail_sender;
138 // $mail_headers .= 'Reply-To: ' . $reply_to_email . "\n";
139 // $mail_headers .= 'X-Sender: ' . $reply_to_email . "\n";
140 // $mail_headers .= 'Return-Path: ' . $reply_to_email . "\n";
141 */
142
143 //debuge($mail_headers, $email_id , $fields_values , $replace_array);
144 if (
145 ( $email_id == 'new_admin' ) // Only for email: "New item to Admin"
146 || ( isset( $additional_params['reply'] ) )
147 ) {
148 if ( isset( $replace_array['email'] ) ) { // Get email from the item form.
149
150 $reply_to_email = sanitize_email( $replace_array['email'] );
151 if ( ! empty( $reply_to_email ) )
152 $mail_headers .= 'Reply-To: ' . $reply_to_email . "\r\n" ;
153
154 // $mail_headers .= 'X-Sender: ' . $reply_to_email . "\r\n" ;
155 // $mail_headers .= 'Return-Path: ' . $reply_to_email . "\r\n" ;
156 }
157 }
158
159 return $mail_headers;
160 }
161 add_filter( 'wpbm_email_api_get_headers_after', 'wpbm_email_api_get_headers_after', 10, 5 ); // Hook fire in api-email.php
162
163
164 /** Check if we can send Email - block sending in live demos
165 *
166 * @param bool $is_send_email
167 * @param string $email_id
168 * @param array $fields_values - list of params to parse: 'content', 'header_content', 'footer_content' for different languges, etc ....
169 * @return bool
170 */
171 function wpbm_email_api_is_allow_send( $is_send_email, $email_id, $fields_values ) {
172 //debuge($fields_values);
173 if ( wpbm_is_this_demo() )
174 $is_send_email = false;
175
176 return $is_send_email;
177 }
178 add_filter( 'wpbm_email_api_is_allow_send', 'wpbm_email_api_is_allow_send', 100, 3 ); // Hook fire in api-email.php
179 add_filter( 'wpbm_email_api_is_allow_send_copy' , 'wpbm_email_api_is_allow_send' , 100, 3);
180
181 /** Show warning about not sending emails, and reason about this.
182 *
183 * @param object $wp_error_object - WP Error object
184 * @param string $error_description - Description
185 */
186 function wpbm_email_sending_error( $wp_error_object, $error_description = '' ) {
187
188 if ( empty( $error_description ) ) {
189 // $error_description = __( 'Unknown exception', 'booking-manager') . '.'; // Overwrite to show error, if no description ???
190 }
191
192 if ( ! empty( $error_description ) ) {
193
194 $error_description = '' . __('Error', 'booking-manager') . '! ' . __('Email had not sent. Some error occuered.', 'booking-manager') . ' ' . $error_description;
195
196 // Admin side
197 if ( function_exists( 'wpbm_show_message' ) ) {
198 wpbm_show_message ( $error_description , 15 , 'error');
199
200 }
201
202 // Front-end
203 ?>
204 <script type="text/javascript">
205 if (typeof( wpbm_show_message_under_element ) == 'function') {
206 wpbm_show_message_under_element( '.wpbm_form' , '<?php echo esc_js( $error_description ) ; ?>', '');
207 }
208 </script>
209 <?php
210 } else {
211
212 // Error that have no description. Its can be Empty Object like this: WP_Error Object( 'errors' => array(), 'error_data' => array() ), or NOT
213 // debuge( $wp_error_object );
214 }
215 }
216 add_action('wpbm_email_sending_error', 'wpbm_email_sending_error', 10, 2);