PluginProbe
Booking Calendar / 11.8
Booking Calendar v11.8
11.9 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 All 205 releases
booking / includes / page-form-builder / field-packs / captcha / field-captcha-wptpl.php

field-captcha-wptpl.php in Booking Calendar 11.8, at includes/page-form-builder/field-packs/captcha/field-captcha-wptpl.php

295 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPBC BFB Pack: Text Captcha (WP-template–driven with Inspector)
4 *
5 * Purpose:
6 * - Adds a CAPTCHA field that exports to the shortcode [captcha].
7 * - Inspector and Preview are rendered via wp.template() blocks.
8 * - Supports standard field title (label) and help text under the CAPTCHA.
9 * - Enforces usage guard via usage_key 'captcha' (palette item can set data-usagenumber="1").
10 *
11 * Contracts:
12 * - Filter: wpbc_bfb_register_field_packs
13 * - Action: wpbc_enqueue_js_field_pack
14 * - Action: wpbc_bfb_palette_register_items (optional palette registration)
15 *
16 * File: ../includes/page-form-builder/field-packs/captcha/field-captcha-wptpl.php
17 *
18 * @package Booking Calendar
19 * @author wpdevelop, oplugins
20 * @since 11.0.0
21 * @modified 2025-10-18
22 * @version 1.0.0
23 */
24
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit;
27 }
28
29 /**
30 * Register the "captcha" field pack (WP-template–driven Inspector).
31 *
32 * @param array $packs Accumulated packs from other modules.
33 *
34 * @return array Modified packs with "captcha" field included.
35 */
36 function wpbc_bfb_register_field_packs__field_captcha_wptpl( $packs ) {
37
38 $packs['captcha'] = array(
39 'kind' => 'field',
40 'type' => 'captcha',
41 'label' => '',//__( 'Text Captcha', 'booking' ),
42 'icon' => 'wpbc-bi-shield-lock',
43 'usage_key' => 'captcha',
44
45 // Schema for coercion/defaults/serialization (template-driven inspector).
46 'schema' => array(
47 'props' => array(
48 'label' => array( 'type' => 'string', 'default' => __( 'CAPTCHA', 'booking' ) ),
49 'html_id' => array( 'type' => 'string', 'default' => '' ),
50 'cssclass' => array( 'type' => 'string', 'default' => '' ),
51 'help' => array( 'type' => 'string', 'default' => '' ),
52 ),
53 ),
54
55 // Ask core to print wp.template() blocks for this pack.
56 'templates_printer' => 'wpbc_bfb_field_captcha_wptpl_print_templates',
57 );
58
59 return $packs;
60 }
61 add_filter( 'wpbc_bfb_register_field_packs', 'wpbc_bfb_register_field_packs__field_captcha_wptpl' );
62
63
64 /**
65 * Enqueue the CAPTCHA (WP-template) pack JS for the Builder page.
66 *
67 * @param string $page Current admin page slug (from core).
68 *
69 * @return void
70 */
71 function wpbc_bfb_enqueue__field_captcha_wptpl_js( $page ) {
72
73 wp_enqueue_script(
74 'wpbc-bfb_field_captcha_wptpl',
75 wpbc_plugin_url( '/includes/page-form-builder/field-packs/captcha/_out/field-captcha-wptpl.js' ),
76 array( 'wp-util', 'wpbc-bfb' ),
77 WP_BK_VERSION_NUM,
78 true
79 );
80 }
81 add_action( 'wpbc_enqueue_js_field_pack', 'wpbc_bfb_enqueue__field_captcha_wptpl_js', 10, 1 );
82
83
84 /**
85 * Print wp.template() blocks for the CAPTCHA field:
86 * - Canvas Preview: tmpl-wpbc-bfb-field-captcha
87 * - Inspector: tmpl-wpbc-bfb-inspector-captcha
88 *
89 * Uses {{ ... }} (escaped). Keep preview inert/disabled (Builder only).
90 *
91 * @param string $page The current page slug (core passes the Builder slug here).
92 *
93 * @return void
94 */
95 function wpbc_bfb_field_captcha_wptpl_print_templates( $page ) {
96
97 if ( WPBC_BFB_BUILDER_PAGE_SLUG !== $page ) {
98 return;
99 }
100
101 // ============ Canvas Preview Template ============
102 ?>
103 <script type="text/html" id="tmpl-wpbc-bfb-field-captcha">
104 <span class="wpbc_bfb__noaction wpbc_bfb__no-drag-zone" inert="">
105 <# var has_label = !!( data.label && data.label !== '' ); #>
106
107 <# if ( has_label ) { #>
108 <label class="wpbc_bfb__field-label" <# if ( data.html_id ) { #> for="{{ data.html_id }}" <# } #>>
109 {{ data.label }}
110 </label>
111 <# } #>
112
113 <span class="wpbc_text_captcha_container wpdev-form-control-wrap">
114 <input autocomplete="off" type="hidden"
115 name="wpdev_captcha_challenge_{{ data.id || 'X' }}"
116 id="wpdev_captcha_challenge_{{ data.id || 'X' }}"
117 value="{{ data.challenge || '0000000000' }}"/>
118
119 <input autocomplete="off" type="text"
120 class="captachinput {{ data.cssclass || '' }}"
121 value=""
122 name="captcha_input{{ data.id || 'X' }}"
123 id="captcha_input{{ data.id || 'X' }}"
124 tabindex="-1"
125 disabled
126 aria-disabled="true"/>
127
128 <img decoding="async" draggable="false"
129 class="captcha_img"
130 id="captcha_img{{ data.id || 'X' }}"
131 alt="{{ data.alt_text || '' }}"
132 src="{{ data.img_url || data.placeholder_src || '' }}"/>
133 </span>
134
135 <# if ( data.help ) { #>
136 <div class="wpbc_bfb__help">{{ data.help }}</div>
137 <# } #>
138 </span>
139 </script>
140 <?php
141
142 // ============ Inspector Template ============
143 ?>
144 <script type="text/html" id="tmpl-wpbc-bfb-inspector-captcha">
145 <div class="wpbc_bfb__inspector__head">
146 <div class="header_container">
147 <div class="header_title_content">
148 <h3 class="title"><?php
149 echo esc_html__( 'Text Captcha', 'booking' ); ?></h3>
150 <div class="desc">
151 <?php
152 echo esc_html__( 'The CAPTCHA appears on the form only if it is enabled in Settings - Form Options.', 'booking' );
153 ?>
154 </div>
155 </div>
156 <div class="actions wpbc_ajx_toolbar wpbc_no_borders">
157 <div class="ui_container ui_container_small">
158 <div class="ui_group">
159 <div class="ui_element">
160 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
161 data-action="deselect" aria-label="<?php
162 echo esc_attr__( 'Deselect', 'booking' ); ?>">
163 <i class="menu_icon icon-1x wpbc_icn_remove_done"></i>
164 </button>
165 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
166 data-action="scrollto" aria-label="<?php
167 echo esc_attr__( 'Scroll to field', 'booking' ); ?>">
168 <i class="menu_icon icon-1x wpbc_icn_ads_click filter_center_focus"></i>
169 </button>
170 </div>
171 <div class="ui_element">
172 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
173 data-action="move-up" aria-label="<?php
174 echo esc_attr__( 'Move up', 'booking' ); ?>">
175 <i class="menu_icon icon-1x wpbc_icn_arrow_upward"></i>
176 </button>
177 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
178 data-action="move-down" aria-label="<?php
179 echo esc_attr__( 'Move down', 'booking' ); ?>">
180 <i class="menu_icon icon-1x wpbc_icn_arrow_downward"></i>
181 </button>
182 </div>
183 <div class="ui_element">
184 <button data-action="delete" aria-label="<?php
185 echo esc_attr__( 'Delete', 'booking' ); ?>"
186 type="button"
187 class="button button-secondary wpbc_ui_control wpbc_ui_button wpbc_ui_button_danger button-link-delete">
188 <span class="in-button-text"><?php
189 echo esc_html__( 'Delete', 'booking' ); ?></span>&nbsp;&nbsp;
190 <i class="menu_icon icon-1x wpbc_icn_delete_outline"></i>
191 </button>
192 </div>
193 </div><!-- .ui_group -->
194 </div><!-- .ui_container -->
195 </div><!-- .actions -->
196 </div><!-- .header_container -->
197 </div><!-- .wpbc_bfb__inspector__head -->
198
199 <div class="wpbc_bfb__inspector__body">
200
201 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group is-open" data-group="basic">
202 <button type="button" class="group__header">
203 <h3><?php
204 echo esc_html__( 'Basic', 'booking' ); ?></h3>
205 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
206 </button>
207 <div class="group__fields">
208 <div class="inspector__row">
209 <label class="inspector__label"><?php
210 echo esc_html__( 'Label', 'booking' ); ?></label>
211 <div class="inspector__control">
212 <input type="text" class="inspector__input" data-inspector-key="label"
213 value="{{ data.label || '<?php
214 echo esc_js( __( 'CAPTCHA', 'booking' ) ); ?>' }}">
215 </div>
216 </div>
217
218 <div class="inspector__row">
219 <label class="inspector__label"><?php
220 echo esc_html__( 'Help text', 'booking' ); ?></label>
221 <div class="inspector__control">
222 <textarea class="inspector__textarea" rows="3" data-inspector-key="help">{{ data.help || '' }}</textarea>
223 </div>
224 </div>
225 </div>
226 </section>
227
228 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group" data-group="appearance">
229 <button type="button" class="group__header">
230 <h3><?php
231 echo esc_html__( 'Appearance', 'booking' ); ?></h3>
232 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
233 </button>
234 <div class="group__fields">
235 <div class="inspector__row">
236 <label class="inspector__label"><?php
237 echo esc_html__( 'CSS class', 'booking' ); ?></label>
238 <div class="inspector__control">
239 <input type="text" class="inspector__input" data-inspector-key="cssclass"
240 value="{{ data.cssclass || '' }}">
241 </div>
242 </div>
243
244 <div class="inspector__row">
245 <label class="inspector__label"><?php
246 echo esc_html__( 'HTML ID', 'booking' ); ?></label>
247 <div class="inspector__control">
248 <input type="text" class="inspector__input" data-inspector-key="html_id"
249 value="{{ data.html_id || '' }}">
250 </div>
251 </div>
252
253 <div class="wpbc_bfb__inspector__note">
254 <?php
255 echo esc_html__( 'This field renders as [captcha]. Name and validation are handled by the Booking Calendar core.', 'booking' ); ?>
256 </div>
257 </div>
258 </section>
259
260 </div><!-- .wpbc_bfb__inspector__body -->
261 </script>
262 <?php
263 }
264
265 /**
266 * (Optional) Register the "Text Captcha" palette item in "general/bottom".
267 *
268 * @param string $group Palette group: 'general' | 'advanced' | ...
269 * @param string $position Position: 'top' | 'bottom'
270 *
271 * @return void
272 */
273 function wpbc_bfb_palette_register_items__captcha_wptpl( $group, $position ) {
274
275 if ( 'essentials' !== $group || 'top' !== $position ) {
276 return;
277 }
278
279 ?>
280 <li class="wpbc_bfb__field"
281 data-id="captcha"
282 data-type="captcha"
283 data-usage_key="captcha"
284 data-usagenumber="1"
285 data-label="<?php
286 echo ''; // esc_attr( __( 'Text Captcha', 'booking' ) ); ?>">
287 <i class="menu_icon icon-1x wpbc_icn_format_shapes"></i>
288 <span class="wpbc_bfb__field-label"><?php
289 echo esc_html( __( 'Text Captcha', 'booking' ) ); ?></span>
290 <span class="wpbc_bfb__field-type">captcha</span>
291 </li>
292 <?php
293 }
294 add_action( 'wpbc_bfb_palette_register_items', 'wpbc_bfb_palette_register_items__captcha_wptpl', 10, 2 );
295