PluginProbe
Booking Calendar / 11.4.3
Booking Calendar v11.4.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 / includes / elementor-booking-form / elementor-widget-booking.php

elementor-widget-booking.php in Booking Calendar 11.4.3, at includes/elementor-booking-form/elementor-widget-booking.php

517 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * includes/elementor-booking-form/elementor-widget-booking.php
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor Booking Calendar Widget.
12 *
13 * Elementor widget for Booking Calendar plugin.
14 *
15 * @since 1.0.0
16 */
17 class WPBC_Elementor_WPBC_Booking_Form_1 extends \Elementor\Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve list widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 * @return string Widget name.
27 */
28 public function get_name(): string {
29 return 'wpbc_widget_booking_form_1';
30 }
31
32 /**
33 * Get widget title.
34 *
35 * Retrieve list widget title.
36 *
37 * @since 1.0.0
38 * @access public
39 * @return string Widget title.
40 */
41 public function get_title(): string {
42 return 'Booking Calendar'; // . ' - ' . esc_html__( 'Booking Form', 'booking' ); //.
43 }
44
45 /**
46 * Get widget icon.
47 *
48 * Retrieve list widget icon.
49 *
50 * @since 1.0.0
51 * @access public
52 * @return string Widget icon.
53 */
54 public function get_icon(): string {
55 return 'wpbc_logo_in_elementor';
56 }
57
58 /**
59 * Get widget categories.
60 *
61 * Retrieve the list of categories the list widget belongs to.
62 *
63 * @since 1.0.0
64 * @access public
65 * @return array Widget categories.
66 */
67 public function get_categories(): array {
68 return [ 'basic', 'wpbc' ];
69 }
70
71 /**
72 * Get widget keywords.
73 *
74 * Retrieve the list of keywords the list widget belongs to.
75 *
76 * @since 1.0.0
77 * @access public
78 * @return array Widget keywords.
79 */
80 public function get_keywords(): array {
81 return [ 'Booking Calendar', 'booking', 'calendar', 'bookings', 'events', 'appointments', 'booking plugin', 'wpbc' ];
82 }
83
84 /**
85 * Get custom help URL.
86 *
87 * Retrieve a URL where the user can get more information about the widget.
88 *
89 * @since 1.0.0
90 * @access public
91 * @return string Widget help URL.
92 */
93 public function get_custom_help_url(): string {
94 return 'https://wpbookingcalendar.com/contact/';
95 }
96
97 /**
98 * Get widget promotion data.
99 *
100 * Retrieve the widget promotion data.
101 *
102 * @since 1.0.0
103 * @access protected
104 * @return array Widget promotion data.
105 */
106 protected function get_upsale_data(): array {
107 return array(
108 'image' => esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ),
109 'image_alt' => esc_attr__( 'Upgrade', 'booking' ),
110 'title' => esc_html__( 'Booking Calendar Pro', 'booking' ),
111 'description' => esc_html__( 'Get the premium version of the plugin with additional features.', 'booking' ),
112 'upgrade_url' => esc_url( 'https://wpbookingcalendar.com/prices/' ),
113 'upgrade_text' => esc_html__( 'Upgrade Now', 'booking' ),
114 'condition' => ! class_exists('wpdev_bk_personal'),
115 );
116 }
117
118 /**
119 * Whether the widget requires inner wrapper.
120 *
121 * Determine whether to optimize the DOM size.
122 *
123 * @since 1.0.0
124 * @access public
125 * @return bool Whether to optimize the DOM size.
126 */
127 public function has_widget_inner_wrapper(): bool {
128 return true;
129 }
130
131 /**
132 * Whether the element returns dynamic content.
133 *
134 * Determine whether to cache the element output or not.
135 *
136 * @since 1.0.0
137 * @access protected
138 * @return bool Whether to cache the element output.
139 */
140 protected function is_dynamic_content(): bool {
141 return true;
142 }
143
144 /**
145 * Register list widget controls.
146 *
147 * Add input fields to allow the user to customize the widget settings.
148 *
149 * @since 1.0.0
150 * @access protected
151 */
152 protected function register_controls(): void {
153
154 $this->start_controls_section(
155 'wpbc_booking_interface_section',
156 [
157 'label' => esc_html__( 'Booking Interface', 'booking' ),
158 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
159 ]
160 );
161
162 $this->add_control(
163 'wpbc_booking_shortcode',
164 [
165 'type' => \Elementor\Controls_Manager::SELECT,
166 'label' => esc_html__( 'Display Mode', 'booking' ),
167 'options' => [
168 'booking' => esc_html__( 'Booking Form', 'booking' ) . ' + ' . esc_html__( 'Calendar', 'booking' ),
169 'bookingcalendar' => esc_html__( 'Availability Calendar Only', 'booking' ),
170 ],
171 'default' => 'booking',
172 'label_block' => true,
173 ]
174 );
175
176 if ( class_exists( 'wpdev_bk_personal' ) ) {
177 $this->add_control(
178 'wpbc_booking_resource_id',
179 [
180 'label' => esc_html__( 'Select Booking Resource', 'booking' ),
181 'type' => 'wpbc_resource_selection',
182 ]
183 );
184 }
185
186 $this->add_control(
187 'wpbc_booking_months_number',
188 [
189 'type' => \Elementor\Controls_Manager::SELECT,
190 'label' => esc_html__( 'Number of Visible Months', 'booking' ),
191 'options' => [
192 '1' => '1 ' . esc_html__( 'month', 'booking' ),
193 '2' => '2 ' . esc_html__( 'months', 'booking' ),
194 '3' => '3 ' . esc_html__( 'months', 'booking' ),
195 '4' => '4 ' . esc_html__( 'months', 'booking' ),
196 '5' => '5 ' . esc_html__( 'months', 'booking' ),
197 '6' => '6 ' . esc_html__( 'months', 'booking' ),
198 '7' => '7 ' . esc_html__( 'months', 'booking' ),
199 '8' => '8 ' . esc_html__( 'months', 'booking' ),
200 '9' => '9 ' . esc_html__( 'months', 'booking' ),
201 '10' => '10 ' . esc_html__( 'months', 'booking' ),
202 '11' => '11 ' . esc_html__( 'months', 'booking' ),
203 '12' => '12 ' . esc_html__( 'months', 'booking' ),
204 ],
205 'default' => '1',
206 ]
207 );
208
209
210 if ( wpbc_is_custom_forms_enabled() ) {
211 $this->add_control(
212 'wpbc_custom_form_id',
213 [
214 'label' => esc_html__( 'Use Custom Form', 'booking' ),
215 'type' => 'wpbc_custom_form_selection',
216 'condition' => [
217 'wpbc_booking_shortcode' => 'booking',
218 ],
219 ]
220 );
221 }
222
223 $this->add_control(
224 'wpbc_go_button__form_fields',
225 [
226 'type' => 'wpbc_go_button',
227 'text' => esc_html__( 'Go to Form Fields Configuration', 'booking' ),
228 'icon' => 'eicon-share-arrow',
229 'css_class' => 'e-btn-txt e-btn-txt-border',
230 'url' => esc_url( wpbc_get_settings_url() . '&tab=builder_booking_form' ),
231 'condition' => [
232 'wpbc_booking_shortcode' => 'booking',
233 ],
234 ]
235 );
236
237 $this->add_control(
238 'wpbc_booking_popup_enabled',
239 [
240 'type' => \Elementor\Controls_Manager::SWITCHER,
241 'label' => esc_html__( 'Open in Popup', 'booking' ),
242 'description' => esc_html__( 'Show a button that opens the booking form in a popup window.', 'booking' ),
243 'label_on' => esc_html__( 'Yes', 'booking' ),
244 'label_off' => esc_html__( 'No', 'booking' ),
245 'return_value' => 'yes',
246 'default' => '',
247 'condition' => [
248 'wpbc_booking_shortcode' => 'booking',
249 ],
250 ]
251 );
252
253 $this->add_control(
254 'wpbc_booking_popup_button_title',
255 [
256 'type' => \Elementor\Controls_Manager::TEXT,
257 'label' => esc_html__( 'Popup Button Title', 'booking' ),
258 'default' => esc_html__( 'Book now', 'booking' ),
259 'placeholder' => esc_html__( 'Book now', 'booking' ),
260 'label_block' => true,
261 'condition' => [
262 'wpbc_booking_shortcode' => 'booking',
263 'wpbc_booking_popup_enabled' => 'yes',
264 ],
265 ]
266 );
267
268 $this->add_control(
269 'wpbc_booking_popup_title',
270 [
271 'type' => \Elementor\Controls_Manager::TEXT,
272 'label' => esc_html__( 'Popup Title', 'booking' ),
273 'default' => esc_html__( 'Booking Form', 'booking' ),
274 'placeholder' => esc_html__( 'Booking Form', 'booking' ),
275 'label_block' => true,
276 'condition' => [
277 'wpbc_booking_shortcode' => 'booking',
278 'wpbc_booking_popup_enabled' => 'yes',
279 ],
280 ]
281 );
282
283 $this->add_control(
284 'wpbc_booking_popup_button_class',
285 [
286 'type' => \Elementor\Controls_Manager::TEXT,
287 'label' => esc_html__( 'Popup Button CSS Class', 'booking' ),
288 'default' => 'wp-element-button',
289 'placeholder' => 'wp-element-button',
290 'label_block' => true,
291 'condition' => [
292 'wpbc_booking_shortcode' => 'booking',
293 'wpbc_booking_popup_enabled' => 'yes',
294 ],
295 ]
296 );
297
298 $this->add_control(
299 'wpbc_booking_popup_modal_class',
300 [
301 'type' => \Elementor\Controls_Manager::TEXT,
302 'label' => esc_html__( 'Popup CSS Class', 'booking' ),
303 'default' => '',
304 'placeholder' => '',
305 'label_block' => true,
306 'condition' => [
307 'wpbc_booking_shortcode' => 'booking',
308 'wpbc_booking_popup_enabled' => 'yes',
309 ],
310 ]
311 );
312
313 $this->add_control(
314 'wpbc_booking_popup_size',
315 [
316 'type' => \Elementor\Controls_Manager::SELECT,
317 'label' => esc_html__( 'Popup Size', 'booking' ),
318 'options' => [
319 'lg' => esc_html__( 'Large', 'booking' ),
320 'default' => esc_html__( 'Default', 'booking' ),
321 'sm' => esc_html__( 'Small', 'booking' ),
322 ],
323 'default' => 'lg',
324 'condition' => [
325 'wpbc_booking_shortcode' => 'booking',
326 'wpbc_booking_popup_enabled' => 'yes',
327 ],
328 ]
329 );
330
331 $this->end_controls_section();
332
333 $this->start_controls_section(
334 'wpbc_booking_advanced_section',
335 [
336 'label' => esc_html__( 'Advanced', 'booking' ),
337 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
338 ]
339 );
340
341 $this->add_control(
342 'wpbc_booking_calendar_dates_start',
343 [
344 'type' => \Elementor\Controls_Manager::DATE_TIME,
345 'label' => esc_html__( 'Earliest date visible/selectable in the calendar.', 'booking' ),
346 'default' => '',
347 'label_block' => true,
348 'description' => '<strong>' . esc_html__('Optional', 'booking') . '!</strong> ' . esc_html__( 'Format: YYYY-MM-DD (e.g. 2025-07-26)', 'booking' ),
349 'picker_options' => [
350 'enableTime' => false,
351 'dateFormat' => 'Y-m-d', // '2025-07-26' format
352 ],
353 ]
354 );
355
356 $this->add_control(
357 'wpbc_booking_calendar_dates_end',
358 [
359 'type' => \Elementor\Controls_Manager::DATE_TIME,
360 'label' => esc_html__( 'Latest date visible/selectable in the calendar.', 'booking' ),
361 'default' => '',
362 'label_block' => true,
363 'description' => '<strong>' . esc_html__('Optional', 'booking') . '!</strong> ' . esc_html__( 'Format: YYYY-MM-DD (e.g. 2025-12-31)', 'booking' ),
364 'picker_options' => [
365 'enableTime' => false,
366 'dateFormat' => 'Y-m-d', // '2025-07-26' format
367 ],
368 ]
369 );
370
371 $this->add_control(
372 'wpbc_booking_calendar_startmonth',
373 [
374 'type' => \Elementor\Controls_Manager::DATE_TIME,
375 'label' => esc_html__( 'Select start month of calendar after loading.', 'booking' ),
376 'default' => '',
377 'label_block' => true,
378 'description' => '<strong>' . esc_html__('Optional', 'booking') . '!</strong> ' . esc_html__( 'Format: YYYY-MM (e.g. 2025-3)', 'booking' ),
379 'picker_options' => [
380 'enableTime' => false,
381 'dateFormat' => 'Y-m', // '2025-07-26' format
382 ],
383 ]
384 );
385 $this->add_control(
386 'wpbc_booking_calendar_dates_reset_button',
387 [
388 'type' => \Elementor\Controls_Manager::RAW_HTML,
389 'raw' => '<button type="button" class="elementor-button wpbc-reset-dates-button" style="margin-top:10px;">'.esc_html__('Reset Dates','booking').'</button>',
390 'content_classes' => 'wpbc-calendar-dates-reset-wrapper',
391 ]
392 );
393
394 $this->end_controls_section();
395
396
397 $this->start_controls_section(
398 'wpbc_theme_section',
399 [
400 'label' => esc_html__( 'Appearance & Color Themes', 'booking' ),
401 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
402 ]
403 );
404
405 $this->add_control(
406 'wpbc_calendar_skin_control',
407 [
408 'label' => esc_html__( 'Calendar Theme (Skin)', 'booking' ),
409 'type' => 'wpbc_calendar_skin_selection',
410 'frontend_available' => false,
411 'render_type' => 'none',
412 'label_block' => true,
413 ]
414 );
415
416 $this->end_controls_section();
417 }
418
419
420 /**
421 * Render list widget output on the frontend.
422 *
423 * Written in PHP and used to generate the final HTML.
424 *
425 * @since 1.0.0
426 * @access protected
427 */
428 protected function render(): void {
429
430 $shortcode_params = array();
431 $settings = $this->get_settings_for_display();
432
433 // Shortcode type.
434 $allowed_shortcodes = array( 'booking', 'bookingcalendar' );
435 $shortcode_type = in_array( $settings['wpbc_booking_shortcode'], $allowed_shortcodes, true ) ? $settings['wpbc_booking_shortcode'] : 'booking';
436
437 // Number of months.
438 $months_number = isset( $settings['wpbc_booking_months_number'] ) ? intval( $settings['wpbc_booking_months_number'] ) : 1;
439 if ( $months_number > 1 ) {
440 $shortcode_params[] = "nummonths={$months_number}";
441 }
442
443 // Booking resource (if personal version is active).
444 if ( class_exists( 'wpdev_bk_personal' ) && ! empty( $settings['wpbc_booking_resource_id'] ) && intval( $settings['wpbc_booking_resource_id'] ) > 1 ) {
445 $resource_id = intval( $settings['wpbc_booking_resource_id'] );
446 $shortcode_params[] = "resource_id={$resource_id}";
447 }
448
449 // Is custom use form ?
450 if ( ( class_exists( 'wpdev_bk_biz_m' ) ) && ! empty( $settings['wpbc_custom_form_id'] ) ) {
451 $wpbc_custom_form_id = sanitize_text_field( $settings['wpbc_custom_form_id'] );
452 if ( 'standard' !== $wpbc_custom_form_id ) {
453 $shortcode_params[] = "form_type='{$wpbc_custom_form_id}'";
454 }
455 }
456
457 // wpbc_booking_calendar_dates_start / calendar_dates_end / startmonth .
458 if ( ! empty( $settings['wpbc_booking_calendar_dates_start'] ) ) {
459 $shortcode_params[] = "calendar_dates_start='" . $settings['wpbc_booking_calendar_dates_start'] . "'";
460 }
461 if ( ! empty( $settings['wpbc_booking_calendar_dates_end'] ) ) {
462 $shortcode_params[] = "calendar_dates_end='" . $settings['wpbc_booking_calendar_dates_end'] . "'";
463 }
464 if ( ! empty( $settings['wpbc_booking_calendar_startmonth'] ) ) {
465 $shortcode_params[] = "startmonth='" . $settings['wpbc_booking_calendar_startmonth'] . "'";
466 }
467
468 if ( 'booking' === $shortcode_type && ! empty( $settings['wpbc_booking_popup_enabled'] ) && 'yes' === $settings['wpbc_booking_popup_enabled'] ) {
469 $shortcode_params[] = 'popup=1';
470
471 $popup_button_title = isset( $settings['wpbc_booking_popup_button_title'] ) ? sanitize_text_field( $settings['wpbc_booking_popup_button_title'] ) : '';
472 if ( '' !== $popup_button_title && esc_html__( 'Book now', 'booking' ) !== $popup_button_title ) {
473 $shortcode_params[] = "popup_button_title='" . str_replace( "'", '', $popup_button_title ) . "'";
474 }
475
476 $popup_title = isset( $settings['wpbc_booking_popup_title'] ) ? sanitize_text_field( $settings['wpbc_booking_popup_title'] ) : '';
477 if ( '' !== $popup_title && esc_html__( 'Booking Form', 'booking' ) !== $popup_title ) {
478 $shortcode_params[] = "popup_title='" . str_replace( "'", '', $popup_title ) . "'";
479 }
480
481 $popup_button_class = isset( $settings['wpbc_booking_popup_button_class'] ) ? sanitize_text_field( $settings['wpbc_booking_popup_button_class'] ) : '';
482 if ( '' !== $popup_button_class && 'wp-element-button' !== $popup_button_class ) {
483 $shortcode_params[] = "popup_button_class='" . str_replace( "'", '', $popup_button_class ) . "'";
484 }
485
486 $popup_modal_class = isset( $settings['wpbc_booking_popup_modal_class'] ) ? sanitize_text_field( $settings['wpbc_booking_popup_modal_class'] ) : '';
487 if ( '' !== $popup_modal_class ) {
488 $shortcode_params[] = "popup_modal_class='" . str_replace( "'", '', $popup_modal_class ) . "'";
489 }
490
491 $popup_size = isset( $settings['wpbc_booking_popup_size'] ) ? sanitize_key( $settings['wpbc_booking_popup_size'] ) : 'lg';
492 if ( ! in_array( $popup_size, array( 'lg', 'sm', 'default' ), true ) ) {
493 $popup_size = 'lg';
494 }
495 if ( 'lg' !== $popup_size ) {
496 $shortcode_params[] = "popup_size='{$popup_size}'";
497 }
498 }
499
500
501
502 // Final parameters string.
503 $shortcode_params_str = implode( ' ', $shortcode_params );
504
505 echo do_shortcode( '[' . $shortcode_type . ' ' . $shortcode_params_str . ']' );
506 }
507
508 public function get_script_depends(): array {
509 return array( 'wpbc-modal', 'wpbc-elementor-frontend-bridge' );
510 }
511
512 public function get_style_depends(): array {
513 return array( 'wpdevelop-bts', 'wpdevelop-bts-theme', 'wpbc-admin-modal-popups', 'wpbc-elementor-frontend-bridge' );
514 }
515
516 }
517