| 1 |
<?php |
| 2 |
/** |
| 3 |
* Booking Form Builder - Preview Service (Option A). |
| 4 |
* |
| 5 |
* - Creates and manages a single private "Booking Form Preview" page. |
| 6 |
* - Handles AJAX to store a temporary snapshot of the current BFB structure. |
| 7 |
* - Builds a secure preview URL for that page and injects the real booking shortcode. |
| 8 |
* - Optionally exposes a filter hook to let BFB override form structure from snapshot. |
| 9 |
* |
| 10 |
* @package Booking Calendar |
| 11 |
* @subpackage Form Builder |
| 12 |
* |
| 13 |
* @author wpdevelop |
| 14 |
* @version 1.0.0 |
| 15 |
* @since 10.14.0 |
| 16 |
* @file: ../includes/page-form-builder/preview/bfb-preview.php |
| 17 |
*/ |
| 18 |
|
| 19 |
/** |
| 20 |
== Preview pipeline == |
| 21 |
When click on update Preview, the client sends AJAX: |
| 22 |
action = WPBC_AJX_BFB_SAVE_FORM_CONFIG |
| 23 |
status = preview |
| 24 |
structure = JSON.stringify( builder_structure ) |
| 25 |
settings = JSON.stringify( form_settings ) (options + css_vars) |
| 26 |
and then either: |
| 27 |
Advanced Mode text (if chosen / auto+dirty), OR |
| 28 |
Builder export by calling WPBC_BFB_Exporter.export_all(structure, export_options) and sending: |
| 29 |
advanced_form |
| 30 |
content_form (from fields_data) |
| 31 |
Server stores it temporarily in a transient via create_preview_session(): |
| 32 |
structure |
| 33 |
advanced_form |
| 34 |
content_form |
| 35 |
Then it returns a secure URL, and the iframe loads that page. |
| 36 |
On the preview page request, your service injects the booking shortcode and applies filters: |
| 37 |
wpbc_bfb_get_form_structure |
| 38 |
wpbc_bfb_get_form_advanced_form |
| 39 |
wpbc_bfb_get_form_content_form |
| 40 |
*/ |
| 41 |
|
| 42 |
if ( ! defined( 'ABSPATH' ) ) { |
| 43 |
exit; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Service for handling BFB preview page and snapshots. |
| 48 |
*/ |
| 49 |
class WPBC_BFB_Preview_Service { |
| 50 |
|
| 51 |
/** |
| 52 |
* Singleton instance. |
| 53 |
* |
| 54 |
* @var WPBC_BFB_Preview_Service|null |
| 55 |
*/ |
| 56 |
protected static $instance = null; |
| 57 |
|
| 58 |
/** |
| 59 |
* Currently active preview data for this request (if any). |
| 60 |
* |
| 61 |
* @var array|null |
| 62 |
*/ |
| 63 |
protected $current_preview_data = null; |
| 64 |
|
| 65 |
/** |
| 66 |
* Get singleton instance. |
| 67 |
* |
| 68 |
* @return WPBC_BFB_Preview_Service |
| 69 |
*/ |
| 70 |
public static function get_instance() { |
| 71 |
if ( null === self::$instance ) { |
| 72 |
self::$instance = new self(); |
| 73 |
} |
| 74 |
|
| 75 |
return self::$instance; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Constructor (private, use get_instance()). |
| 80 |
*/ |
| 81 |
private function __construct() { |
| 82 |
|
| 83 |
// Ensure preview page exists (lazy). |
| 84 |
add_action( 'init', array( $this, 'ensure_preview_page_exists' ), 20 ); |
| 85 |
|
| 86 |
// Re-apply template after switching theme. |
| 87 |
add_action( 'after_switch_theme', array( $this, 'ensure_preview_page_template' ), 20 ); |
| 88 |
|
| 89 |
// Inject preview content into preview page. |
| 90 |
add_filter( 'the_content', array( $this, 'filter_the_content_for_preview' ) ); |
| 91 |
|
| 92 |
// Optionally hide preview page from Pages list in admin. |
| 93 |
// add_action( 'pre_get_posts', array( $this, 'hide_preview_page_in_admin_list' ) ); |
| 94 |
|
| 95 |
// Enqueue JS/CSS on Builder admin page. |
| 96 |
add_action( 'wpbc_enqueue_js_files_on_page_done', array( $this, 'enqueue_js_files' ) ); |
| 97 |
|
| 98 |
// Hide admin bar in preview iframe only. |
| 99 |
add_action( 'after_setup_theme', array( $this, 'maybe_hide_admin_bar_for_preview' ) ); |
| 100 |
|
| 101 |
add_filter( 'wp_robots', array( $this, 'add_noindex_to_preview_page' ), 99 ); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Ensure that the preview page exists and is stored in options. |
| 106 |
* |
| 107 |
* This runs on 'init' and can also be called manually. |
| 108 |
* |
| 109 |
* @return int|false Page ID on success, false on failure. |
| 110 |
*/ |
| 111 |
public function ensure_preview_page_exists() { |
| 112 |
|
| 113 |
$option_key = $this->get_page_option_key(); |
| 114 |
$page_id = (int) get_option( $option_key ); |
| 115 |
|
| 116 |
if ( $page_id > 0 ) { |
| 117 |
|
| 118 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 119 |
if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) && ( isset( $_POST['action'] ) ) && ( 'WPBC_AJX_BFB_SAVE_FORM_CONFIG' === $_POST['action'] ) ) { |
| 120 |
// Probably saving preview before making this preview, so we can check about ensure preview page. |
| 121 |
} else { |
| 122 |
return false; |
| 123 |
} |
| 124 |
|
| 125 |
$page = get_post( $page_id ); |
| 126 |
|
| 127 |
if ( $page instanceof WP_Post && 'page' === $page->post_type ) { |
| 128 |
|
| 129 |
// Ensure it uses full-width template (if available). |
| 130 |
$this->ensure_preview_page_template(); |
| 131 |
|
| 132 |
return $page_id; |
| 133 |
} |
| 134 |
|
| 135 |
delete_option( $option_key ); |
| 136 |
} |
| 137 |
|
| 138 |
$page_id = $this->create_preview_page(); |
| 139 |
|
| 140 |
if ( $page_id > 0 ) { |
| 141 |
update_option( $option_key, $page_id ); |
| 142 |
|
| 143 |
// Set full-width template right after creation. |
| 144 |
$this->ensure_preview_page_template(); |
| 145 |
|
| 146 |
return $page_id; |
| 147 |
} |
| 148 |
|
| 149 |
return false; |
| 150 |
} |
| 151 |
|
| 152 |
public function add_noindex_to_preview_page( $robots ) { |
| 153 |
|
| 154 |
if ( ! $this->is_main_query_page() ) { |
| 155 |
return $robots; |
| 156 |
} |
| 157 |
|
| 158 |
$page_id = (int) get_queried_object_id(); |
| 159 |
if ( $page_id !== (int) $this->get_preview_page_id() ) { |
| 160 |
return $robots; |
| 161 |
} |
| 162 |
|
| 163 |
$robots['noindex'] = true; |
| 164 |
$robots['nofollow'] = true; |
| 165 |
$robots['noarchive'] = true; |
| 166 |
|
| 167 |
return $robots; |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Check the main query directly without calling a conditional query tag too early. |
| 172 |
* |
| 173 |
* @return bool |
| 174 |
*/ |
| 175 |
protected function is_main_query_page() { |
| 176 |
return isset( $GLOBALS['wp_query'] ) |
| 177 |
&& ( $GLOBALS['wp_query'] instanceof WP_Query ) |
| 178 |
&& $GLOBALS['wp_query']->is_page(); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Resolve capability used for preview / Builder access. |
| 183 |
* |
| 184 |
* Uses wpbc_bfb_get_manage_cap() when available, falls back to manage_options. |
| 185 |
* |
| 186 |
* @return string |
| 187 |
*/ |
| 188 |
protected function get_manage_cap() { |
| 189 |
if ( function_exists( 'wpbc_bfb_get_manage_cap' ) ) { |
| 190 |
return wpbc_bfb_get_manage_cap(); |
| 191 |
} |
| 192 |
|
| 193 |
return 'manage_options'; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Check if current request is a BFB preview request. |
| 198 |
* |
| 199 |
* @return bool |
| 200 |
*/ |
| 201 |
protected function is_preview_request() { |
| 202 |
|
| 203 |
// Quick GET check (works before main query is parsed). |
| 204 |
if ( isset( $_GET['wpbc_bfb_preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 205 |
return true; |
| 206 |
} |
| 207 |
|
| 208 |
// Fallback for places where query vars are already set. |
| 209 |
$is_preview = get_query_var( 'wpbc_bfb_preview' ); |
| 210 |
|
| 211 |
return ! empty( $is_preview ); |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Hide admin toolbar on front-end preview requests. |
| 216 |
* |
| 217 |
* This affects ONLY the preview page loaded in the iframe. |
| 218 |
*/ |
| 219 |
public function maybe_hide_admin_bar_for_preview() { |
| 220 |
|
| 221 |
// Do not affect wp-admin. |
| 222 |
if ( is_admin() ) { |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
if ( ! $this->is_preview_request() ) { |
| 227 |
return; |
| 228 |
} |
| 229 |
|
| 230 |
$cap = $this->get_manage_cap(); |
| 231 |
|
| 232 |
// Optionally limit to users who can see this preview anyway. |
| 233 |
if ( ! is_user_logged_in() || ! current_user_can( $cap ) ) { |
| 234 |
return; |
| 235 |
} |
| 236 |
|
| 237 |
// Disable admin bar for this request only. |
| 238 |
show_admin_bar( false ); |
| 239 |
} |
| 240 |
|
| 241 |
public function enqueue_js_files() { |
| 242 |
if ( ! is_admin() ) { |
| 243 |
return; |
| 244 |
} |
| 245 |
// BFB preview script on the Builder admin page. |
| 246 |
wp_enqueue_script( |
| 247 |
'wpbc-bfb-preview', |
| 248 |
wpbc_plugin_url( '/includes/page-form-builder/preview/_out/bfb-preview.js' ), |
| 249 |
array( 'wpbc-bfb_builder' ), |
| 250 |
WP_BK_VERSION_NUM, |
| 251 |
true |
| 252 |
); |
| 253 |
wp_enqueue_style( |
| 254 |
'wpbc-bfb-preview-mode', |
| 255 |
wpbc_plugin_url( '/includes/page-form-builder/preview/_out/bfb-preview.css' ), |
| 256 |
array(), |
| 257 |
WP_BK_VERSION_NUM |
| 258 |
); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Return the option key where preview page ID is stored. |
| 263 |
* |
| 264 |
* @return string |
| 265 |
*/ |
| 266 |
protected function get_page_option_key() { |
| 267 |
return 'wpbc_bfb_preview_page_id'; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Create the private "Booking Form Preview" page. |
| 272 |
* |
| 273 |
* @return int|false Page ID on success, false on failure. |
| 274 |
*/ |
| 275 |
protected function create_preview_page() { |
| 276 |
|
| 277 |
$page_id = wpbc_bfb_activation__create_preview_page_raw(); |
| 278 |
return $page_id; |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Get the preview page ID (ensures it exists). |
| 283 |
* |
| 284 |
* @return int|false |
| 285 |
*/ |
| 286 |
public function get_preview_page_id() { |
| 287 |
$option_key = $this->get_page_option_key(); |
| 288 |
$page_id = (int) get_option( $option_key ); |
| 289 |
|
| 290 |
if ( $page_id > 0 ) { |
| 291 |
return $page_id; |
| 292 |
} |
| 293 |
|
| 294 |
return $this->ensure_preview_page_exists(); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
/** |
| 299 |
* Build transient key for storing preview snapshot. |
| 300 |
* |
| 301 |
* @param int $user_id Current user ID. |
| 302 |
* @param string $token Random token. |
| 303 |
* @param int $form_id Booking form ID. |
| 304 |
* |
| 305 |
* @return string |
| 306 |
*/ |
| 307 |
protected function get_transient_key( $user_id, $token, $form_id ) { |
| 308 |
|
| 309 |
$user_id = (int) $user_id; |
| 310 |
$form_id = (int) $form_id; |
| 311 |
|
| 312 |
return 'wpbc_bfb_preview_' . $user_id . '_' . $form_id . '_' . sanitize_key( $token ); |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Try to load preview data from current request (front-end). |
| 317 |
* |
| 318 |
* @return array|null |
| 319 |
*/ |
| 320 |
protected function get_preview_data_from_request() { |
| 321 |
|
| 322 |
if ( null !== $this->current_preview_data ) { |
| 323 |
return $this->current_preview_data; |
| 324 |
} |
| 325 |
|
| 326 |
// Check query flag. |
| 327 |
$is_preview = get_query_var( 'wpbc_bfb_preview' ); |
| 328 |
|
| 329 |
if ( empty( $is_preview ) && ! isset( $_GET['wpbc_bfb_preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 330 |
return null; |
| 331 |
} |
| 332 |
|
| 333 |
$cap = $this->get_manage_cap(); |
| 334 |
|
| 335 |
if ( ! is_user_logged_in() || ! current_user_can( $cap ) ) { |
| 336 |
return null; |
| 337 |
} |
| 338 |
|
| 339 |
$token = get_query_var( 'wpbc_bfb_preview_token' ); |
| 340 |
$form_id = absint( get_query_var( 'wpbc_bfb_preview_form_id' ) ); |
| 341 |
|
| 342 |
if ( empty( $token ) ) { |
| 343 |
$token = isset( $_GET['wpbc_bfb_preview_token'] ) ? sanitize_text_field( wp_unslash( $_GET['wpbc_bfb_preview_token'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 344 |
} |
| 345 |
|
| 346 |
if ( empty( $form_id ) ) { |
| 347 |
$form_id = isset( $_GET['wpbc_bfb_preview_form_id'] ) ? absint( wp_unslash( $_GET['wpbc_bfb_preview_form_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 348 |
} |
| 349 |
|
| 350 |
$nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 351 |
|
| 352 |
if ( empty( $token ) || empty( $form_id ) ) { |
| 353 |
return null; |
| 354 |
} |
| 355 |
|
| 356 |
if ( ! wp_verify_nonce( $nonce, 'wpbc_bfb_preview_' . $token ) ) { |
| 357 |
return null; |
| 358 |
} |
| 359 |
|
| 360 |
$user_id = wpbc_get_current_user_id(); |
| 361 |
|
| 362 |
if ( $user_id <= 0 ) { |
| 363 |
return null; |
| 364 |
} |
| 365 |
|
| 366 |
$transient_key = $this->get_transient_key( $user_id, $token, $form_id ); |
| 367 |
$data = get_transient( $transient_key ); |
| 368 |
|
| 369 |
if ( empty( $data ) ) { |
| 370 |
return null; |
| 371 |
} |
| 372 |
|
| 373 |
$has_structure = ( ! empty( $data['structure'] ) && is_array( $data['structure'] ) ); |
| 374 |
$has_advanced = ( ! empty( $data['advanced_form'] ) || ! empty( $data['content_form'] ) ); |
| 375 |
|
| 376 |
if ( ! $has_structure && ! $has_advanced ) { |
| 377 |
return null; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
$this->current_preview_data = $data; |
| 382 |
|
| 383 |
return $this->current_preview_data; |
| 384 |
} |
| 385 |
|
| 386 |
// ----------------------------------------------------------------------------------------------------------------- |
| 387 |
|
| 388 |
/** |
| 389 |
* Ensure preview page uses a "full width" template (if the current theme provides one). |
| 390 |
* |
| 391 |
* WordPress stores selected templates in post meta: _wp_page_template. :contentReference[oaicite:1]{index=1} |
| 392 |
* |
| 393 |
* Developers can hard-force a template via: |
| 394 |
* apply_filters( 'wpbc_bfb_preview_page_template', $template, $page_id ) |
| 395 |
* |
| 396 |
* - Classic theme template value: 'templates/full-width.php' |
| 397 |
* - Block theme template value: 'page-no-title' (template slug) |
| 398 |
* |
| 399 |
* @return void |
| 400 |
*/ |
| 401 |
public function ensure_preview_page_template() { |
| 402 |
|
| 403 |
$page_id = (int) $this->get_preview_page_id(); |
| 404 |
if ( $page_id <= 0 ) { |
| 405 |
return; |
| 406 |
} |
| 407 |
|
| 408 |
// If already set and valid, do nothing (fast path). |
| 409 |
$current = (string) get_post_meta( $page_id, '_wp_page_template', true ); |
| 410 |
if ( $this->is_preview_template_value_valid( $current ) ) { |
| 411 |
return; |
| 412 |
} |
| 413 |
|
| 414 |
$template = $this->detect_full_width_template_value(); |
| 415 |
|
| 416 |
/** |
| 417 |
* Force/override template for preview page. |
| 418 |
* |
| 419 |
* Return values: |
| 420 |
* - '' or 'default' => keep theme default |
| 421 |
* - classic: 'templates/full-width.php' |
| 422 |
* - block: 'page-no-title' (slug) |
| 423 |
*/ |
| 424 |
$template = apply_filters( 'wpbc_bfb_preview_page_template', $template, $page_id ); |
| 425 |
|
| 426 |
$template = (string) $template; |
| 427 |
$template = trim( $template ); |
| 428 |
|
| 429 |
if ( '' === $template || 'default' === $template ) { |
| 430 |
// Use default template. |
| 431 |
delete_post_meta( $page_id, '_wp_page_template' ); |
| 432 |
|
| 433 |
return; |
| 434 |
} |
| 435 |
|
| 436 |
// Store chosen template. |
| 437 |
update_post_meta( $page_id, '_wp_page_template', $template ); |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* Validate existing _wp_page_template meta value for classic themes. |
| 442 |
* For block themes we can’t reliably "locate" the template file here, so we accept non-empty values. |
| 443 |
* |
| 444 |
* @param string $template_value Existing _wp_page_template meta value. |
| 445 |
* |
| 446 |
* @return bool |
| 447 |
*/ |
| 448 |
protected function is_preview_template_value_valid( $template_value ) { |
| 449 |
|
| 450 |
$template_value = (string) $template_value; |
| 451 |
$template_value = trim( $template_value ); |
| 452 |
|
| 453 |
if ( '' === $template_value || 'default' === $template_value ) { |
| 454 |
return false; |
| 455 |
} |
| 456 |
|
| 457 |
// Classic themes: validate that file exists in theme. |
| 458 |
if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { |
| 459 |
return true; |
| 460 |
} |
| 461 |
|
| 462 |
$located = locate_template( array( $template_value ), false, false ); |
| 463 |
|
| 464 |
return ( ! empty( $located ) ); |
| 465 |
} |
| 466 |
|
| 467 |
/** |
| 468 |
* Detect a full-width template value for current theme. |
| 469 |
* |
| 470 |
* @return string Template value for _wp_page_template, or '' if none found. |
| 471 |
*/ |
| 472 |
protected function detect_full_width_template_value() { |
| 473 |
|
| 474 |
// Block themes: try to find a block template slug. |
| 475 |
if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() && function_exists( 'get_block_templates' ) ) { |
| 476 |
$slug = $this->detect_block_theme_full_width_slug(); |
| 477 |
if ( '' !== $slug ) { |
| 478 |
return $slug; |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
// Classic themes: try registered page templates first. |
| 483 |
$file = $this->detect_classic_theme_full_width_file(); |
| 484 |
if ( '' !== $file ) { |
| 485 |
return $file; |
| 486 |
} |
| 487 |
|
| 488 |
return ''; |
| 489 |
} |
| 490 |
|
| 491 |
/** |
| 492 |
* Try to detect a "full width" template slug in block themes. |
| 493 |
* |
| 494 |
* @return string |
| 495 |
*/ |
| 496 |
protected function detect_block_theme_full_width_slug() { |
| 497 |
|
| 498 |
$best_slug = ''; |
| 499 |
$best_score = 0; |
| 500 |
|
| 501 |
$templates = get_block_templates( array( |
| 502 |
'post_type' => 'page', |
| 503 |
), 'wp_template' ); |
| 504 |
|
| 505 |
if ( empty( $templates ) || ! is_array( $templates ) ) { |
| 506 |
return ''; |
| 507 |
} |
| 508 |
|
| 509 |
foreach ( $templates as $tpl ) { |
| 510 |
|
| 511 |
$title = ''; |
| 512 |
$slug = ''; |
| 513 |
|
| 514 |
if ( is_object( $tpl ) ) { |
| 515 |
$title = isset( $tpl->title ) ? (string) $tpl->title : ''; |
| 516 |
$slug = isset( $tpl->slug ) ? (string) $tpl->slug : ''; |
| 517 |
} |
| 518 |
|
| 519 |
$score = $this->score_full_width_candidate( $title . ' ' . $slug ); |
| 520 |
|
| 521 |
if ( $score > $best_score && '' !== $slug ) { |
| 522 |
$best_score = $score; |
| 523 |
$best_slug = $slug; |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
return ( $best_score >= 60 ) ? $best_slug : ''; |
| 528 |
} |
| 529 |
|
| 530 |
/** |
| 531 |
* Try to detect a "full width" template file in classic themes. |
| 532 |
* |
| 533 |
* @return string |
| 534 |
*/ |
| 535 |
protected function detect_classic_theme_full_width_file() { |
| 536 |
|
| 537 |
$theme = wp_get_theme(); |
| 538 |
$templates = $theme->get_page_templates( null, 'page' ); // array( 'Name' => 'file.php' ). |
| 539 |
|
| 540 |
$best_file = ''; |
| 541 |
$best_score = 0; |
| 542 |
|
| 543 |
if ( ! empty( $templates ) && is_array( $templates ) ) { |
| 544 |
foreach ( $templates as $name => $file ) { |
| 545 |
$score = $this->score_full_width_candidate( $name . ' ' . $file ); |
| 546 |
if ( $score > $best_score && ! empty( $file ) ) { |
| 547 |
$best_score = $score; |
| 548 |
$best_file = (string) $file; |
| 549 |
} |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
// Accept strong match from registered templates. |
| 554 |
if ( $best_score >= 60 && '' !== $best_file ) { |
| 555 |
$located = locate_template( array( $best_file ), false, false ); |
| 556 |
if ( ! empty( $located ) ) { |
| 557 |
return $best_file; |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
// Fallback: common filenames (theme-dependent). |
| 562 |
$candidates = array( |
| 563 |
'page-templates/full-width.php', |
| 564 |
'page-templates/fullwidth.php', |
| 565 |
'templates/full-width.php', |
| 566 |
'templates/fullwidth.php', |
| 567 |
'full-width.php', |
| 568 |
'fullwidth.php', |
| 569 |
'page-no-sidebar.php', |
| 570 |
'page-nosidebar.php', |
| 571 |
); |
| 572 |
|
| 573 |
foreach ( $candidates as $candidate ) { |
| 574 |
$located = locate_template( array( $candidate ), false, false ); |
| 575 |
if ( ! empty( $located ) ) { |
| 576 |
return $candidate; |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
return ''; |
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* Score a candidate (template name/slug/file) as "full width". |
| 585 |
* |
| 586 |
* @param string $haystack Text to score. |
| 587 |
* |
| 588 |
* @return int |
| 589 |
*/ |
| 590 |
protected function score_full_width_candidate( $haystack ) { |
| 591 |
|
| 592 |
$h = strtolower( (string) $haystack ); |
| 593 |
$s = 0; |
| 594 |
|
| 595 |
if ( false !== strpos( $h, 'full' ) && false !== strpos( $h, 'width' ) ) { |
| 596 |
$s += 100; |
| 597 |
} |
| 598 |
if ( false !== strpos( $h, 'no' ) && false !== strpos( $h, 'sidebar' ) ) { |
| 599 |
$s += 95; |
| 600 |
} |
| 601 |
// My theme exception for local test server. |
| 602 |
if ( ( isset( $_SERVER['HTTP_HOST'] ) && ( 'beta' === sanitize_key( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) ) && ( false !== strpos( $h, 'no-title' ) ) ) { |
| 603 |
$s += 61; |
| 604 |
} |
| 605 |
if ( false !== strpos( $h, 'wide' ) ) { |
| 606 |
$s += 60; |
| 607 |
} |
| 608 |
if ( false !== strpos( $h, 'canvas' ) || false !== strpos( $h, 'blank' ) ) { |
| 609 |
$s += 40; |
| 610 |
} |
| 611 |
if ( false !== strpos( $h, 'elementor' ) && false !== strpos( $h, 'full' ) ) { |
| 612 |
$s += 30; |
| 613 |
} |
| 614 |
|
| 615 |
return $s; |
| 616 |
} |
| 617 |
// ----------------------------------------------------------------------------------------------------------------- |
| 618 |
|
| 619 |
/** |
| 620 |
* Filter "the_content" to inject the real booking form into the preview page. |
| 621 |
* |
| 622 |
* Note: |
| 623 |
* - This is where we run the actual booking shortcode. |
| 624 |
* - The theme (classic or block) wraps this content as usual. |
| 625 |
* |
| 626 |
* @param string $content Original page content. |
| 627 |
* |
| 628 |
* @return string |
| 629 |
*/ |
| 630 |
public function filter_the_content_for_preview( $content ) { |
| 631 |
|
| 632 |
if ( ! $this->is_main_query_page() ) { |
| 633 |
return $content; |
| 634 |
} |
| 635 |
|
| 636 |
$page_id = get_the_ID(); |
| 637 |
$preview_page_id = $this->get_preview_page_id(); |
| 638 |
|
| 639 |
if ( $preview_page_id <= 0 || (int) $page_id !== (int) $preview_page_id ) { |
| 640 |
return $content; |
| 641 |
} |
| 642 |
|
| 643 |
$preview_data = $this->get_preview_data_from_request(); |
| 644 |
|
| 645 |
if ( empty( $preview_data ) ) { |
| 646 |
// No active preview snapshot, show a simple message. |
| 647 |
return '<p>' . esc_html__( 'This is a booking form preview page. Please refresh the preview from the Builder.', 'booking' ) . '</p>'; |
| 648 |
} |
| 649 |
|
| 650 |
// Safety: disable caching for this request. |
| 651 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound |
| 652 |
if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); } |
| 653 |
|
| 654 |
nocache_headers(); |
| 655 |
|
| 656 |
// Store preview data for this request so other hooks can access it. |
| 657 |
$this->current_preview_data = $preview_data; |
| 658 |
|
| 659 |
// Optional: expose a filter so BFB structure loader can override structure per preview. |
| 660 |
// Your wpbc_bfb_get_form_structure() can apply this filter when resolving structure. |
| 661 |
add_filter( 'wpbc_bfb_get_form_structure', array( $this, 'filter_form_structure_for_preview' ), 10, 2 ); |
| 662 |
add_filter( 'wpbc_bfb_get_form_advanced_form', array( $this, 'filter_form_advanced_form_for_preview' ), 10, 2 ); |
| 663 |
add_filter( 'wpbc_bfb_get_form_content_form', array( $this, 'filter_form_content_form_for_preview' ), 10, 2 ); |
| 664 |
|
| 665 |
$resource_id = WPBC_FE_Attr_Postprocessor::get_default_booking_resource_id(); |
| 666 |
|
| 667 |
$form_name = isset( $preview_data['form_name'] ) ? sanitize_text_field( wp_unslash( $preview_data['form_name'] ) ) : 'standard'; |
| 668 |
if ( '' === $form_name ) { |
| 669 |
$form_name = 'standard'; |
| 670 |
} |
| 671 |
|
| 672 |
$shortcode = '[booking resource_id="' . esc_attr( $resource_id ) . '" form_type="' . esc_attr( $form_name ) . '" form_status="preview"]'; |
| 673 |
|
| 674 |
$preview_html = do_shortcode( $shortcode ); |
| 675 |
|
| 676 |
return $this->filter_wrapped_html_for_preview_form_style( $preview_html, array(), $resource_id, $form_name ); |
| 677 |
} |
| 678 |
|
| 679 |
public function filter_form_advanced_form_for_preview( $advanced_form, $form_id ) { |
| 680 |
|
| 681 |
if ( empty( $this->current_preview_data ) ) { |
| 682 |
return $advanced_form; |
| 683 |
} |
| 684 |
|
| 685 |
if ( (int) $form_id !== (int) $this->current_preview_data['form_id'] ) { |
| 686 |
return $advanced_form; |
| 687 |
} |
| 688 |
|
| 689 |
if ( isset( $this->current_preview_data['advanced_form'] ) ) { |
| 690 |
return (string) $this->current_preview_data['advanced_form']; |
| 691 |
} |
| 692 |
|
| 693 |
return $advanced_form; |
| 694 |
} |
| 695 |
|
| 696 |
public function filter_form_content_form_for_preview( $content_form, $form_id ) { |
| 697 |
|
| 698 |
if ( empty( $this->current_preview_data ) ) { |
| 699 |
return $content_form; |
| 700 |
} |
| 701 |
|
| 702 |
if ( (int) $form_id !== (int) $this->current_preview_data['form_id'] ) { |
| 703 |
return $content_form; |
| 704 |
} |
| 705 |
|
| 706 |
if ( isset( $this->current_preview_data['content_form'] ) ) { |
| 707 |
return (string) $this->current_preview_data['content_form']; |
| 708 |
} |
| 709 |
|
| 710 |
return $content_form; |
| 711 |
} |
| 712 |
|
| 713 |
/** |
| 714 |
* Filter that allows BFB structure loader to receive snapshot for preview. |
| 715 |
* |
| 716 |
* Usage example in your loader: |
| 717 |
* $structure = apply_filters( 'wpbc_bfb_get_form_structure', $structure, $form_id ); |
| 718 |
* |
| 719 |
* @param array $structure Default structure loaded from DB. |
| 720 |
* @param int $form_id Booking form ID. |
| 721 |
* |
| 722 |
* @return array |
| 723 |
*/ |
| 724 |
public function filter_form_structure_for_preview( $structure, $form_id ) { |
| 725 |
|
| 726 |
if ( empty( $this->current_preview_data ) ) { |
| 727 |
return $structure; |
| 728 |
} |
| 729 |
|
| 730 |
if ( (int) $form_id !== (int) $this->current_preview_data['form_id'] ) { |
| 731 |
return $structure; |
| 732 |
} |
| 733 |
|
| 734 |
if ( empty( $this->current_preview_data['structure'] ) || ! is_array( $this->current_preview_data['structure'] ) ) { |
| 735 |
return $structure; |
| 736 |
} |
| 737 |
|
| 738 |
return $this->current_preview_data['structure']; |
| 739 |
} |
| 740 |
|
| 741 |
/** |
| 742 |
* Apply unsaved global Form Style values to the preview iframe only. |
| 743 |
* |
| 744 |
* @param string $wrapped_html Wrapped booking form HTML. |
| 745 |
* @param array $bfb_settings BFB settings. |
| 746 |
* @param int $resource_id Booking resource ID. |
| 747 |
* @param string $custom_booking_form_name Form slug. |
| 748 |
* @return string |
| 749 |
*/ |
| 750 |
public function filter_wrapped_html_for_preview_form_style( $wrapped_html, $bfb_settings, $resource_id, $custom_booking_form_name ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 751 |
|
| 752 |
$preview_style = $this->get_preview_form_style(); |
| 753 |
if ( empty( $preview_style ) ) { |
| 754 |
return $wrapped_html; |
| 755 |
} |
| 756 |
|
| 757 |
$style = isset( $preview_style['booking_form_style'] ) ? wpbc_bfb_settings__sanitize_form_style( $preview_style['booking_form_style'] ) : wpbc_bfb_settings__get_default_form_style(); |
| 758 |
$preset = wpbc_bfb_settings__get_form_style_preset( $style ); |
| 759 |
|
| 760 |
$wrapped_html = $this->remove_classes_from_first_form_wrapper( |
| 761 |
$wrapped_html, |
| 762 |
array( |
| 763 |
'wpbc_theme_dark_1', |
| 764 |
'wpbc_bfb_form_appearance_custom', |
| 765 |
) |
| 766 |
); |
| 767 |
$wrapped_html = $this->remove_classes_from_first_tag_with_classes( |
| 768 |
$wrapped_html, |
| 769 |
array( 'wpbc_bfb_form' ), |
| 770 |
array( |
| 771 |
'wpbc_theme_dark_1', |
| 772 |
'wpbc_bfb_form_appearance_custom', |
| 773 |
) |
| 774 |
); |
| 775 |
|
| 776 |
$theme_class = isset( $preset['theme_class'] ) ? sanitize_html_class( (string) $preset['theme_class'] ) : ''; |
| 777 |
if ( '' !== $theme_class ) { |
| 778 |
$wrapped_html = WPBC_FE_Form_Style_Injector::add_class_to_first_tag_with_classes( $wrapped_html, array( 'wpbc_container', 'wpbc_form' ), $theme_class ); |
| 779 |
} |
| 780 |
|
| 781 |
$css_vars = wpbc_bfb_settings__get_form_style_css_vars( $style, $preview_style ); |
| 782 |
if ( ! empty( $css_vars ) ) { |
| 783 |
$wrapped_html = WPBC_FE_Form_Style_Injector::inject_css_vars_into_form_wrapper( $wrapped_html, $css_vars ); |
| 784 |
$wrapped_html = WPBC_FE_Form_Style_Injector::inject_css_vars_into_bfb_root( $wrapped_html, $css_vars ); |
| 785 |
} |
| 786 |
|
| 787 |
if ( wpbc_bfb_settings__is_custom_form_style( $style ) ) { |
| 788 |
$wrapped_html = WPBC_FE_Form_Style_Injector::add_class_to_first_tag_with_classes( $wrapped_html, array( 'wpbc_container', 'wpbc_form' ), 'wpbc_bfb_form_appearance_custom' ); |
| 789 |
$wrapped_html = WPBC_FE_Form_Style_Injector::add_class_to_first_tag_with_classes( $wrapped_html, array( 'wpbc_bfb_form' ), 'wpbc_bfb_form_appearance_custom' ); |
| 790 |
} |
| 791 |
|
| 792 |
return $wrapped_html; |
| 793 |
} |
| 794 |
|
| 795 |
/** |
| 796 |
* Get sanitized preview Form Style override from the current transient data. |
| 797 |
* |
| 798 |
* @return array |
| 799 |
*/ |
| 800 |
protected function get_preview_form_style() { |
| 801 |
|
| 802 |
if ( empty( $this->current_preview_data['form_style'] ) || ! is_array( $this->current_preview_data['form_style'] ) ) { |
| 803 |
return array(); |
| 804 |
} |
| 805 |
|
| 806 |
$style = isset( $this->current_preview_data['form_style']['booking_form_style'] ) ? $this->current_preview_data['form_style']['booking_form_style'] : ''; |
| 807 |
$style = wpbc_bfb_settings__sanitize_form_style( $style ); |
| 808 |
|
| 809 |
$custom_options = wpbc_bfb_settings__get_custom_form_style_options( $this->current_preview_data['form_style'] ); |
| 810 |
$accent_options = wpbc_bfb_settings__get_form_accent_options( $this->current_preview_data['form_style'] ); |
| 811 |
|
| 812 |
return array_merge( |
| 813 |
array( |
| 814 |
'booking_form_style' => $style, |
| 815 |
), |
| 816 |
$custom_options, |
| 817 |
$accent_options |
| 818 |
); |
| 819 |
} |
| 820 |
|
| 821 |
/** |
| 822 |
* Remove classes from the first outer booking form wrapper. |
| 823 |
* |
| 824 |
* @param string $html HTML. |
| 825 |
* @param array $class_names Class names to remove. |
| 826 |
* @return string |
| 827 |
*/ |
| 828 |
protected function remove_classes_from_first_form_wrapper( $html, $class_names ) { |
| 829 |
|
| 830 |
return $this->remove_classes_from_first_tag_with_classes( $html, array( 'wpbc_container', 'wpbc_form' ), $class_names ); |
| 831 |
} |
| 832 |
|
| 833 |
/** |
| 834 |
* Remove classes from the first tag that has all required classes. |
| 835 |
* |
| 836 |
* @param string $html HTML. |
| 837 |
* @param array $required_classes Required classes. |
| 838 |
* @param array $class_names Class names to remove. |
| 839 |
* @return string |
| 840 |
*/ |
| 841 |
protected function remove_classes_from_first_tag_with_classes( $html, $required_classes, $class_names ) { |
| 842 |
|
| 843 |
$html = (string) $html; |
| 844 |
$required_classes = is_array( $required_classes ) ? $required_classes : array(); |
| 845 |
$class_names = is_array( $class_names ) ? $class_names : array(); |
| 846 |
$remove_map = array(); |
| 847 |
$required_map = array(); |
| 848 |
|
| 849 |
foreach ( $required_classes as $class_name ) { |
| 850 |
$class_name = sanitize_html_class( (string) $class_name ); |
| 851 |
if ( '' !== $class_name ) { |
| 852 |
$required_map[ $class_name ] = true; |
| 853 |
} |
| 854 |
} |
| 855 |
|
| 856 |
foreach ( $class_names as $class_name ) { |
| 857 |
$class_name = sanitize_html_class( (string) $class_name ); |
| 858 |
if ( '' !== $class_name ) { |
| 859 |
$remove_map[ $class_name ] = true; |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
if ( empty( $remove_map ) || empty( $required_map ) ) { |
| 864 |
return $html; |
| 865 |
} |
| 866 |
|
| 867 |
$done = false; |
| 868 |
$out = preg_replace_callback( |
| 869 |
'/<div\b[^>]*\bclass\s*=\s*(["\'])(.*?)\1[^>]*>/i', |
| 870 |
function ( $matches ) use ( &$done, $remove_map, $required_map ) { |
| 871 |
|
| 872 |
$tag = $matches[0]; |
| 873 |
if ( $done ) { |
| 874 |
return $tag; |
| 875 |
} |
| 876 |
|
| 877 |
$quote = $matches[1]; |
| 878 |
$classes = preg_split( '/\s+/', trim( (string) $matches[2] ) ); |
| 879 |
$classes = is_array( $classes ) ? $classes : array(); |
| 880 |
|
| 881 |
foreach ( $required_map as $required_class => $unused ) { |
| 882 |
if ( ! in_array( $required_class, $classes, true ) ) { |
| 883 |
return $tag; |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
$filtered = array(); |
| 888 |
foreach ( $classes as $class_name ) { |
| 889 |
if ( '' === $class_name || isset( $remove_map[ $class_name ] ) ) { |
| 890 |
continue; |
| 891 |
} |
| 892 |
$filtered[] = $class_name; |
| 893 |
} |
| 894 |
|
| 895 |
$done = true; |
| 896 |
|
| 897 |
return preg_replace( '/\bclass\s*=\s*(["\'])(.*?)\1/i', 'class=' . $quote . esc_attr( implode( ' ', $filtered ) ) . $quote, $tag, 1 ); |
| 898 |
}, |
| 899 |
$html |
| 900 |
); |
| 901 |
|
| 902 |
return ( null === $out ) ? $html : $out; |
| 903 |
} |
| 904 |
|
| 905 |
/** |
| 906 |
* Hide the preview page from the Pages list in admin. |
| 907 |
* |
| 908 |
* @param WP_Query $query Main query. |
| 909 |
*/ |
| 910 |
public function hide_preview_page_in_admin_list( $query ) { |
| 911 |
|
| 912 |
if ( ! is_admin() || ! $query->is_main_query() ) { |
| 913 |
return; |
| 914 |
} |
| 915 |
|
| 916 |
global $pagenow; |
| 917 |
|
| 918 |
if ( 'edit.php' !== $pagenow ) { |
| 919 |
return; |
| 920 |
} |
| 921 |
|
| 922 |
$post_type = $query->get( 'post_type' ); |
| 923 |
|
| 924 |
if ( 'page' !== $post_type && '' !== $post_type ) { |
| 925 |
return; |
| 926 |
} |
| 927 |
|
| 928 |
$page_id = $this->get_preview_page_id(); |
| 929 |
|
| 930 |
if ( $page_id <= 0 ) { |
| 931 |
return; |
| 932 |
} |
| 933 |
|
| 934 |
$not_in = (array) $query->get( 'post__not_in' ); |
| 935 |
$not_in[] = (int) $page_id; |
| 936 |
|
| 937 |
$query->set( 'post__not_in', $not_in ); |
| 938 |
} |
| 939 |
|
| 940 |
// FixIn: 2026-01-03 14:31. |
| 941 |
/** |
| 942 |
* Create a preview session: store transient snapshot and return preview URL + token. |
| 943 |
* |
| 944 |
* @param int $preview_form_id Preview form/resource ID. |
| 945 |
* @param int $user_id Current user ID. |
| 946 |
* @param array $structure Decoded BFB structure. |
| 947 |
* |
| 948 |
* @return array|false { preview_url, token } or false on failure. |
| 949 |
*/ |
| 950 |
public function create_preview_session( $preview_form_id, $user_id, $structure, $form_name = 'standard', $advanced_form = '', $content_form = '', $form_style = array() ) { |
| 951 |
|
| 952 |
|
| 953 |
$preview_form_id = (int) $preview_form_id; |
| 954 |
$user_id = (int) $user_id; |
| 955 |
$structure = ( is_array( $structure ) ? $structure : array() ); |
| 956 |
$form_name = sanitize_text_field( (string) $form_name ); |
| 957 |
if ( '' === $form_name ) { |
| 958 |
$form_name = 'standard'; |
| 959 |
} |
| 960 |
$form_style = is_array( $form_style ) ? $form_style : array(); |
| 961 |
if ( ! empty( $form_style ) ) { |
| 962 |
$style_key = isset( $form_style['booking_form_style'] ) ? $form_style['booking_form_style'] : ''; |
| 963 |
$sanitized_style = wpbc_bfb_settings__sanitize_form_style( $style_key ); |
| 964 |
$custom_style = wpbc_bfb_settings__get_custom_form_style_options( $form_style ); |
| 965 |
$accent_style = wpbc_bfb_settings__get_form_accent_options( $form_style ); |
| 966 |
$form_style = array_merge( |
| 967 |
array( |
| 968 |
'booking_form_style' => $sanitized_style, |
| 969 |
), |
| 970 |
$custom_style, |
| 971 |
$accent_style |
| 972 |
); |
| 973 |
} |
| 974 |
if ( $preview_form_id <= 0 ) { |
| 975 |
$preview_form_id = 1; |
| 976 |
} |
| 977 |
if ( $user_id <= 0 ) { |
| 978 |
return false; |
| 979 |
} |
| 980 |
|
| 981 |
$page_id = $this->get_preview_page_id(); |
| 982 |
if ( ! $page_id ) { |
| 983 |
return false; |
| 984 |
} |
| 985 |
|
| 986 |
$token = wp_generate_password( 12, false, false ); |
| 987 |
$transient_key = $this->get_transient_key( $user_id, $token, $preview_form_id ); |
| 988 |
|
| 989 |
$payload = array( |
| 990 |
'user_id' => $user_id, |
| 991 |
// Keep key name as-is (your preview reader expects ['form_id']). |
| 992 |
// This is a *preview context resource/calendar id* (used for shortcode type="..."). |
| 993 |
'form_id' => $preview_form_id, |
| 994 |
'form_name' => $form_name, |
| 995 |
'scope' => 'preview', |
| 996 |
'structure' => $structure, |
| 997 |
'time' => time(), |
| 998 |
'advanced_form' => (string) $advanced_form, |
| 999 |
'content_form' => (string) $content_form, |
| 1000 |
'form_style' => $form_style, |
| 1001 |
); |
| 1002 |
|
| 1003 |
set_transient( $transient_key, $payload, 10 * MINUTE_IN_SECONDS ); |
| 1004 |
|
| 1005 |
$preview_url = add_query_arg( array( |
| 1006 |
'wpbc_bfb_preview' => 1, |
| 1007 |
'wpbc_bfb_preview_token' => rawurlencode( $token ), |
| 1008 |
'wpbc_bfb_preview_form_id' => $preview_form_id, |
| 1009 |
'nonce' => wp_create_nonce( 'wpbc_bfb_preview_' . $token ), |
| 1010 |
), get_permalink( $page_id ) ); |
| 1011 |
|
| 1012 |
return array( |
| 1013 |
'preview_url' => $preview_url, |
| 1014 |
'token' => $token, |
| 1015 |
); |
| 1016 |
} |
| 1017 |
|
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
/** |
| 1022 |
* Render BFB Preview Panel in the Builder admin page. |
| 1023 |
* |
| 1024 |
* @param int $form_id Current booking form / resource ID. |
| 1025 |
*/ |
| 1026 |
function wpbc_bfb_render_preview_panel( $form_id = 1 ) { |
| 1027 |
|
| 1028 |
$form_id = absint( $form_id ); |
| 1029 |
if ( $form_id <= 0 ) { |
| 1030 |
$form_id = 1; |
| 1031 |
} |
| 1032 |
|
| 1033 |
$preview_nonce = wp_create_nonce( 'wpbc_bfb_preview' ); |
| 1034 |
?> |
| 1035 |
<div id="wpbc_bfb__preview_panel" |
| 1036 |
class="wpbc_bfb__preview_panel" |
| 1037 |
data-wpbc-bfb-preview-root="1" |
| 1038 |
data-form-id="<?php echo esc_attr( $form_id ); ?>" |
| 1039 |
data-preview-nonce="<?php echo esc_attr( $preview_nonce ); ?>"> |
| 1040 |
|
| 1041 |
<div class="wpbc_bfb__preview_panel__toolbar"> |
| 1042 |
<h1 class="wpbc_settings_page_header_title wpbc_bfb_ui__elements_show_in_preview"> |
| 1043 |
<?php esc_html_e( 'Booking Form Preview', 'booking' ); ?> |
| 1044 |
</h1> |
| 1045 |
<span class="description"> |
| 1046 |
<?php esc_html_e( 'The preview shows the live booking form inside your site theme.', 'booking' ); ?> |
| 1047 |
</span> |
| 1048 |
<style type="text/css"> |
| 1049 |
html[data-wpbc-bfb-live-source="advanced"] .warning_description { |
| 1050 |
display: block; |
| 1051 |
} |
| 1052 |
.warning_description { |
| 1053 |
display: none; |
| 1054 |
width: 700px; |
| 1055 |
color: #900; |
| 1056 |
width: 630px; |
| 1057 |
color: #44270d; |
| 1058 |
text-align: center; |
| 1059 |
font-size: 14px; |
| 1060 |
line-height: 2; |
| 1061 |
background: #fff; |
| 1062 |
padding: 10px; |
| 1063 |
padding: 0.75em 2em; |
| 1064 |
margin: 20px auto 0; |
| 1065 |
border-radius: 8px; |
| 1066 |
border: 2px solid #b97131; |
| 1067 |
} |
| 1068 |
.warning_description .wpbc_bfb__live_status__advanced { |
| 1069 |
font-weight: 550; |
| 1070 |
display: inline !important; |
| 1071 |
} |
| 1072 |
</style> |
| 1073 |
<div class="warning_description"> |
| 1074 |
<?php |
| 1075 |
/* translators: 1: <strong>, 2: </strong>, 3: <a ...>, 4: </a>, 5: <a ...>, 6: </a> */ |
| 1076 |
printf( __( '%1$sNote!%2$s This preview is generated from %3$sAdvanced (manual)%4$s, which is not synced with the Form Builder. To sync it, enable the corresponding checkbox %5$shere%6$s.', 'booking' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1077 |
'<strong>', |
| 1078 |
'</strong>', |
| 1079 |
'<a class="wpbc_bfb__live_status__advanced" href="javascript:void(0);" onclick="javascript:WPBC_BFB_Preview.show_advanced_tab({});">', |
| 1080 |
'</a>', |
| 1081 |
'<a href="javascript:void(0);" onclick="javascript:WPBC_BFB_Preview.show_advanced_tab({});">', |
| 1082 |
'</a>' |
| 1083 |
); |
| 1084 |
?> |
| 1085 |
</div> |
| 1086 |
</div> |
| 1087 |
|
| 1088 |
<div class="wpbc_bfb__preview_panel__frame_wrapper"> |
| 1089 |
<div class="wpbc_bfb__preview_loader" data-wpbc-bfb-preview-loader="1" aria-hidden="true"> |
| 1090 |
<?php |
| 1091 |
wpbc_bfb_spins_loading_container_mini(); |
| 1092 |
?> |
| 1093 |
</div> |
| 1094 |
|
| 1095 |
<iframe |
| 1096 |
id="wpbc_bfb__preview_iframe" |
| 1097 |
class="wpbc_bfb__preview_iframe" |
| 1098 |
data-wpbc-bfb-preview-iframe="1" |
| 1099 |
src="about:blank" |
| 1100 |
title="<?php esc_attr_e( 'Booking form preview', 'booking' ); ?>" |
| 1101 |
loading="lazy" |
| 1102 |
referrerpolicy="no-referrer-when-downgrade"> |
| 1103 |
</iframe> |
| 1104 |
</div> |
| 1105 |
</div> |
| 1106 |
<?php |
| 1107 |
} |
| 1108 |
|
| 1109 |
/** |
| 1110 |
* Show Loader Spin. |
| 1111 |
* |
| 1112 |
* @return void |
| 1113 |
*/ |
| 1114 |
function wpbc_bfb_spins_loading_container() { |
| 1115 |
?> |
| 1116 |
<div class="wpbc_spins_loading_container"> |
| 1117 |
<div class="wpbc_booking_form_spin_loader"> |
| 1118 |
<div class="wpbc_spins_loader_wrapper"> |
| 1119 |
<div class="wpbc_spin_loader_one_new"></div> |
| 1120 |
</div> |
| 1121 |
</div> |
| 1122 |
<span><?php echo esc_html__( 'Loading', 'booking' ); ?> ...</span> |
| 1123 |
</div> |
| 1124 |
<?php |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
/** |
| 1129 |
* Show Mini Loader Spin. |
| 1130 |
* |
| 1131 |
* @return void |
| 1132 |
*/ |
| 1133 |
function wpbc_bfb_spins_loading_container_mini() { |
| 1134 |
?> |
| 1135 |
<div class="wpbc_spins_loading_container wpbc_bfb_spins_loading_container"> |
| 1136 |
<div class="wpbc_booking_form_spin_loader"> |
| 1137 |
<div class="wpbc_spins_loader_wrapper"> |
| 1138 |
<div class="wpbc_one_spin_loader_mini2"></div> |
| 1139 |
</div> |
| 1140 |
</div> |
| 1141 |
<span><?php esc_html_e( 'Loading', 'booking' ); ?>...</span> |
| 1142 |
</div> |
| 1143 |
<?php |
| 1144 |
} |
| 1145 |
|