PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.6
11.8.4 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 All 204 releases
booking / includes / elementor-booking-form / wpbc-elementor.php

wpbc-elementor.php in Booking Calendar 10.15.6, at includes/elementor-booking-form/wpbc-elementor.php

330 lines 11.6 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/wpbc-elementor.php
4 */
5
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 // ---------------------------------------------------------------------------------------------------------------------
12 // == Add Widgets ==
13 // ---------------------------------------------------------------------------------------------------------------------
14
15 /**
16 * Define Booking Calendar Widget.
17 *
18 * @param $widgets_manager
19 *
20 * @return void
21 */
22 function wpbc_elementor__register_widget__booking_form( $widgets_manager ) {
23
24 require_once WPBC_PLUGIN_DIR . '/includes/elementor-booking-form/elementor-widget-booking.php';
25
26 $widgets_manager->register( new \WPBC_Elementor_WPBC_Booking_Form_1() );
27 }
28 add_action( 'elementor/widgets/register', 'wpbc_elementor__register_widget__booking_form' );
29
30 /**
31 * Add custom category for the Elementor Widgets.
32 *
33 * @param object $elements_manager - Elementor manager.
34 *
35 * @return void
36 */
37 function wpbc_elementor__add_widget_categories( $elements_manager ) {
38
39 $elements_manager->add_category( 'wpbc', [
40 'title' => 'Booking Calendar',
41 'icon' => 'wpbc_logo_in_elementor',
42 ] );
43 }
44 add_action( 'elementor/elements/categories_registered', 'wpbc_elementor__add_widget_categories' );
45
46
47 // ---------------------------------------------------------------------------------------------------------------------
48 // == JS / CSS ==
49 // ---------------------------------------------------------------------------------------------------------------------
50
51 /**
52 * Load CSS, where defined SVG icon
53 * @return void
54 */
55 function wpbc_elementor__enqueue_editor_styles() {
56
57 wp_enqueue_style( 'elementor-wpbc-editor', wpbc_plugin_url( '/includes/elementor-booking-form/_out/wpbc-elementor-editor.css' ), array(), WP_BK_VERSION_NUM );
58 }
59 add_action( 'elementor/editor/after_enqueue_styles', 'wpbc_elementor__enqueue_editor_styles' );
60
61 /**
62 *
63 * function my_plugin_register_editor_styles() {
64 * wp_register_style( 'elementor-wpbc-client-pages', wpbc_plugin_url( '/css/client.css' ), array(), WP_BK_VERSION_NUM );
65 * }
66 * add_action( 'elementor/editor/after_register_styles', 'my_plugin_register_editor_styles' );
67 */
68
69 /**
70 * Load JAVASCRIPT files.
71 *
72 * @return void
73 */
74 function wpbc_elementor__enqueue_save_calendar_skin() {
75
76 wp_enqueue_script( 'wpbc-elementor-save-skin', wpbc_plugin_url( '/includes/elementor-booking-form/_out/wpbc-elementor.js' ), array('jquery', 'elementor-editor' ), WP_BK_VERSION_NUM, true );
77
78 wp_localize_script( 'wpbc-elementor-save-skin', 'WPBC_Ajax', array(
79 'ajax_url' => admin_url( 'admin-ajax.php' ),
80 'nonce' => wp_create_nonce( 'wpbc_save_skin_nonce' ),
81 ) );
82 }
83 add_action( 'elementor/editor/after_enqueue_scripts', 'wpbc_elementor__enqueue_save_calendar_skin' );
84
85
86 // ---------------------------------------------------------------------------------------------------------------------
87 // == Controls ==
88 // ---------------------------------------------------------------------------------------------------------------------
89
90 /**
91 * Register Booking Resource Selection Control.
92 *
93 * Include control file and register control class.
94 *
95 * @since 1.0.0
96 * @param \Elementor\Controls_Manager $controls_manager Elementor controls manager.
97 * @return void
98 */
99 function wpbc_elementor__register_resource_selection_control( $controls_manager ) {
100
101 if ( class_exists( 'wpdev_bk_personal' ) ) {
102 require_once WPBC_PLUGIN_DIR . '/includes/elementor-booking-form/controls/elementor_resource_selection.php';
103
104 $controls_manager->register( new \WPBC_Elementor_Booking_Resource_Selection_Control() );
105 }
106 }
107 add_action( 'elementor/controls/register', 'wpbc_elementor__register_resource_selection_control' );
108
109 /**
110 * Register Booking Custom_Form Selection Control.
111 *
112 * Include control file and register control class.
113 *
114 * @since 1.0.0
115 * @param \Elementor\Controls_Manager $controls_manager Elementor controls manager.
116 * @return void
117 */
118 function wpbc_elementor__register_custom_form_selection_control( $controls_manager ) {
119
120 if ( wpbc_is_custom_forms_enabled() ) {
121
122 require_once WPBC_PLUGIN_DIR . '/includes/elementor-booking-form/controls/elementor_custom_form.php';
123
124 $controls_manager->register( new \WPBC_Elementor_Custom_Form_Selection_Control() );
125 }
126 }
127 add_action( 'elementor/controls/register', 'wpbc_elementor__register_custom_form_selection_control' );
128
129 /**
130 * Register Calendar Skin Selection Control.
131 *
132 * Include control file and register control class.
133 *
134 * @since 1.0.0
135 * @param \Elementor\Controls_Manager $controls_manager Elementor controls manager.
136 * @return void
137 */
138 function wpbc_elementor__register_calendar_skin_selection_control( $controls_manager ) {
139
140 require_once WPBC_PLUGIN_DIR . '/includes/elementor-booking-form/controls/elementor_calendar_skin_selection.php';
141
142 $controls_manager->register( new \WPBC_Elementor_Calendar_Skin_Selection_Control() );
143 }
144 add_action( 'elementor/controls/register', 'wpbc_elementor__register_calendar_skin_selection_control' );
145
146 /**
147 * Register Go Button
148 *
149 * Include control file and register control class.
150 *
151 * @since 1.0.0
152 * @param \Elementor\Controls_Manager $controls_manager Elementor controls manager.
153 * @return void
154 */
155 function wpbc_elementor__register_go_button_control( $controls_manager ) {
156
157 require_once WPBC_PLUGIN_DIR . '/includes/elementor-booking-form/controls/elementor_go_button.php';
158
159 $controls_manager->register( new \WPBC_Elementor_Go_Button_Control() );
160 }
161 add_action( 'elementor/controls/register', 'wpbc_elementor__register_go_button_control' );
162
163
164 // ---------------------------------------------------------------------------------------------------------------------
165 // == Ajax ==
166 // ---------------------------------------------------------------------------------------------------------------------
167
168 /**
169 * Ajax Callback.
170 *
171 * @return void
172 */
173 function wpbc_save_calendar_skin_callback() {
174
175 check_ajax_referer( 'wpbc_save_skin_nonce' );
176 $selected_calendar_skin = ( ! empty( $_POST['skin'] ) ) ? sanitize_text_field( wp_unslash( $_POST['skin'] ) ) : '';
177 $html_id = ( ! empty( $_POST['html_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['html_id'] ) ) : '';
178 $calendar_skin_to_save = '';
179
180 if ( ! empty( $selected_calendar_skin ) ) {
181
182 // FixIn: 10.3.0.5.
183 $upload_dir = wp_upload_dir();
184 $custom_user_skin_folder = $upload_dir['basedir'];
185 $custom_user_skin_url = $upload_dir['baseurl'];
186
187 $calendar_skin_to_save = str_replace( array( WPBC_PLUGIN_DIR, WPBC_PLUGIN_URL, $custom_user_skin_folder, $custom_user_skin_url ), '', $selected_calendar_skin );
188
189 // Check if this skin exist in the plugin folder.
190 if (
191 ( file_exists( WPBC_PLUGIN_DIR . $calendar_skin_to_save ) ) ||
192 ( file_exists( $custom_user_skin_folder . $calendar_skin_to_save ) )
193 ) {
194 update_bk_option( 'booking_skin', $calendar_skin_to_save );
195 }
196 }
197
198
199 if ( empty( $calendar_skin_to_save ) ) {
200 wp_send_json_error( 'No skin provided.' );
201 }
202
203 wp_send_json_success(
204 array(
205 'html_id' => $html_id,
206 'url_full' => $selected_calendar_skin,
207 'url_saved' => $calendar_skin_to_save,
208 )
209 );
210 }
211 add_action('wp_ajax_wpbc_save_calendar_skin', 'wpbc_save_calendar_skin_callback');
212
213
214 // ---------------------------------------------------------------------------------------------------------------------
215 // == Warning ==
216 // ---------------------------------------------------------------------------------------------------------------------
217 function wpbc_elementor_warn_text_widget_shortcodes( $widget_content, $widget ) {
218
219 if ( ! is_object( $widget ) || ! method_exists( $widget, 'get_name' ) ) {
220 return $widget_content;
221 }
222
223 // Only Text Editor widget sanitizes with wp_kses_post().
224 if ( 'text-editor' !== $widget->get_name() ) {
225 return $widget_content;
226 }
227
228 $settings = array();
229 if ( method_exists( $widget, 'get_settings_for_display' ) ) {
230 $settings = $widget->get_settings_for_display();
231 }
232
233 $raw = ( isset( $settings['editor'] ) ) ? (string) $settings['editor'] : '';
234 if ( '' === $raw ) {
235 return $widget_content;
236 }
237
238 // Detect Booking Calendar shortcodes in the raw editor content.
239 if ( ! preg_match( '/\[(booking|bookingcalendar|bookingform|bookingselect|bookingtimeline)\b/i', $raw ) ) {
240 return $widget_content;
241 }
242
243 // Show warning to admins and in Elementor editor mode.
244 $show_warning = false;
245
246 if ( function_exists( 'current_user_can' ) && current_user_can( 'manage_options' ) ) {
247 $show_warning = true;
248 }
249
250 if ( class_exists( '\Elementor\Plugin' ) && isset( \Elementor\Plugin::$instance->editor ) ) {
251 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
252 $show_warning = true;
253 }
254 }
255
256 if ( ! $show_warning ) {
257 // For visitors, either return original (even if broken),
258 // or replace shortcode area with a softer public message.
259 return $widget_content;
260 }
261
262 // Prepend warning before the sanitized output.
263 $widget_content = wpbc_elementor_build_text_widget_warning() . $widget_content;
264
265 return $widget_content;
266 }
267 add_filter( 'elementor/widget/render_content', 'wpbc_elementor_warn_text_widget_shortcodes', 20, 2 );
268
269
270 /**
271 * Build Elementor Text Editor widget warning for Booking Calendar shortcodes.
272 *
273 * @param string $faq_url
274 *
275 * @return string HTML
276 */
277 function wpbc_elementor_build_text_widget_warning( $faq_url = '' ) {
278
279 $faq_url = ( '' !== $faq_url ) ? $faq_url : 'https://wpbookingcalendar.com/faq/elementor-3-33-5-booking-calendar/';
280
281 $warning = '<div class="wpbc-elementor-warning" role="alert" style="border:1px solid #d63638;padding:12px;margin:10px 0;background:#fff;">';
282 $warning .= '<strong>' . esc_html__( 'Booking Calendar Notice', 'booking' ) . '</strong>';
283
284 $warning .= '<p style="margin:8px 0 0 0;">' .
285 esc_html( 'This Booking Calendar shortcode is placed inside an Elementor Text Editor widget.' ) .
286 '</p>';
287
288 $warning .= '<p style="margin:8px 0 0 0;">' .
289 esc_html( 'Since Elementor 3.33.5, the Elementor Text Editor widget can strip the booking form markup, which prevents the calendar and form from working correctly.' ) .
290 '</p>';
291
292 $warning .= '<p style="margin:8px 0 0 0;">' . esc_html__( 'Please use one of these instead:', 'booking' ) . '</p>';
293
294 $warning .= '<ul style="margin:8px 0 0 18px;">';
295 $warning .= '<li>' . esc_html( 'Elementor Shortcode widget' ) . '</li>';
296 $warning .= '<li>' . esc_html( 'The native Booking Calendar Elementor widget' ) . '</li>';
297 $warning .= '<li>' .
298 esc_html__( 'More details in the FAQ:', 'booking' ) . ' ' .
299 '<a href="' . esc_url( $faq_url ) . '" target="_blank" rel="noopener noreferrer">' . esc_html( $faq_url ) . '</a>' .
300 '</li>';
301 $warning .= '</ul>';
302
303 $warning .= '</div>';
304
305 return $warning;
306 }
307
308
309 add_action( 'elementor/frontend/after_register_scripts', function() {
310 wp_register_script( 'wpbc-elementor-frontend-bridge', wpbc_plugin_url( '/includes/elementor-booking-form/_out/wpbc-elementor-frontend-bridge.js' ), array( 'jquery' ), WP_BK_VERSION_NUM, true );
311 } );
312
313 add_action( 'elementor/frontend/after_register_styles', function() {
314 wp_register_style( 'wpbc-elementor-frontend-bridge', wpbc_plugin_url( '/includes/elementor-booking-form/_out/wpbc-elementor-frontend-bridge.css' ), array(), WP_BK_VERSION_NUM );
315 } );
316
317 add_filter( 'wpbc_force_client_assets', function( $force ) {
318
319 if ( $force ) {
320 return true;
321 }
322
323 // If Elementor widget exists on the page, Elementor enqueues the bridge handle.
324 if ( wp_script_is( 'wpbc-elementor-frontend-bridge', 'enqueued' ) || wp_style_is( 'wpbc-elementor-frontend-bridge', 'enqueued' ) ) {
325 return true;
326 }
327
328 return false;
329 } );
330