PluginProbe
Booking Calendar / 11.8.1
Booking Calendar v11.8.1
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / core / wpbc-emails.php

wpbc-emails.php in Booking Calendar 11.8.1, at core/wpbc-emails.php

607 lines 30.7 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 Calendar
5 * @category Send Emails
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 *
11 * @modified 15.09.2015
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // Emails
20 ////////////////////////////////////////////////////////////////////////////////
21
22 /**
23 * Check email and format it
24 *
25 * @param string $emails
26 * @return string
27 */
28 function wpbc_validate_emails( $emails ) {
29
30 $emails = str_replace(';', ',', $emails);
31
32 if ( !is_array( $emails ) )
33 $emails = explode( ',', $emails );
34
35 $emails_list = array();
36 foreach ( (array) $emails as $recipient ) {
37
38 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
39 $recipient_name = '';
40 if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
41 if ( count( $matches ) == 3 ) {
42 $recipient_name = $matches[1];
43 $recipient = $matches[2];
44 }
45 } else {
46 // Check about correct format of email
47 if( preg_match( '/([\w\.\-_]+)?\w+@[\w\-_]+(\.\w+){1,}/im', $recipient, $matches ) ) { // FixIn: 8.7.7.2.
48 $recipient = $matches[0];
49 }
50 }
51
52 $recipient_name = str_replace('"', '', $recipient_name);
53 $recipient_name = trim( wp_specialchars_decode( esc_html( stripslashes( $recipient_name ) ), ENT_QUOTES ) );
54
55 $emails_list[] = ( empty( $recipient_name ) ? '' : $recipient_name . ' ' )
56 . '<' . sanitize_email( $recipient ) . '>';
57 }
58
59 $emails_list = implode( ',', $emails_list );
60
61 return $emails_list;
62 }
63
64
65 /**
66 * Convert email address to the correct format like "Jony Smith" <smith@server.com> - tp prevent "WordPress" title in email.
67 * @param string $wpbc_mail - just simple email
68 * @param type $booking_form_show - array with name and secondname of the person - title
69 * @return string - formated email.
70 */
71 function wpbc_email_prepand_person_name( $wpbc_mail, $booking_form_show = array() ) {
72
73 //FixIn:5.4.4
74 $wpbc_email_title = ((isset($booking_form_show['firstname']))?$booking_form_show['firstname'].' ':'')
75 .((isset($booking_form_show['name']))?$booking_form_show['name'].' ':'')
76 .((isset($booking_form_show['lastname']))?$booking_form_show['lastname'].' ':'')
77 .((isset($booking_form_show['secondname']))?$booking_form_show['secondname'].' ':'');
78 $wpbc_email_title = ( ( empty($wpbc_email_title ) ) ? __('Booking system' ,'booking') : substr( $wpbc_email_title, 0 , -1 ) );
79
80 $wpbc_email_title = str_replace('"', '', $wpbc_email_title);
81 $wpbc_email_title = trim( wp_specialchars_decode( esc_html( stripslashes( $wpbc_email_title ) ), ENT_QUOTES ) );
82
83 $wpbc_mail = wpbc_validate_emails( $wpbc_email_title . ' <' . $wpbc_mail . '> ' );
84
85 return $wpbc_mail;
86 }
87
88 // Old, Replaced in api-emails
89 class wpbc_email_return_path {
90 function __construct() {
91 add_action( 'phpmailer_init', array( $this, 'fix' ) );
92 }
93
94 function fix( $phpmailer ) {
95 $phpmailer->Sender = $phpmailer->From;
96 }
97 }
98
99
100 function wpbc_wp_mail( $mail_recipient, $mail_subject, $mail_body, $mail_headers ){
101
102 $wpbc_email_return_path = new wpbc_email_return_path();
103
104 // $mail_recipient = str_replace( '"', '', $mail_recipient ); //FixIn:5.4.3
105 if ( wpbc_email_api_is_allow_send( true, '', '' ) ) {
106 @wp_mail( $mail_recipient, $mail_subject, $mail_body, $mail_headers );
107 }
108 unset( $wpbc_email_return_path );
109 }
110
111
112
113
114
115 function wpbc_check_for_several_emails_in_form( $mail_recipients, $formdata, $bktype ) { // FixIn: 6.0.1.9.
116
117 $possible_other_emails = explode('~',$formdata);
118 $possible_other_emails = array_map("explode", array_fill(0,count($possible_other_emails),'^'), $possible_other_emails);
119 $other_emails = array();
120 foreach ( $possible_other_emails as $possible_emails ) {
121 if ( ( $possible_emails[0] == 'email' )
122 //&& ( $possible_emails[1] != 'email' . $bktype )
123 && ( ! empty($possible_emails[2]) )
124 )
125 $other_emails[]= trim( $possible_emails[2] ); // FixIn: 8.2.1.6.
126 }
127 $other_emails = array_unique( $other_emails ); // FixIn: 8.2.1.6.
128 if ( count( $other_emails ) > 1 ) {
129 $other_emails = implode(',',$other_emails);
130 $mail_recipients = $other_emails;
131 }
132 return $mail_recipients;
133 }
134
135
136 // N E W /////////////////////////////////////////////////////////////////////
137
138
139 /**
140 * Parse email and get Parts of Email - Name and Email
141 *
142 * @param string $email
143 * @return array [email] => beta@wpbookingcalendar.com
144 [title] => Booking system
145 [original] => "Booking system"
146 [original_to_show] => "Booking system" <beta@wpbookingcalendar.com>
147 */
148 function wpbc_get_email_parts( $email ) {
149
150 $email_to_parse = html_entity_decode( $email ); // Convert &quot; to " etc...
151
152 $pure_name = '';
153 $pure_email = '';
154 if( preg_match( '/(.*)<(.+)>/', $email_to_parse, $matches ) ) {
155 if ( count( $matches ) == 3 ) {
156 $pure_name = $matches[1];
157 $pure_email = $matches[2];
158 }
159 } else { // Check about correct format of email
160 if( preg_match( '/([\w\.\-_]+)?\w+@[\w\-_]+(\.\w+){1,}/im', $email_to_parse, $matches ) ) {
161 $pure_email = $matches[0];
162 }
163 }
164
165 $pure_name = trim( wp_specialchars_decode( esc_html( stripslashes( $pure_name ) ), ENT_QUOTES ) , ' "');
166
167 $return_email = array(
168 'email' => sanitize_email( $pure_email )
169 , 'title' => $pure_name
170 , 'original' => $email_to_parse
171 , 'original_to_show' => htmlentities( $email_to_parse ) // Convert " to &quot; etc...
172 );
173
174 return $return_email;
175 }
176
177
178 function wpbc_tooltip_help__fix_quote( $field_val ) {
179
180 $field_val = str_replace( '"', "'", $field_val );
181
182 return $field_val;
183 }
184
185 // Get Emails Help Shortcodes for Settings pages
186 function wpbc_get_email_help_shortcodes( $skip_shortcodes = array() , $email_example = '') {
187
188 $icn = '<a href="https://wpbookingcalendar.com/faq/email-shortcodes/#available_shortcodes"
189 class="tooltip_top wpbc-bi-question-circle wpbc_help_tooltip_icon_left"
190 data-original-title="%2$s"></a> %1$s';
191
192 $fields = array();
193
194 if ( class_exists('wpdev_bk_personal') ) {
195 $fields[] = sprintf(__('You can use (in subject and content of email template) any shortcodes, which you used in the booking form. Use the shortcodes in the same way as you used them in the content form at Settings Fields page.' ,'booking'));
196 $fields[] = '<hr/>';
197 }
198 $fields[] = '<strong>' . esc_html__('You can use following shortcodes in content of this template' ,'booking') . '</strong>';
199
200 // [content]
201 if ( class_exists( 'wpdev_bk_personal' ) ) {
202 /* translators: 1: ... */
203 $fields[] = sprintf( $icn, '<code>[content]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting data info about the booking, which you configured in the content form at Settings Fields page', 'booking' ), '[content]' ) ) );
204 } else {
205 /* translators: 1: ... */
206 $fields[] = sprintf( $icn, '<code>[content]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting data info about the booking', 'booking' ), '[content]' ) ) );
207 }
208
209
210 // [dates]
211 /* translators: 1: ... */
212 $fields[] = sprintf( $icn, '<code>[dates]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting the dates of booking' ,'booking'), '[dates]' ) ) );
213 /* translators: 1: ... */
214 $fields[] = sprintf( $icn, '<code>[only_dates]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting only booking dates without times' ,'booking'), '[only_dates]' ) ) );
215
216 // [check_in_date]
217 if ( ! in_array( 'check_in_date', $skip_shortcodes ) ) {
218 /* translators: 1: ... */
219 $fields[] = sprintf( $icn, '<code>[check_in_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting check-in date (first day of reservation),', 'booking' ), '[check_in_date]' ) ) );
220 /* translators: 1: ... */
221 $fields[] = sprintf( $icn, '<code>[check_in_only_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting check-in date (only date without time) (first day of reservation),', 'booking' ), '[check_in_only_date]' ) ) ); // FixIn: 8.7.2.5.
222 }
223 // [check_out_date] [check_out_plus1day]
224 if ( ! in_array( 'check_out_date', $skip_shortcodes ) ) {
225 /* translators: 1: ... */
226 $fields[] = sprintf( $icn, '<code>[check_out_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting check-out date (last day of reservation),' ,'booking'), '[check_out_date]' ) ) );
227 /* translators: 1: ... */
228 $fields[] = sprintf( $icn, '<code>[check_out_only_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting check-out date (only date without time) (last day of reservation),' ,'booking'), '[check_out_only_date]' ) ) ); // FixIn: 8.7.2.5.
229 /* translators: 1: ... */
230 $fields[] = sprintf( $icn, '<code>[check_out_plus1day]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting check-out date (last day of reservation),' ,'booking'), '[check_out_plus1day]') . ' + 1 ' . __('day', 'booking') ) );
231 }
232
233 // [dates_count]
234 if ( ! in_array( 'dates_count', $skip_shortcodes ) ) {
235 /* translators: 1: ... */
236 $fields[] = sprintf( $icn, '<code>[dates_count]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting the number of booking dates ', 'booking' ), '[dates_count]' ) ) );
237
238 $fields[] = sprintf( $icn, '<code>[days_count]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( 'Number of selected days.', 'booking' ), '[days_count]' ) ) );
239 $fields[] = sprintf( $icn, '<code>[nights_count]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( 'Number of selected nights.', 'booking' ), '[nights_count]' ) ) );
240 $fields[] = sprintf( $icn, '<code>[days_count_plus1day]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( 'Number of selected days.', 'booking' ), '[days_count_plus1day]' ) . ' (+ 1 ' . __('day', 'booking') . ')' ) );
241 }
242
243 $fields[] = '<hr/>';
244
245
246 // [id]
247 /* translators: 1: ... */
248 $fields[] = sprintf( $icn, '<code>[booking_id]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting ID of booking ' ,'booking'), '[id], [booking_id]' ) ) );
249
250 // [resource_title] [bookingtype]
251 if ( class_exists( 'wpdev_bk_personal' ) ) {
252 if ( ! in_array( 'bookingtype', $skip_shortcodes ) ) {
253 /* translators: 1: ... */
254 $fields[] = sprintf( $icn, '<code>[resource_title]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%1$s or %2$s - inserting the title of the booking resource ', 'booking' ), '[resource_title]', '[bookingtype]' ) ) );
255 }
256 }
257 // FixIn: 10.9.2.4.
258 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
259 if ( ! in_array( 'bookingtype', $skip_shortcodes ) ) {
260 /* translators: 1: ... */
261 $fields[] = sprintf( $icn, '<code>[parent_resource_title]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting the title of the parent booking resource ', 'booking' ), '[parent_resource_title]' ) ) );
262 }
263 }
264
265
266 // [cost]
267 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
268 if ( ! in_array( 'cost', $skip_shortcodes ) ) {
269 /* translators: 1: ... */
270 $fields[] = sprintf( $icn, '<code>[cost]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting the cost of booking ', 'booking' ), '[cost]' ) ) );
271 }
272 }
273
274 $fields[] = '<hr/>';
275
276 // [siteurl]
277 /* translators: 1: ... */
278 $fields[] = sprintf( $icn, '<code>[siteurl]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting your site URL ' ,'booking'), '[siteurl]' ) ) );
279
280 if ( class_exists('wpdev_bk_personal') ) {
281 /* translators: 1: ... */
282 $fields[] = sprintf( $icn, '<code>[remote_ip]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting IP address of the user who made this action ' ,'booking'), '[remote_ip]' ) ) );
283 /* translators: 1: ... */
284 $fields[] = sprintf( $icn, '<code>[user_agent]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting contents of the User-Agent: header from the current request, if there is one ' ,'booking'), '[user_agent]' ) ) );
285 /* translators: 1: ... */
286 $fields[] = sprintf( $icn, '<code>[request_url]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting address of the page (if any), where visitor make this action ' ,'booking'), '[request_url]' ) ) );
287 /* translators: 1: ... */
288 $fields[] = sprintf( $icn, '<code>[current_time]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting time of this action ' ,'booking'), '[current_time]' ) ) );
289 }
290
291 /* translators: 1: ... */
292 $fields[] = sprintf( $icn, '<code>[current_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting date of this action ' ,'booking'), '[current_date]' ) ) );
293
294 /* translators: 1: ... */
295 $fields[] = sprintf( $icn, '<code>[modification_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_date]' ) ) );
296 /* translators: 1: ... */
297 $fields[] = sprintf( $icn, '<code>[modification_year]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_year]' ) ) );
298 /* translators: 1: ... */
299 $fields[] = sprintf( $icn, '<code>[modification_month]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_month]' ) ) );
300 /* translators: 1: ... */
301 $fields[] = sprintf( $icn, '<code>[modification_day]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_day]' ) ) );
302 /* translators: 1: ... */
303 $fields[] = sprintf( $icn, '<code>[modification_hour]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_hour]' ) ) );
304 /* translators: 1: ... */
305 $fields[] = sprintf( $icn, '<code>[modification_minutes]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_minutes]' ) ) );
306 /* translators: 1: ... */
307 $fields[] = sprintf( $icn, '<code>[modification_seconds]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting modification date of booking ' ,'booking'), '[modification_seconds]' ) ) );
308 // FixIn: 10.0.0.34.
309 /* translators: 1: ... */
310 $fields[] = sprintf( $icn, '<code>[creation_date]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_date]' ) ) );
311 /* translators: 1: ... */
312 $fields[] = sprintf( $icn, '<code>[creation_year]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_year]' ) ) );
313 /* translators: 1: ... */
314 $fields[] = sprintf( $icn, '<code>[creation_month]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_month]' ) ) );
315 /* translators: 1: ... */
316 $fields[] = sprintf( $icn, '<code>[creation_day]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_day]' ) ) );
317 /* translators: 1: ... */
318 $fields[] = sprintf( $icn, '<code>[creation_hour]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_hour]' ) ) );
319 /* translators: 1: ... */
320 $fields[] = sprintf( $icn, '<code>[creation_minutes]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_minutes]' ) ) );
321 /* translators: 1: ... */
322 $fields[] = sprintf( $icn, '<code>[creation_seconds]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting creation date of booking ' ,'booking'), '[creation_seconds]' ) ) );
323
324
325
326 // [moderatelink]
327 if ( ! in_array( 'moderatelink', $skip_shortcodes ) ) {
328 /* translators: 1: ... */
329 $fields[] = sprintf( $icn, '<code>[moderatelink]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting moderate link of new booking ' ,'booking'), '[moderatelink]' ) ) );
330
331 // FixIn: 8.4.7.25.
332 /* translators: 1: ... */
333 $fields[] = sprintf( $icn, '<code>[click2approve]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting link to approve booking in 1 mouse click ' ,'booking'), '[click2approve]' ) ) );
334 /* translators: 1: ... */
335 $fields[] = sprintf( $icn, '<code>[click2decline]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting link to set booking as pending in 1 mouse click ' ,'booking'), '[click2decline]' ) ) );
336 /* translators: 1: ... */
337 $fields[] = sprintf( $icn, '<code>[click2trash]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting link for move booking to trash in 1 mouse click ' ,'booking'), '[click2trash]' ) ) );
338
339 }
340
341 // FixIn: 9.6.3.8.
342 if ( ! in_array( 'add_to_google_cal_button', $skip_shortcodes ) ) {
343 /* translators: 1: ... */
344 $fields[] = sprintf( $icn, '<code>[add_to_google_cal_button]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting link for export booking to' ,'booking'), '[add_to_google_cal_button]') . ' Google Calendar' ) );
345 /* translators: 1: ... */
346 $fields[] = sprintf( $icn, '<code>[add_to_google_cal_url]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - inserting URL for export booking to' ,'booking'), '[add_to_google_cal_url]') . ' Google Calendar' ) );
347
348 }
349
350
351 if ( class_exists('wpdev_bk_personal') ) {
352
353 //FixIn: 8.1.3.5.1
354 if ( ! in_array( 'visitorbookingslisting', $skip_shortcodes ) ) {
355 /* translators: 1: ... */
356 $fields[] = sprintf( $icn, '<code>[visitorbookingslisting]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%1$s - inserting link to the page where visitor can see listing of own bookings, (possible to use the %2$s parameter for setting different %3$s of this page. Example: %4$s )', 'booking' ), '[visitorbookingslisting]', '"url"', 'URL', '[visitorbookingslisting url="http://www.server.com/custom-page/"]' )
357 /* translators: 1: ... */
358 . ' ' . sprintf( __( 'Example of HTML a link usage: %s )', 'booking' ), '[visitorbookingslisting url="http://www.server.com/listing-custom-page/" type="link" title="Listing"]]' ) ) );
359 }
360
361 if ( ! in_array( 'visitorbookingediturl', $skip_shortcodes ) ) {
362 /* translators: 1: ... */
363 $fields[] = sprintf( $icn, '<code>[visitorbookingediturl]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%1$s - inserting link to the page where visitor can edit the reservation, (possible to use the %2$s parameter for setting different %3$s of this page. Example: %4$s )', 'booking' ), '[visitorbookingediturl]', '"url"', 'URL', '[visitorbookingediturl url="http://www.server.com/custom-page/"]' )
364 /* translators: 1: ... */
365 . ' ' . sprintf( __( 'Example of HTML a link usage: %s )', 'booking' ), '[visitorbookingediturl url="http://www.server.com/edit-custom-page/" type="link" title="Edit Booking"]]' ) ) );
366 }
367 // [visitorbookingcancelurl]
368 if ( ! in_array( 'visitorbookingcancelurl', $skip_shortcodes ) ) {
369
370 /* translators: 1: ... */
371 $fields[] = sprintf( $icn, '<code>[visitorbookingcancelurl]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%1$s - inserting link to the page where visitor can cancel the reservation, (possible to use the %2$s parameter for setting different %3$s of this page. Example: %4$s )', 'booking' ), '[visitorbookingcancelurl]', '"url"', 'URL', '[visitorbookingcancelurl url="http://www.server.com/custom-page/"]' )
372 /* translators: 1: ... */
373 . ' ' . sprintf( __( 'Example of HTML a link usage: %s )' ,'booking'), '[visitorbookingcancelurl url="http://www.server.com/cancel-custom-page/" type="link" title="Cancel Booking"]]' )
374 ) );
375 }
376
377 if ( class_exists('wpdev_bk_biz_s') ) {
378 // [visitorbookingpayurl]
379 if ( ! in_array( 'visitorbookingpayurl', $skip_shortcodes ) ) {
380 /* translators: 1: ... */
381 $fields[] = sprintf( $icn, '<code>[visitorbookingpayurl]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%1$s - inserting link to payment page where visitor can pay for the reservation (possible to use the %2$s parameter for setting different %3$s of this page. Example: %4$s )', 'booking' ), '[visitorbookingpayurl]', '"url"', 'URL', '[visitorbookingpayurl url="http://www.server.com/custom-page/"]' )
382 /* translators: 1: ... */
383 . ' ' . sprintf( __( 'Example of HTML a link usage: %s )', 'booking' ), '[visitorbookingpayurl url="http://www.server.com/payment-custom-page/" type="link" title="Pay Now"]]' ) ) );
384 }
385
386 // [paymentreason]
387 if ( ! in_array( 'paymentreason', $skip_shortcodes ) ) {
388 /* translators: 1: ... */
389 $fields[] = sprintf( $icn, '<code>[paymentreason]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - add the reason for booking payment, you can enter it before sending email, ', 'booking' ), '[paymentreason]' ) ) );
390 }
391 }
392 }
393
394 // [denyreason]
395 if ( ! in_array( 'denyreason', $skip_shortcodes ) ) {
396 /* translators: 1: ... */
397 $fields[] = sprintf( $icn, '<code>[denyreason]</code>', wpbc_tooltip_help__fix_quote( sprintf( __( '%s - add the reason booking was cancelled, you can enter it before sending email, ', 'booking' ), '[denyreason]' ) ) );
398 }
399
400
401 //$fields[] = __('HTML tags is accepted.' ,'booking');
402
403 $fields[] = '<hr/>';
404
405 // show_additional_translation_shortcode_help
406 $fields[] = '<strong>' . sprintf(__('Configuration in several languages' ,'booking') ) . '.</strong>';
407 /* translators: 1: ... */
408 $fields[] = sprintf( __( '%1$s - start new translation section, where %2$s - locale of translation', 'booking' ),'<code>[lang=LOCALE]</code>','<code>LOCALE</code>');
409 /* translators: 1: ... */
410 $fields[] = sprintf(__( 'Example #1: %s - start French translation section' ,'booking'),'<code>[lang=fr_FR]</code>');
411 /* translators: 1: ... */
412 $fields[] = sprintf(__( 'Example #2: "%s" - English and French translation of some message' ,'booking'),'<code>Thank you for your booking.[lang=fr_FR]Je vous remercie de votre reservation.</code>');
413
414
415 return (array) apply_filters( 'wpbc_email_help_shortcodes', $fields, $skip_shortcodes, $email_example );
416 }
417
418
419 function wpbc_email_troubleshooting_help_notice(){
420
421 ?><div class="wpbc-settings-notice notice-warning notice-helpful-info">
422 <?php
423 /* translators: 1: ... */
424 echo wp_kses_post( sprintf( __( 'To ensure your notifications arrive in your and your customers inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something does not seem to be sending correctly, install the %1$s or check the %2$sEmail FAQ%3$s page.', 'booking' ),
425 '<a href="https://wordpress.org/plugins/wp-mail-logging/">WP Mail Logging Plugin</a>',
426 '<a href="https://wpbookingcalendar.com/faq/no-emails/">', '</a>' ) ); ?>
427 </div><?php
428 }
429
430
431 /**
432 * Check Email subject about Language sections
433 *
434 * @param string $subject
435 * @param string $email_id
436 * @return string
437 */
438 function wpbc_email_api_get_subject_before( $subject, $email_id ) {
439
440 $subject = wpbc_lang( $subject );
441
442 return $subject;
443 }
444 add_filter( 'wpbc_email_api_get_subject_before', 'wpbc_email_api_get_subject_before', 10, 2 ); // Hook fire in api-email.php
445
446
447 /**
448 * Check Email sections content about Language sections
449 *
450 * @param array $fields_values - list of params to parse: 'content', 'header_content', 'footer_content' for different languges, etc ....
451 * @param string $email_id - Email ID
452 * @param string $email_type - 'plain' | 'html'
453 */
454 function wpbc_email_api_get_content_before( $fields_values, $email_id , $email_type ) {
455
456 if ( isset( $fields_values['content'] ) ) {
457 $fields_values['content'] = wpbc_lang( $fields_values['content'] );
458 if ( $email_type == 'html' ) {
459 $fields_values['content'] = make_clickable( $fields_values['content'] );
460 }
461 }
462
463 if ( isset( $fields_values['header_content'] ) ) {
464 $fields_values['header_content'] = wpbc_lang( $fields_values['header_content'] );
465 }
466
467 if ( isset( $fields_values['footer_content'] ) ) {
468 $fields_values['footer_content'] = wpbc_lang( $fields_values['footer_content'] );
469 }
470
471 return $fields_values;
472 }
473 add_filter( 'wpbc_email_api_get_content_before', 'wpbc_email_api_get_content_before', 10, 3 ); // Hook fire in api-email.php
474
475
476 /**
477 * Modify email content, if needed. - In HTML mail content, make links clickable.
478 *
479 * @param array $email_content - content of Email
480 * @param string $email_id - Email ID
481 * @param string $email_type - 'plain' | 'html'
482 */
483 function wpbc_email_api_get_content_after( $email_content, $email_id , $email_type ) {
484
485 if ( ( $email_type == 'html' ) || ( $email_type == 'multipart' ) )
486 $email_content = make_clickable( $email_content );
487
488 return $email_content;
489 }
490 add_filter( 'wpbc_email_api_get_content_after', 'wpbc_email_api_get_content_after', 10, 3 ); // Hook fire in api-email.php
491
492
493 /**
494 * Check Email Headers - in New Booking Email (to admin) set Reply-To header to visitor email.
495 *
496 * @param string $headers
497 * @param string $email_id - Email ID
498 * @param array $fields_values - list of params to parse: 'content', 'header_content', 'footer_content' for different languges, etc ....
499 * @param array $replace_array - list of relpaced shortcodes
500 * @return string
501 */
502 function wpbc_email_api_get_headers_after( $mail_headers, $email_id , $fields_values , $replace_array, $additional_params = array() ) {
503
504 /*
505 // Default in api-emails.php:
506 // $mail_headers = 'From: ' . $this->get_from__name() . ' <' . $this->get_from__email_address() . '> ' . "\r\n" ;
507 // $mail_headers .= 'Content-Type: ' . $this->get_content_type() . "\r\n" ;
508 //
509 // $mail_headers = "From: $mail_sender\n";
510 // preg_match('/<(.*)>/', $mail_sender, $simple_email_matches );
511 // $reply_to_email = ( count( $simple_email_matches ) > 1 ) ? $simple_email_matches[1] : $mail_sender;
512 // $mail_headers .= 'Reply-To: ' . $reply_to_email . "\n";
513 // $mail_headers .= 'X-Sender: ' . $reply_to_email . "\n";
514 // $mail_headers .= 'Return-Path: ' . $reply_to_email . "\n";
515 */
516
517 //debuge($mail_headers, $email_id , $fields_values , $replace_array);
518 if (
519 ( $email_id == 'new_admin' ) // Only for email: "New Booking to Admin"
520 || ( isset( $additional_params['reply'] ) )
521 ){
522 // FixIn: 9.7.3.17.
523 if (
524 ( ! empty( $replace_array['email'] ) )
525 && ( ! empty( $fields_values['enable_replyto'] ) )
526 && ( 'On' == $fields_values['enable_replyto'] )
527 ){ // Get email from the booking form.
528
529 $reply_to_email = sanitize_email( $replace_array['email'] );
530 if ( ! empty( $reply_to_email ) ) {
531 $mail_headers .= 'Reply-To: ' . $reply_to_email . "\r\n";
532 }
533 // $mail_headers .= 'X-Sender: ' . $reply_to_email . "\r\n" ;
534 // $mail_headers .= 'Return-Path: ' . $reply_to_email . "\r\n" ;
535 }
536 }
537
538 return $mail_headers;
539 }
540 add_filter( 'wpbc_email_api_get_headers_after', 'wpbc_email_api_get_headers_after', 10, 5 ); // Hook fire in api-email.php
541
542
543 /**
544 * Check if we can send Email - block sending in live demos
545 *
546 * @param bool $is_send_email - is send emails?.
547 * @param string $email_id - email id.
548 * @param array $fields_values - list of params to parse: 'content', 'header_content', 'footer_content' for different languges, etc ....
549 *
550 * @return bool
551 */
552 function wpbc_email_api_is_allow_send( $is_send_email, $email_id, $fields_values ) {
553
554 if ( wpbc_is_this_demo() ) {
555 $is_send_email = false;
556 }
557 // FixIn: 10.12.1.5.
558 if ( WPBC_IS_PLAYGROUND ) {
559 $is_send_email = false;
560 }
561
562 return $is_send_email;
563 }
564
565 add_filter( 'wpbc_email_api_is_allow_send', 'wpbc_email_api_is_allow_send', 10, 3 ); // Hook fire in api-email.php
566
567
568 /**
569 * Show warning about not sending emails, and reason about this.
570 *
571 * @param object $wp_error_object - WP Error object
572 * @param string $error_description - Description
573 */
574 function wpbc_email_sending_error( $wp_error_object, $error_description = '' ) {
575
576 if ( ( defined( 'WPBC_AJAX_ERROR_CATCH' ) ) && ( WPBC_AJAX_ERROR_CATCH ) ) { return false; } // FixIn: 9.2.1.10.
577
578 if ( empty( $error_description ) ) {
579 // $error_description = __( 'Unknown exception', 'booking' ) . '.'; // Overwrite to show error, if no description ???
580 }
581
582 if ( ! empty( $error_description ) ) {
583
584 $error_description = '' . __('Error', 'booking') . '! ' . __('Email was not sent. An error occurred.', 'booking') . ' ' . $error_description;
585
586 // Admin side
587 if ( function_exists( 'wpbc_show_message' ) ) {
588 wpbc_show_message ( $error_description , 15 , 'error');
589
590 }
591
592 // Front-end
593 ?>
594 <script type="text/javascript">
595 if (typeof( wpbc_front_end__show_message__warning_under_element ) == 'function') {
596 wpbc_front_end__show_message__warning_under_element( '.booking_form' , '<?php echo esc_js( $error_description ) ; ?>' );
597 }
598 </script>
599 <?php
600 } else {
601
602 // Error that have no description. Its can be Empty Object like this: WP_Error Object( 'errors' => array(), 'error_data' => array() ), or NOT
603 // debuge( $wp_error_object );
604 }
605 }
606 add_action('wpbc_email_sending_error', 'wpbc_email_sending_error', 10, 2);
607