| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | // This file is included via Render::view() using extract(); all variables below are in the calling method's local scope, not global namespace. |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Core\Util\EscapingHelper; |
| 6 | +use BitCode\BitForm\Core\Util\FrontendHelpers; | |
| 6 | 7 | |
| 7 | 8 | if (!defined('ABSPATH')) { |
| 8 | 9 | exit; |
| 9 | 10 | } |
| @@ -20,10 +21,10 @@ | ||
| 20 | 21 | |
| 21 | 22 | $formUpdateVersion = get_option('bitform_form_update_version'); |
| 22 | 23 | $formIdSafe = sanitize_key((string) $formID); |
| 23 | 24 | |
| 24 | -$cssFileUrl = BITFORMS_UPLOAD_BASE_URL . '/form-styles/bitform-' . $formID . '.css'; | |
| 25 | -$cssFileUrlFormId = BITFORMS_UPLOAD_BASE_URL . '/form-styles/bitform-' . $formID . '-formid.css'; | |
| 25 | +$cssFileUrl = FrontendHelpers::styleSrc('form-styles/bitform-' . $formID . '.css'); | |
| 26 | +$cssFileUrlFormId = FrontendHelpers::styleSrc('form-styles/bitform-' . $formID . '-formid.css'); | |
| 26 | 27 | $customCssSubPath = '/form-styles/bitform-custom-' . $formID . '.css'; |
| 27 | 28 | |
| 28 | 29 | wp_register_style('bitform-preview-base-' . $formIdSafe, $cssFileUrl, [], $formUpdateVersion); |
| 29 | 30 | wp_register_style('bitform-preview-formid-' . $formIdSafe, $cssFileUrlFormId, [], $formUpdateVersion); |
| @@ -31,9 +32,9 @@ | ||
| 31 | 32 | wp_enqueue_style('bitform-preview-formid-' . $formIdSafe); |
| 32 | 33 | |
| 33 | 34 | $customCssRegistered = false; |
| 34 | 35 | if (file_exists(BITFORMS_CONTENT_DIR . $customCssSubPath)) { |
| 35 | - wp_register_style('bitform-preview-custom-' . $formIdSafe, BITFORMS_UPLOAD_BASE_URL . $customCssSubPath, [], $formUpdateVersion); | |
| 36 | + wp_register_style('bitform-preview-custom-' . $formIdSafe, FrontendHelpers::styleSrc($customCssSubPath), [], $formUpdateVersion); | |
| 36 | 37 | wp_enqueue_style('bitform-preview-custom-' . $formIdSafe); |
| 37 | 38 | $customCssRegistered = true; |
| 38 | 39 | } |
| 39 | 40 | |
| @@ -58,8 +59,13 @@ | ||
| 58 | 59 | |
| 59 | 60 | if (isset($bfGlobals) && '' !== $bfGlobals) { |
| 60 | 61 | wp_add_inline_script('bitform-preview-' . $formIdSafe, (string) $bfGlobals, 'before'); |
| 61 | 62 | } |
| 63 | +wp_add_inline_script( | |
| 64 | + 'bitform-preview-' . $formIdSafe, | |
| 65 | + 'if(!window.__bfShowPickerBound){window.__bfShowPickerBound=true;document.addEventListener("click",function(e){var t=e.target;if(t&&t.matches&&t.matches("input[data-bf-show-picker=\"1\"]")&&typeof t.showPicker==="function"){try{t.showPicker();}catch(_){}}});}', | |
| 66 | + 'after' | |
| 67 | +); | |
| 62 | 68 | |
| 63 | 69 | $jsSize = bitforms_readable_filesize(filesize(BITFORMS_CONTENT_DIR . '/form-scripts/preview-' . $formID . '.js')); |
| 64 | 70 | $cssSize = bitforms_readable_filesize(filesize(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $formID . '.css')); |
| 65 | 71 | $shortcode = '[bitform id="' . $formID . '"]'; |
| @@ -528,8 +534,13 @@ | ||
| 528 | 534 | |
| 529 | 535 | <!-- Preview Container --> |
| 530 | 536 | <main class="bf-preview-container"> |
| 531 | 537 | <div class="bf-preview-frame" id="bf-preview-frame"> |
| 538 | + <?php | |
| 539 | + // Fallback config for when an optimizer defers or drops the inline script. | |
| 540 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built by buildFormConfigTag(), JSON_HEX_* escaped. | |
| 541 | + echo isset($configTag) ? $configTag : ''; | |
| 542 | + ?> | |
| 532 | 543 | <?php echo wp_kses($formHTML, EscapingHelper::getFormAllowedHtml(isset($formContent) ? $formContent : null)); ?> |
| 533 | 544 | </div> |
| 534 | 545 | </main> |
| 535 | 546 | |