PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.3 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 All 203 releases
booking / core / admin / page-ics-general.php

page-ics-general.php in Booking Calendar 10.1.3, at core/admin/page-ics-general.php

685 lines 30.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @menu Booking > Settings > (Sync) General page
5 * @category Settings API
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 * @modified 2017-12-18
11 *
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16 //FixIn: 8.1.1.10
17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
20
21 /** API for Settings Page */
22 class WPBC_API_SettingsGeneralSync extends WPBC_Settings_API {
23
24 /**
25 * Settings API Constructor
26 * During creation, system try to load values from DB, if exist.
27 *
28 * @param type $id - "Pure Name"
29 */
30 public function __construct( $id, $init_fields_values = array(), $options = array() ) {
31
32 // This configuration meaning that options will be saved separately, without $id of this CLASS, just by using names of fields -- update_bk_option( $this->options['db_prefix_option'] . $field_name , $field_value );
33 $default_options = array(
34 'db_prefix_option' => ''
35 , 'db_saving_type' => 'separate'
36 );
37 // separate_prefix: update_bk_option( $this->options['db_prefix_option'] . $settings_id . '_' . $field_name , $value );
38 $options = wp_parse_args( $options, $default_options );
39
40 /**
41 * Activation and deactivation of these options already done at the wpbc-gcal.php file
42
43 // add_bk_action( 'wpbc_other_versions_activation', array( $this, 'activate' ) ); // Activate
44 // add_bk_action( 'wpbc_other_versions_deactivation', array( $this, 'deactivate' ) ); // Deactivate
45 */
46
47 parent::__construct( $id, $options, $init_fields_values ); // Define ID of Setting page and options
48 }
49
50
51
52 /** Define settings Fields */
53 public function init_settings_fields() {
54
55 $this->fields = array();
56
57 // TODO:
58 // add_bk_option( 'booking_gcal_events_form_fields', 'a:3:{s:5:"title";s:9:"text^name";s:11:"description";s:12:"text^details";s:5:"where";s:5:"text^";}');
59
60 // Problem with email^email field, previously its was text^email and problem with textarea^details field, previously its was text^details
61
62
63 ////////////////////////////////////////////////////////////////////////
64 // Get form fields from different forms in the paid versions
65 ////////////////////////////////////////////////////////////////////////
66 $options = array();
67 $options[ 'text^' ] = __('None' ,'booking');
68
69 $booking_forms = wpbc_get__in_all_forms__field_names_arr();
70
71 foreach ( $booking_forms as $single_booking_form ) {
72
73 //OPTGROUP - Open
74 $options[ $single_booking_form['name'] ] = array(
75 'title' => ucfirst( trim( $single_booking_form['name'] ) )
76 , 'optgroup' => true
77 , 'close' => false );
78
79 $field_listing = $single_booking_form['listing'];
80 for ( $i = 0; $i < $single_booking_form['num']; $i++ ) {
81 $options[ ( ( trim( $single_booking_form['name'] ) != 'standard' ) ? trim( $single_booking_form['name'] ) . '^' : '' ) .
82 trim( $single_booking_form['listing']['fields_type'][$i] ). '^' . trim( $single_booking_form['listing']['fields'][$i] )
83 ] = ( trim( $single_booking_form['listing']['labels'][$i] ) );
84 }
85
86 //OPTGROUP - Close
87 $options[ $single_booking_form['name'] . '_close' ] = array(
88 'title' => $single_booking_form['name'] // ucfirst( trim( $option_group_name ) )
89 , 'optgroup' => true
90 , 'close' => true );
91 }
92 ////////////////////////////////////////////////////////////////////////
93
94
95
96 // booking_gcal_events_form_fields - !!! real name of option to save. This option have to be skipped during saving and during loading need some actions.
97 $this->fields['booking_gcal_events_form_fields_title'] = array(
98 'type' => 'select'
99 , 'default' => ''
100 , 'title' => __('Event Title', 'booking')
101 , 'description' => sprintf( __( 'Select field for assigning to %sevent property%s' ,'booking'), '<b>', '</b>' )
102 , 'description_tag' => 'span'
103 , 'css' => ''
104 , 'options' => $options
105 , 'group' => 'events_fields'
106 );
107 $this->fields['booking_gcal_events_form_fields_description'] = array(
108 'type' => 'select'
109 , 'default' => ''
110 , 'title' => __('Event Description (optional field)' ,'booking')
111 , 'description' => sprintf( __( 'Select field for assigning to %sevent property%s' ,'booking'), '<b>', '</b>' )
112 , 'description_tag' => 'span'
113 , 'css' => ''
114 , 'options' => $options
115 , 'group' => 'events_fields'
116 );
117 $this->fields['booking_gcal_events_form_fields_where'] = array(
118 'type' => 'select'
119 , 'default' => ''
120 , 'title' => __('Location' ,'booking')
121 , 'description' => sprintf( __( 'Select field for assigning to %sevent property%s' ,'booking'), '<b>', '</b>' )
122 , 'description_tag' => 'span'
123 , 'css' => ''
124 , 'options' => $options
125 , 'group' => 'events_fields'
126 );
127 ////////////////////////////////////////////////////////////////////////
128
129
130 $options = array();
131 $options[''] = __('Default' ,'booking');
132
133 // structure: $wpbc_booking_region_cities_list["Pacific"]["Fiji"] = "Fiji";
134 $wpbc_booking_region_cities_list = wpbc_get_booking_region_cities_list(); //FixIn: 8.9.4.9
135
136 foreach ( $wpbc_booking_region_cities_list as $region => $region_cities) {
137
138 //OPTGROUP - Open
139 $options[ $region ] = array(
140 'title' => ucfirst( trim( $region ) )
141 , 'optgroup' => true
142 , 'close' => false );
143
144 foreach ($region_cities as $city_key => $city_title) {
145
146 $options[ trim( $region .'/'. $city_key ) ] = ( trim( $city_title ) );
147 }
148
149 //OPTGROUP - Close
150 $options[ $region . '_close' ] = array(
151 'title' => $region // ucfirst( trim( $option_group_name ) )
152 , 'optgroup' => true
153 , 'close' => true );
154 }
155 $this->fields['booking_gcal_timezone'] = array(
156 'type' => 'select'
157 , 'default' => ''
158 , 'title' => __('Timezone', 'booking')
159 , 'description' => __('Select a city in your required timezone, if you are having problems with dates and times.' ,'booking')
160 , 'description_tag' => 'p'
161 , 'css' => ''
162 , 'options' => $options
163 , 'group' => 'general'
164 );
165
166 //FixIn: 9.5.4.1
167 $this->fields['booking_ics_import_append_checkout_day'] = array(
168 'type' => 'checkbox'
169 , 'default' => 'On'
170 , 'title' => __('Append check out day', 'booking')
171 , 'label' => __('Append one check out day, during import .ics feeds' ,'booking')
172 , 'description' => ''
173 , 'group' => 'import_advanced'
174 );
175
176 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
177 //FixIn: 8.1.3.29
178 $this->fields['booking_ics_import_add_change_over_time'] = array(
179 'type' => 'checkbox'
180 , 'default' => 'On'
181 , 'title' => __('Use check in/out time', 'booking')
182 , 'label' => __('Use check in/out time of plugin, during import .ics feeds' ,'booking')
183 , 'description' => ''
184 , 'group' => 'import_advanced'
185 );
186 //FixIn: 8.5.2.3
187 $this->fields['booking_is_ics_export_only_approved'] = array(
188 'type' => 'checkbox'
189 , 'default' => 'Off'
190 , 'title' => __('Export only approved bookings', 'booking')
191 , 'label' => __('Enable of export only approved bookings in .ics feeds' ,'booking')
192 , 'description' => ''
193 , 'group' => 'export_advanced'
194 );
195
196 //FixIn: 8.8.3.19
197 $this->fields['booking_is_ics_export_imported_bookings'] = array(
198 'type' => 'select'
199 , 'default' => ''
200 , 'title' => __('Export bookings type', 'booking')
201 , 'description' => __('Select which type of bookings to export' ,'booking')
202 , 'description_tag' => 'p'
203 , 'css' => ''
204 , 'options' => array (
205 '' => __('All bookings'),
206 'plugin' => __('Bookings created in Booking Calendar'),
207 'imported' => __('Imported bookings'),
208 )
209 , 'group' => 'export_advanced'
210 );
211 }
212
213 //FixIn: 8.5.1.1
214 /*
215 //FixIn: 8.4.7.1
216 $this->fields['booking_ics_force_import'] = array(
217 'type' => 'checkbox'
218 , 'default' => 'Off'
219 , 'title' => __('Force import', 'booking')
220 , 'label' => __('Import bookings without checking, if such bookings already have been imported.' ,'booking')
221 , 'description' => ''
222 , 'group' => 'import_advanced'
223 );
224 /**/
225 //FixIn: 8.4.7.12 //FixIn: //FixIn: 9.1.2.6
226 $this->fields['booking_ics_force_trash_before_import'] = array(
227 'type' => 'select'
228 , 'default' => 'Off'
229 , 'title' => __('Trash / delete all imported bookings before new import', 'booking')
230 , 'description' => __('Move all previously imported bookings to trash or permanently delete before new import bookings. Its can resolve issue of updating deleted and edited events in external sources. Its work only, if you are using one source (.ics feed) for importing into specific booking resource!' ,'booking')
231 , 'description_tag' => 'p'
232 , 'css' => ''
233 , 'options' => array ( //FixIn: 9.7.3.9
234 'Off' => __( 'Do nothing', 'booking' ),
235 'On' => __( 'Trash imported bookings', 'booking' ),
236 'delete' => __( 'Permanently delete', 'booking' )
237 )
238 , 'group' => 'import_advanced'
239 );
240
241
242 $this->fields['booking_condition_import_only_new'] = array(
243 'type' => 'checkbox'
244 , 'default' => 'Off'
245 , 'title' => __( 'Import conditions', 'booking' )//__('Import only new events', 'booking')
246 , 'label' => '<strong>' . __( 'Import Only New Events', 'booking' ) . '</strong> - ' . __( 'Import only if the event has not been imported before.', 'booking' )
247 , 'description' => ''
248 , 'group' => 'import_advanced'
249 );
250 $this->fields['booking_condition_import_if_available'] = array(
251 'type' => 'checkbox'
252 , 'default' => 'Off'
253 , 'title' => ''//__('Import if dates available', 'booking')
254 , 'label' => '<strong>' . __( 'Import if Dates Available', 'booking' ) . '</strong> - ' . __( 'Import only if dates are available in the source calendar.', 'booking' )
255 , 'description' => ''
256 , 'group' => 'import_advanced'
257 );
258
259
260 ////////////////////////////////////////////////////////////////////////
261
262 }
263
264 }
265
266
267 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
268 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
269
270
271 /**
272 * Show Content
273 * Update Content
274 * Define Slug
275 * Define where to show
276 */
277 class WPBC_Page_SettingsGeneralSync extends WPBC_Page_Structure {
278
279 public $settings_api = false;
280
281
282 /**
283 * API - for Fields of this Settings Page
284 *
285 * @param array $init_fields_values - array of init form fields data - this array can ovveride "default" fields and loaded data.
286 * @return object API
287 */
288 public function get_api( $init_fields_values = array() ){
289
290 if ( $this->settings_api === false ) {
291 $this->settings_api = new WPBC_API_SettingsGeneralSync( 'general_sync' , $init_fields_values );
292 }
293 return $this->settings_api;
294 }
295
296
297 public function in_page() {
298 return 'wpbc-settings';
299 }
300
301
302 public function tabs() {
303
304 $tabs = array();
305
306 $tabs[ 'sync' ] = array(
307 'title' => __( 'Sync', 'booking') // Title of TAB
308 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
309 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
310 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
311 //, 'position' => '' // 'left' || 'right' || ''
312 //, 'css_classes'=> '' // CSS class(es)
313 //, 'icon' => '' // Icon - link to the real PNG img
314 , 'font_icon' => 'wpbc_icn_sync_alt' // CSS definition of forn Icon
315 //, 'default' => false // Is this tab activated by default or not: true || false.
316 //, 'disabled' => false // Is this tab disbaled: true || false.
317 //, 'hided' => false // Is this tab hided: true || false.
318 , 'subtabs' => array()
319 );
320
321
322 $subtabs = array();
323
324 $subtabs[ 'general' ] = array(
325 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
326 , 'title' => __( 'General', 'booking' ) // Title of TAB
327 , 'page_title' => __( 'General Settings', 'booking' ) . ' - ' . __( 'Sync', 'booking' ) // Title of Page
328 , 'hint' => __( 'General Settings', 'booking' ) . ' - ' . __( 'Sync', 'booking' ) // Hint
329 , 'link' => '' // link
330 , 'position' => '' // 'left' || 'right' || ''
331 , 'css_classes' => '' // CSS class(es)
332 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
333 //, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon
334 , 'header_font_icon' => 'wpbc_icn_sync_alt' // CSS definition of Font Icon //FixIn: 9.6.1.4
335 , 'default' => true // Is this sub tab activated by default or not: true || false.
336 , 'disabled' => false // Is this sub tab deactivated: true || false.
337 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
338 , 'content' => 'content' // Function to load as conten of this TAB
339 );
340
341 $tabs[ 'sync' ]['subtabs'] = $subtabs;
342
343
344 return $tabs;
345 }
346
347
348 /** Show Content of Settings page */
349 public function content() {
350
351 $this->css();
352
353 ////////////////////////////////////////////////////////////////////////
354 // Checking
355 ////////////////////////////////////////////////////////////////////////
356
357 do_action( 'wpbc_hook_settings_page_header', 'ics_general_settings' ); // Define Notices Section and show some static messages, if needed
358
359 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
360
361 // if ( ! wpbc_is_mu_user_can_be_here('only_super_admin') ) return false; // User is not Super admin, so exit. Basically its was already checked at the bottom of the PHP file, just in case.
362
363
364
365 ////////////////////////////////////////////////////////////////////////
366 // Load Data
367 ////////////////////////////////////////////////////////////////////////
368
369 $this->get_api(); // Load fields Data from DB
370
371 /**
372 * O v e r l o a d some values for our pseudo options - during normal opening of page
373 * if we making saving, so we need to overload these options
374 * one more time
375 */
376 $booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
377 $booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
378
379 if (isset($booking_gcal_events_form_fields['title']))
380 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_title', $booking_gcal_events_form_fields['title'] );
381
382 if (isset($booking_gcal_events_form_fields['description']))
383 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_description', $booking_gcal_events_form_fields['description'] );
384
385 if (isset($booking_gcal_events_form_fields['where']))
386 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_where', $booking_gcal_events_form_fields['where'] );
387
388 $this->get_api()->set_values_to_fields();
389
390
391 ////////////////////////////////////////////////////////////////////////
392 // S u b m i t Main Form
393 ////////////////////////////////////////////////////////////////////////
394
395 $submit_form_name = 'wpbc_general_sync'; // Define form name
396
397 // $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
398
399 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
400
401 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
402 $nonce_gen_time = check_admin_referer( 'wpbc_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page
403
404 // Save Changes
405 $this->update();
406 }
407
408 ////////////////////////////////////////////////////////////////////////
409 // JavaScript: Tooltips, Popover, Datepick (js & css)
410 ////////////////////////////////////////////////////////////////////////
411
412 echo '<span class="wpdevelop">';
413
414 wpbc_js_for_bookings_page();
415
416 echo '</span>';
417
418 ?><div class="clear" style="margin-bottom:0px;"></div><?php
419
420
421 ////////////////////////////////////////////////////////////////////////
422 // Content ////////////////////////////////////////////////////////////
423 ?>
424 <div class="clear" style="margin-bottom:0px;"></div>
425 <span class="metabox-holder">
426 <form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post" autocomplete="off">
427 <?php
428 // N o n c e field, and key for checking S u b m i t
429 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
430 ?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" /><?php
431 ?><div class="clear"></div><?php
432
433 ?><div class="clear" style="height:10px;"></div><?php
434
435
436 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_events_general', __('General Settings' ,'booking') );
437
438 $this->get_api()->show( 'general' );
439
440 wpbc_close_meta_box_section();
441
442
443 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_events_fields', __('Import' ,'booking') . ' > ' . __('Assign events fields to specific booking form field' ,'booking') );
444
445 $this->get_api()->show( 'events_fields' );
446
447 wpbc_close_meta_box_section();
448
449 //FixIn: 8.5.1.1
450 // if ( class_exists( 'wpdev_bk_biz_s' ) ) {
451
452 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_import', __( 'Import', 'booking' ) . ' ' . __( 'Advanced', 'booking' ) );
453
454 $this->get_api()->show( 'import_advanced' );
455
456 wpbc_close_meta_box_section();
457
458
459 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_export', __( 'Export', 'booking' ) . ' ' . __( 'Advanced', 'booking' ) );
460
461 $this->get_api()->show( 'export_advanced' );
462
463 wpbc_close_meta_box_section();
464 // }
465 ?>
466
467 <div class="clear"></div>
468
469 <input type="submit" value="<?php _e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" />
470 <?php
471
472 ?>
473 </form>
474 </span>
475 <?php
476
477 do_action( 'wpbc_hook_settings_page_footer', 'ics_general_settings' );
478
479 $this->enqueue_js();
480
481 }
482
483
484 /** Save Chanages */
485 public function update() {
486 // if ( function_exists( 'wpbc_general_sync__update') )
487 // wpbc_general_sync__update();
488
489 // Get Validated Email fields
490 $validated_fields = $this->get_api()->validate_post();
491
492 $validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__general_sync', $validated_fields ); //Hook for validated fields.
493
494 //debuge($validated_fields);
495
496 $this->get_api()->save_to_db( $validated_fields );
497
498 wpbc_show_changes_saved_message();
499 }
500
501
502 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
503
504 /** CSS for this page */
505 private function css() {
506 ?>
507 <style type="text/css">
508 .wpbc_import_ics_bar .wpbc_import_btn,
509 .wpbc_import_ics_bar .wpbc_upload_btn{
510 float:left;
511 margin:9px 5px 10px 1px;
512
513 }
514 .wpbc_import_ics_bar .wpbc_import_div {
515 float:left;
516 width:70%;
517 }
518 .wpbc_import_ics_bar .wpbc_import_br_selection,
519 .wpbc_import_ics_bar .wpbc_import_url {
520 float:left;
521 width:28%;
522 height: 2em;
523 padding: 2px;
524 border-radius: 0;
525 margin:10px 5px 10px 1px;
526 }
527 .wpbc_import_ics_bar .wpbc_import_url {
528 width:70%;
529 padding: 2px 5px;
530 }
531 .wpbc_system_info_log {
532 font-size: 11px;
533 line-height: 1.5em;
534 border: 2px dashed #e85;
535 padding: 5px 20px;
536 display: none;
537 }
538 /**********************************************************************************************************/
539 .wpbc-help-message {
540 border:none;
541 }
542 /* toolbar fix */
543 .wpdevelop .visibility_container .control-group {
544 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
545 }
546 /* Selectbox element in toolbar */
547 .visibility_container select optgroup{
548 color:#999;
549 vertical-align: middle;
550 font-style: italic;
551 font-weight: 400;
552 }
553 .visibility_container select option {
554 padding:5px;
555 font-weight: 600;
556 }
557 .visibility_container select optgroup option{
558 padding: 5px 20px;
559 color:#555;
560 font-weight: 600;
561 }
562 #wpbc_create_new_custom_form_name_fields {
563 width: 360px;
564 display:none;
565 }
566 @media (max-width: 782px) {
567 .wpbc_import_ics_bar .wpbc_import_br_selection,
568 .wpbc_import_ics_bar .wpbc_import_div {
569 float:none;
570 width:100%;
571 }
572 }
573 @media (max-width: 399px) {
574 #wpbc_create_new_custom_form_name_fields {
575 width: 100%;
576 }
577 }
578 </style>
579 <?php
580 }
581
582
583
584 /**
585 * Add Custon JavaScript - for some specific settings options
586 * Executed After post content, after initial definition of settings, and possible definition after POST request.
587 *
588 * @param type $menu_slug
589 */
590 private function enqueue_js(){
591
592 // JavaScript //////////////////////////////////////////////////////////////
593
594 $js_script = '';
595
596 // //Show|Hide grayed section
597 // $js_script .= "
598 // if ( ! jQuery('#ics_general_booking_gcal_auto_import_is_active').is(':checked') ) {
599 // jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
600 // }
601 // ";
602
603 // // Hide|Show on Click Radion
604 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
605 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
606 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
607 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
608 // } else {
609 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
610 // }
611 // } ); ";
612
613 ////////////////////////////////////////////////////////////////////////
614
615
616 // Eneque JS to the footer of the page
617 wpbc_enqueue_js( $js_script );
618 }
619
620 // </editor-fold>
621
622 }
623 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsGeneralSync() , '__construct') ); // Executed after creation of Menu
624
625
626 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
627 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
628
629
630 /**
631 * Validate some fields during saving to DB
632 * Skip saving some pseudo options, instead of that creare new real option.
633 *
634 * @param array $validated_fields
635 * @return type
636 */
637 function wpbc_fields_before_saving_to_db__general_sync( $validated_fields ) {
638
639 // Set new option based on pseudo options
640 $validated_fields['booking_gcal_events_form_fields'] = array(
641 'title' => $validated_fields['booking_gcal_events_form_fields_title']
642 , 'description' => $validated_fields['booking_gcal_events_form_fields_description']
643 , 'where' => $validated_fields['booking_gcal_events_form_fields_where']
644 );
645 // Unset several pseudo options.
646 unset( $validated_fields['booking_gcal_events_form_fields_title'] );
647 unset( $validated_fields['booking_gcal_events_form_fields_description'] );
648 unset( $validated_fields['booking_gcal_events_form_fields_where'] );
649
650 return $validated_fields;
651 }
652 add_filter('wpbc_fields_before_saving_to_db__general_sync', 'wpbc_fields_before_saving_to_db__general_sync');
653
654
655
656 /**
657 * Override fields array of Settings page, AFTER saving to DB. Some fields have to have different Values.
658 * Set here values for our pseudo-options, after saving to DB
659 * Because they was not overloading during this saving
660 *
661 * @param array $fields
662 * @param string $page_id
663 * @return array - fields
664 */
665 function wpbc_fields_after_saving_to_db__general_sync( $fields, $page_id ) {
666
667 if ( $page_id == 'general_sync' ) { // Check our API ID relative saving of this settings page
668
669 $booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
670 $booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
671
672 if (isset($booking_gcal_events_form_fields['title']))
673 $fields[ 'booking_gcal_events_form_fields_title' ]['value'] = $booking_gcal_events_form_fields['title'];
674
675 if (isset($booking_gcal_events_form_fields['description']))
676 $fields[ 'booking_gcal_events_form_fields_description' ]['value'] = $booking_gcal_events_form_fields['description'];
677
678 if (isset($booking_gcal_events_form_fields['where']))
679 $fields[ 'booking_gcal_events_form_fields_where' ]['value'] = $booking_gcal_events_form_fields['where'];
680
681 }
682 return $fields;
683 }
684 add_filter('wpbc_fields_after_saving_to_db', 'wpbc_fields_after_saving_to_db__general_sync', 10, 2);
685