PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.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
← All changes | core/wpbc-dev-api.php +159 -20 10.1.311.8.3 View file →
@@ -11,14 +11,15 @@
11 11 *
12 12 * @modified 2017-06-24
13 13 */
14 14
15 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15 +if ( ! defined( 'ABSPATH' ) ) {
16 + exit; // Exit if accessed directly.
17 +}
16 18
17 -//FixIn: 8.0
18 19
19 20 // ---------------------------------------------------------------------------------------------------------------------
20 -// Add New Booking
21 +// Add New Booking .
21 22 // ---------------------------------------------------------------------------------------------------------------------
22 23 /**
23 24 * Add New Booking
24 25 *
@@ -256,8 +257,10 @@
256 257 * ]
257 258 * OR
258 259 * [ 'result' => 'error', 'message' => 'Booking can not be saved ...' ]
259 260 */
261 + $server_request_uri = ( ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
262 + $server_http_referer_uri = ( ( isset( $_SERVER['HTTP_REFERER'] ) ) ? sanitize_text_field( $_SERVER['HTTP_REFERER'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
260 263 $where_to_save_booking = wpbc__where_to_save_booking( array(
261 264 'resource_id' => $resource_id, // 2
262 265 'skip_booking_id' => '', // '', | 125 if edit booking
263 266 'dates_only_sql_arr' => $dates_only_sql_arr, // [ "2023-10-18", "2023-10-25", "2023-11-25" ]
@@ -262,9 +265,9 @@
262 265 'skip_booking_id' => '', // '', | 125 if edit booking
263 266 'dates_only_sql_arr' => $dates_only_sql_arr, // [ "2023-10-18", "2023-10-25", "2023-11-25" ]
264 267 'time_as_seconds_arr' => $time_as_seconds_arr, // [ 36000, 39600 ]
265 268 'how_many_items_to_book' => 1, // 1
266 - 'request_uri' => ( ( ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) ? $_SERVER['HTTP_REFERER'] : $_SERVER['REQUEST_URI'] ), // front-end: $_SERVER['REQUEST_URI'] | ajax: $_SERVER['HTTP_REFERER'] // It different in Ajax requests. It's used for change-over days to detect for exception at specific pages, // 'http://beta/resource-id2/'
269 + 'request_uri' => ( ( ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) ? $server_http_referer_uri : $server_request_uri ), // front-end: $server_request_uri | ajax: $_SERVER['HTTP_REFERER'] // It different in Ajax requests. It's used for change-over days to detect for exception at specific pages, // 'http://beta/resource-id2/'
267 270 'as_single_resource' => true, // false
268 271 'is_use_booking_recurrent_time' => $params['is_use_booking_recurrent_time']
269 272 ) );
270 273
@@ -288,9 +291,9 @@
288 291 // ---------------------------------------------------------------------------------------------------------------------
289 292 // Get Bookings Array - [Listing]
290 293 // ---------------------------------------------------------------------------------------------------------------------
291 294 /**
292 - * Get bookings array from Booking Calendar
295 + * Deprecated: Get bookings array from Booking Calendar
293 296 *
294 297 * @param aray $params
295 298 * @return array
296 299 ( [bookings] => Array (
@@ -426,9 +429,9 @@
426 429 , 'wh_cost' => ''
427 430 , 'wh_cost2' => ''
428 431 , 'or_sort' => ''
429 432 , 'page_num' => '1'
430 - , 'wh_trash' => '' // '' | trash | any //FixIn: 8.0.2.8
433 + , 'wh_trash' => '' // '' | trash | any // FixIn: 8.0.2.8.
431 434 , 'limit_hours' => '0,24'
432 435 , 'only_booked_resources' => 0
433 436 , 'page_items_count' => '100000'
434 437 );
@@ -438,9 +441,9 @@
438 441
439 442 return $bookings_arr;
440 443 }
441 444
442 -//FixIn: 8.7.6.4
445 +// FixIn: 8.7.6.4.
443 446 /**
444 447 * Get Booking Data as array of properties
445 448 *
446 449 * @param string $booking_id - digit '11' or comma separated '11,19,12'
@@ -451,10 +454,11 @@
451 454
452 455 global $wpdb;
453 456 $booking_id = wpbc_clean_digit_or_csd( $booking_id );
454 457
455 - $slct_sql = "SELECT * FROM {$wpdb->prefix}booking as b left join {$wpdb->prefix}bookingdates as bd on (b.booking_id = bd.booking_id) WHERE b.booking_id IN (%s) LIMIT 0,1";
456 - $slct_sql = $wpdb->prepare( $slct_sql, $booking_id );
458 + $slct_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as b left join {$wpdb->prefix}bookingdates as bd on (b.booking_id = bd.booking_id) WHERE b.booking_id IN (%s) LIMIT 0,1", $booking_id );
459 +
460 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
457 461 $slct_sql_results = $wpdb->get_results( $slct_sql, ARRAY_A );
458 462
459 463 $data = array();
460 464
@@ -478,9 +482,9 @@
478 482 }
479 483 return $data;
480 484 }
481 485
482 -//FixIn: 8.7.7.3
486 +// FixIn: 8.7.7.3.
483 487 /**
484 488 * Get booking form fields in Booking Calendar Free version
485 489 * @return array
486 490 */
@@ -485,15 +489,14 @@
485 489 * @return array
486 490 */
487 491 function wpbc_get_form_fields_free() {
488 492 $obj = array();
489 - if ( class_exists( 'WPBC_Page_SettingsFormFieldsFree' ) ) {
493 + if ( function_exists( 'wpbc_simple_form__db__get_visual_form_structure' ) ) {
490 494
491 - //FixIn: 8.7.8.7
492 - $form_free = new WPBC_Page_SettingsFormFieldsFree();
493 - $form_fields = $form_free->get_booking_form_structure_for_visual();
495 + $form_fields = wpbc_simple_form__db__get_visual_form_structure();
496 +
494 497 foreach ( $form_fields as $field ) {
495 - //FixIn: 8.7.8.7
498 + // FixIn: 8.7.8.7.
496 499 if ( ( ! empty( $field['name'] ) )
497 500 && ( ! empty( $field['label'] ) )
498 501 && ( ! in_array( $field['type'], array(
499 502 'captcha',
@@ -508,8 +511,73 @@
508 511 }
509 512
510 513
511 514 /**
515 + * Hook for definition of the different DEFAULT parameters for single booking resource, that was just created by user at the Booking > Resources page.
516 + * In this example, you need to uncomment this line:
517 + * //add_action('wpbc_resource_created','wpbc_resource_created__add_other_params', 10, 1);
518 + * And the following function add Duration-Based Costs for the exist booking resources and some Search Filters.
519 + */
520 +//add_action('wpbc_resource_created','wpbc_resource_created__add_other_params', 10, 1);
521 +function wpbc_resource_created__add_other_params( $resource_id ) {
522 +
523 + global $wpdb;
524 +
525 + // -----------------------------------------------------------------------------------------------------------------
526 + // Add default 'Duration-Based Costs'
527 + // -----------------------------------------------------------------------------------------------------------------
528 + $wp_queries = array();
529 +
530 + //WP Booking Calendar > Prices > Daily Costs page -> section Duration-Based Costs
531 + $season_id = 4;
532 + $meta_arr = array(
533 + array( 'active' => 'On', 'type' => 'summ', 'from' => 7, 'to' => 14, 'cost' => 90, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
534 + array( 'active' => 'On', 'type' => '>', 'from' => 8, 'to' => 27, 'cost' => 90, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
535 + array( 'active' => 'On', 'type' => 'summ', 'from' => 28, 'to' => 14, 'cost' => 75, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
536 + array( 'active' => 'On', 'type' => '>', 'from' => 29, 'to' => 60, 'cost' => 75, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
537 + array( 'active' => 'On', 'type' => '=', 'from' => 'LAST', 'to' => 14, 'cost' => 0, 'cost_apply_to' => 'fixed' ,'season_filter' => $season_id )
538 + );
539 + $meta_str = maybe_serialize($meta_arr);
540 + $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking_types_meta ( type_id, meta_key, meta_value ) VALUES ( {$resource_id}, 'costs_depends', '{$meta_str}' );";
541 +
542 + // // WP Booking Calendar > Prices > Daily Costs page -> section Seasonal Pricing
543 + // $meta_str = "a:3:{s:6:\"filter\";a:3:{i:3;s:3:\"Off\";i:2;s:3:\"Off\";i:1;s:2:\"On\";}s:4:\"rate\";a:3:{i:3;s:1:\"0\";i:2;s:1:\"0\";i:1;s:3:\"200\";}s:9:\"rate_type\";a:3:{i:3;s:1:\"%\";i:2;s:1:\"%\";i:1;s:1:\"%\";}}";
544 + // $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking_types_meta ( type_id, meta_key, meta_value ) VALUES ( {$resource_id}, 'rates', '{$meta_str}' );";
545 + //
546 + // //WP Booking Calendar > Availability > Season Availability page
547 + // $meta_str = "a:2:{s:7:\"general\";s:2:\"On\";s:6:\"filter\";a:3:{i:3;s:3:\"Off\";i:2;s:2:\"On\";i:1;s:3:\"Off\";}}";
548 + // $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking_types_meta ( type_id, meta_key, meta_value ) VALUES ( {$resource_id}, 'availability', '{$meta_str}' );";
549 +
550 + foreach ( $wp_queries as $wp_q ) {
551 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
552 + $wpdb->query( $wp_q );
553 + }
554 +
555 + // -----------------------------------------------------------------------------------------------------------------
556 + // Add default 'Searchable Filters':
557 + // -----------------------------------------------------------------------------------------------------------------
558 + // Get search options for all booking resources
559 + $search_options_arr = wpbc_searchable_resources__get_all_options();
560 +
561 + // Booking Calendar Business Large version
562 + $demo_examples = array();
563 + $demo_examples[ $resource_id ] = array();
564 + $demo_examples[ $resource_id ]['is_searchable'] = 'On';
565 + // $demo_examples[ $resource_id ]['title'] = 'General Consultation';
566 + // $demo_examples[ $resource_id ]['url'] = get_site_url() . '/demo/service-a/#main';
567 + // $demo_examples[ $resource_id ]['picture'] = get_site_url() . '/demo_assets/service-a.jpg';
568 + // $demo_examples[ $resource_id ]['description'] = '...';
569 + $demo_examples[ $resource_id ]['options'] = 'neighborhood^=^La Ecovilla~housing_type^=^Entire home~price_range^=^$150-$199~bedrooms^<=^1~my_contribution^=^1';
570 +
571 + foreach ( $demo_examples as $res_id => $res_options ) {
572 + $search_options_arr[ $res_id ] = $res_options;
573 + }
574 + wpbc_searchable_resources__save_all_options( $search_options_arr );
575 +
576 +}
577 +
578 +
579 +/**
512 580 * DEPRECATED :: Hook action after creation new booking
513 581 * @param int $booking_id
514 582 * @param int $resource_id
515 583 * @param string $str_dates__dd_mm_yyyy - "30.02.2014, 31.02.2014, 01.03.2014"
@@ -591,24 +659,24 @@
591 659 * @param int/string $is_approved_dates - '1' | '0' | 1 | 0 1 -approved, 0 - pending
592 660 function your_cust_func_wpbc_booking_approved( $booking_id, $is_approved_dates ) {
593 661
594 662 }
595 - add_action( 'wpbc_booking_approved', 'your_cust_func_wpbc_booking_approved', 100, 2 ); //FixIn: 8.7.6.1
663 + add_action( 'wpbc_booking_approved', 'your_cust_func_wpbc_booking_approved', 100, 2 ); // FixIn: 8.7.6.1.
596 664 */
597 665
598 666 /**
599 667 * Hook action after trash of booking:
600 - * do_action( 'wpbc_booking_trash', $booking_id, $is_trash ); //FixIn: 8.7.6.2
668 + * do_action( 'wpbc_booking_trash', $booking_id, $is_trash ); // FixIn: 8.7.6.2.
601 669 */
602 670
603 671 /**
604 672 * Hook action after delete of booking:
605 - * do_action( 'wpbc_booking_delete', $approved_id_str ); //FixIn: 8.7.6.3
673 + * do_action( 'wpbc_booking_delete', $approved_id_str ); // FixIn: 8.7.6.3.
606 674 */
607 675
608 676 /**
609 677 * Hooks in new Booking Listing page for different actions:
610 - * //FixIn: 9.5.3.3
678 + * // FixIn: 9.5.3.3.
611 679 do_action( 'wpbc_set_booking_locale', $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
612 680 do_action( 'wpbc_set_booking_pending', $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
613 681 do_action( 'wpbc_set_booking_approved' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
614 682 do_action( 'wpbc_move_booking_to_trash' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
@@ -650,5 +718,76 @@
650 718 * $resources_id_arr = explode( ',', $resources_id_str );
651 719 * // Do something ...
652 720 * }
653 721 * add_action( 'wpbc_deleted_booking_resources', 'my_func__on_resource_delete' );
654 - */
722 + */
723 +
724 +
725 +/**
726 + * Some exmaples of fucntions usage.
727 + *
728 + * @return void
729 + */
730 +function wpbc_create_a_new_booking_exmaple(){
731 +
732 + // -----------------------------------------------------------------------------------------------------------------
733 + // Example #1.
734 + // -----------------------------------------------------------------------------------------------------------------
735 + $booking = array(
736 + 'dates' => array( '2027-06-24', '2027-06-24', '2027-06-25', '2027-06-26' ),
737 + 'data' => array(
738 + 'secondname' => array( 'value' => 'Smith', 'type' => 'text' ),
739 + 'name' => 'Rika',
740 + 'email' => array( 'value' => 'rika@cost.com', 'type' => 'email' ),
741 + )
742 + );
743 + $booking_id = wpbc_api_booking_add_new( $booking['dates'], $booking['data'] );
744 +
745 + // -----------------------------------------------------------------------------------------------------------------
746 + // Example #2. - Add bew booking, without checking if the dates/times are available in source booking resource.
747 + // -----------------------------------------------------------------------------------------------------------------
748 + $booking = array(
749 + 'dates' => array( '2027-08-24', '2027-08-25', '2027-08-26' ),
750 + 'data' => array(
751 + 'rangetime' => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' ), // Define booked time-slot.
752 + 'name' => 'John', // Simple configuration.
753 + 'secondname' => array( 'value' => 'Smith', 'type' => 'text' ), // Advanced configuration.
754 + 'email' => array( 'value' => 'John@cost.com', 'type' => 'email' ),
755 + ),
756 + 'resource_id' => 3,
757 + 'options' => array(
758 + 'save_booking_even_if_unavailable' => 1, // [0 | 1] if 1 - skip checking if the dates/times are available.
759 + ),
760 + );
761 + $booking_id = wpbc_api_booking_add_new( $booking['dates'], $booking['data'], $booking['resource_id'], $booking['options'] );
762 +
763 + // -----------------------------------------------------------------------------------------------------------------
764 + // Example #3. - Check if time slot on specific date available.
765 + // -----------------------------------------------------------------------------------------------------------------
766 + $booking = array(
767 + 'dates' => array( '2027-08-24 15:00:01', '2027-08-24 16:00:02' ),
768 + 'resource_id' => 3,
769 + 'params' => array( 'is_use_booking_recurrent_time' => false ),
770 + );
771 + $is_dates_booked = wpbc_api_is_dates_booked( $booking['dates'], $booking['resource_id'], $booking['params'] );
772 + if ( $is_dates_booked ) {
773 + // Booked.
774 + } else {
775 + // Available.
776 + }
777 +
778 + // -----------------------------------------------------------------------------------------------------------------
779 + // Example #4. - Check if dates available.
780 + // -----------------------------------------------------------------------------------------------------------------
781 + $booking = array(
782 + 'dates' => array( '2027-08-24 00:00:00', '2027-08-25 00:00:00', '2027-08-26 00:00:00' ),
783 + 'resource_id' => 3,
784 + 'params' => array( 'is_use_booking_recurrent_time' => false ),
785 + );
786 + $is_dates_booked = wpbc_api_is_dates_booked( $booking['dates'], $booking['resource_id'], $booking['params'] );
787 + if ( $is_dates_booked ) {
788 + // Booked.
789 + } else {
790 + // Available.
791 + }
792 +
793 +}