PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.6
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 / text / field-text-wptpl.php

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

329 lines 14.1 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 Field (WP-template–driven Reference)
4 *
5 * Purpose:
6 * - Demonstrates a field pack whose Inspector UI and preview are rendered via wp.template().
7 * - Keeps a PHP schema for coercion/validation/serialization, but omits 'inspector_ui' to prefer the template-based Inspector.
8 *
9 * Loading:
10 * - This pack assumes you do NOT load the schema-driven "text" pack simultaneously.
11 *
12 * Contracts:
13 * - Filter: wpbc_bfb_register_field_packs
14 * - Action: wpbc_enqueue_js_field_pack
15 * - Action: wpbc_bfb_palette_register_items (optional)
16 *
17 * Notes:
18 * - Keep JS get_defaults() in sync with the schema defaults below.
19 *
20 * File: ../includes/page-form-builder/field-packs/text/field-text-wptpl.php
21 *
22 * @package Booking Calendar
23 * @author wpdevelop, oplugins
24 * @since 11.0.0
25 * @modified 2025-09-04
26 * @version 1.0.1
27 */
28
29 if ( ! defined( 'ABSPATH' ) ) {
30 exit;
31 }
32
33 /**
34 * Register the "text" field pack (WP-template–driven Inspector).
35 *
36 * @param array $packs Accumulated packs from other modules.
37 * @return array Modified packs with "text" field included.
38 */
39 function wpbc_bfb_register_field_packs__field_text_wptpl( $packs ) {
40
41 $packs['text'] = array(
42 'kind' => 'field',
43 'type' => 'text',
44 'label' => __( 'Text', 'booking' ),
45 'icon' => 'wpbc_icn_text_fields',
46 'usage_key' => 'text', // Optional: used by UsageLimitService if you set limits elsewhere.
47
48 // Schema still drives coercion, defaults and serialization.
49 'schema' => array(
50 'props' => array(
51 'label' => array( 'type' => 'string', 'default' => __( 'Text', 'booking' ) ),
52 'name' => array( 'type' => 'string', 'default' => '' ),
53 'html_id' => array( 'type' => 'string', 'default' => '' ),
54 'placeholder' => array( 'type' => 'string', 'default' => '' ),
55 'required' => array( 'type' => 'boolean', 'default' => false ),
56 'minlength' => array( 'type' => 'number', 'default' => null, 'min' => 0 ),
57 'maxlength' => array( 'type' => 'number', 'default' => null, 'min' => 0 ),
58 'pattern' => array( 'type' => 'string', 'default' => '' ),
59 'cssclass' => array( 'type' => 'string', 'default' => '' ),
60 'help' => array( 'type' => 'string', 'default' => '' ),
61 'default_value' => array( 'type' => 'string', 'default' => '' ),
62 ),
63 ),
64
65 // Ask core to print the two wp.template() blocks for this pack.
66 'templates_printer' => 'wpbc_bfb_field_text_wptpl_print_templates'
67 );
68
69 return $packs;
70 }
71 add_filter( 'wpbc_bfb_register_field_packs', 'wpbc_bfb_register_field_packs__field_text_wptpl' );
72
73
74 /**
75 * Enqueue the Text (WP-template) pack JS for the Builder page.
76 *
77 * Hook runs on Builder; we keep it lean and attach our renderer file.
78 *
79 * @param string $page Current admin page slug (from core).
80 * @return void
81 */
82 function wpbc_bfb_enqueue__field_text_wptpl_js( $page ) {
83
84 wp_enqueue_script( 'wpbc-bfb_field_text_wptpl', wpbc_plugin_url( '/includes/page-form-builder/field-packs/text/_out/field-text-wptpl.js' ), array( 'wp-util', 'wpbc-bfb' ), WP_BK_VERSION_NUM, true );
85 }
86 add_action( 'wpbc_enqueue_js_field_pack', 'wpbc_bfb_enqueue__field_text_wptpl_js', 10, 1 );
87
88
89 /**
90 * Print wp.template() blocks for the Text field:
91 * - Canvas Preview: tmpl-wpbc-bfb-field-text
92 * - Inspector: tmpl-wpbc-bfb-inspector-text
93 *
94 * Uses {{ ... }} (escaped) — do not switch to {{{ ... }}} for user-provided content.
95 *
96 * @param string $page The current page slug (core passes the Builder slug here).
97 * @return void
98 */
99 function wpbc_bfb_field_text_wptpl_print_templates( $page ) {
100
101 if ( WPBC_BFB_BUILDER_PAGE_SLUG !== $page ) {
102 return;
103 }
104
105 // ============ Canvas Preview Template ============
106 ?>
107 <script type="text/html" id="tmpl-wpbc-bfb-field-text">
108 <span class="wpbc_bfb__noaction wpbc_bfb__no-drag-zone" inert="">
109 <# var is_req = ( true === data.required || 'true' === data.required || 1 === data.required || '1' === data.required ); #>
110
111 <# if ( data.label && data.label !== '' ) { #>
112 <label class="wpbc_bfb__field-label" <# if ( data.html_id ) { #> for="{{ data.html_id }}" <# } #>>
113 {{ data.label }} <# if ( is_req ) { #><span aria-hidden="true">*</span><# } #>
114 </label>
115 <# } #>
116
117 <span class="wpbc_wrap_text wpdev-form-control-wrap">
118 <input type="text"
119 class="wpbc_bfb__preview-input {{ data.cssclass || '' }}"
120 placeholder="{{ data.placeholder || '' }}"
121 name="{{ data.name || data.id || 'field' }}"
122 autocomplete="off"
123 tabindex="-1"
124 aria-disabled="true"
125 <# if ( data.html_id ) { #> id="{{ data.html_id }}" <# } #>
126 <# if ( data.default_value != null && data.default_value !== '' ) { #> value="{{ data.default_value }}" <# } #>
127 <# if ( is_req ) { #> required aria-required="true" <# } #>
128 <# if ( data.minlength != null && data.minlength !== '' && isFinite( Number( data.minlength ) ) ) { #> minlength="{{ Number( data.minlength ) }}" <# } #>
129 <# if ( data.maxlength != null && data.maxlength !== '' && isFinite( Number( data.maxlength ) ) ) { #> maxlength="{{ Number( data.maxlength ) }}" <# } #>
130 <# if ( data.pattern ) { #> pattern="{{ data.pattern }}" <# } #>
131 />
132 </span>
133
134 <# if ( data.help ) { #>
135 <div class="wpbc_bfb__help">{{ data.help }}</div>
136 <# } #>
137 </span>
138 </script>
139 <?php
140
141 // ============ Inspector Template ============
142 ?>
143 <script type="text/html" id="tmpl-wpbc-bfb-inspector-text">
144 <div class="wpbc_bfb__inspector__head">
145 <div class="header_container">
146 <div class="header_title_content">
147 <h3 class="title"><?php echo esc_html__( 'Text', 'booking' ); ?></h3><?php //TODO remove it. ?>
148 <div class="desc"><?php echo esc_html__( 'Configure a single-line text input.', 'booking' ); ?></div>
149 </div>
150 <div class="actions wpbc_ajx_toolbar wpbc_no_borders">
151 <div class="ui_container ui_container_small">
152 <div class="ui_group">
153 <div class="ui_element">
154 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
155 data-action="deselect" aria-label="<?php echo esc_attr__( 'Deselect', 'booking' ); ?>">
156 <i class="menu_icon icon-1x wpbc_icn_remove_done"></i>
157 </button>
158 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
159 data-action="scrollto" aria-label="<?php echo esc_attr__( 'Scroll to field', 'booking' ); ?>">
160 <i class="menu_icon icon-1x wpbc_icn_ads_click filter_center_focus"></i>
161 </button>
162 </div>
163 <div class="ui_element">
164 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
165 data-action="move-up" aria-label="<?php echo esc_attr__( 'Move up', 'booking' ); ?>">
166 <i class="menu_icon icon-1x wpbc_icn_arrow_upward"></i>
167 </button>
168 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
169 data-action="move-down" aria-label="<?php echo esc_attr__( 'Move down', 'booking' ); ?>">
170 <i class="menu_icon icon-1x wpbc_icn_arrow_downward"></i>
171 </button>
172 </div>
173 <div class="ui_element">
174 <button data-action="duplicate" aria-label="<?php echo esc_attr__( 'Duplicate', 'booking' ); ?>"
175 type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button">
176 <i class="menu_icon icon-1x wpbc_icn_content_copy"></i>
177 </button>
178 <button data-action="delete" aria-label="<?php echo esc_attr__( 'Delete', 'booking' ); ?>"
179 type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button wpbc_ui_button_danger button-link-delete" >
180 <span class="in-button-text"><?php echo esc_html__( 'Delete', 'booking' ); ?></span>&nbsp;&nbsp;
181 <i class="menu_icon icon-1x wpbc_icn_delete_outline"></i>
182 </button>
183 </div>
184 </div><!-- .ui_group -->
185 </div><!-- .ui_container -->
186 </div><!-- .actions -->
187 </div><!-- .header_container -->
188 </div><!-- .wpbc_bfb__inspector__head -->
189
190 <div class="wpbc_bfb__inspector__body">
191
192 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group is-open" data-group="basic">
193 <button type="button" class="group__header">
194 <h3><?php echo esc_html__( 'Basic', 'booking' ); ?></h3>
195 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
196 </button>
197 <div class="group__fields">
198 <div class="inspector__row">
199 <label class="inspector__label"><?php echo esc_html__( 'Label', 'booking' ); ?></label>
200 <div class="inspector__control">
201 <input type="text" class="inspector__input" data-inspector-key="label"
202 value="{{ data.label || '<?php echo esc_js( __( 'Text', 'booking' ) ); ?>' }}">
203 </div>
204 </div>
205
206 <div class="inspector__row">
207 <label class="inspector__label"><?php echo esc_html__( 'Name', 'booking' ); ?></label>
208 <div class="inspector__control">
209 <input type="text" class="inspector__input" data-inspector-key="name" placeholder="<?php esc_attr_e( 'auto — from label', 'booking' ); ?>" value="{{ data.name || '' }}">
210 </div>
211 </div>
212
213 <div class="inspector__row">
214 <label class="inspector__label"><?php echo esc_html__( 'Placeholder', 'booking' ); ?></label>
215 <div class="inspector__control">
216 <input type="text" class="inspector__input" data-inspector-key="placeholder" value="{{ data.placeholder || '' }}">
217 </div>
218 </div>
219
220 <div class="inspector__row">
221 <label class="inspector__label"><?php echo esc_html__( 'Required', 'booking' ); ?></label>
222 <div class="inspector__control">
223 <input type="checkbox" class="inspector__checkbox" data-inspector-key="required"
224 <# if ( true === data.required || 'true' === data.required || 1 === data.required || '1' === data.required ) { #> checked <# } #> >
225 </div>
226 </div>
227
228 <div class="inspector__row">
229 <label class="inspector__label"><?php echo esc_html__( 'Default value', 'booking' ); ?></label>
230 <div class="inspector__control">
231 <input type="text" class="inspector__input" data-inspector-key="default_value" value="{{ data.default_value || '' }}">
232 </div>
233 </div>
234
235 <div class="inspector__row">
236 <label class="inspector__label"><?php echo esc_html__( 'Help text', 'booking' ); ?></label>
237 <div class="inspector__control">
238 <textarea class="inspector__textarea" rows="3" data-inspector-key="help">{{ data.help || '' }}</textarea>
239 </div>
240 </div>
241 </div>
242 </section>
243
244 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group" data-group="validation">
245 <button type="button" class="group__header">
246 <h3><?php echo esc_html__( 'Validation', 'booking' ); ?></h3>
247 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
248 </button>
249 <div class="group__fields">
250 <div class="inspector__row">
251 <label class="inspector__label"><?php echo esc_html__( 'Min length', 'booking' ); ?></label>
252 <div class="inspector__control">
253 <input type="number" class="inspector__input" data-inspector-key="minlength" value="{{ data.minlength || '' }}">
254 </div>
255 </div>
256
257 <div class="inspector__row">
258 <label class="inspector__label"><?php echo esc_html__( 'Max length', 'booking' ); ?></label>
259 <div class="inspector__control">
260 <input type="number" class="inspector__input" data-inspector-key="maxlength" value="{{ data.maxlength || '' }}">
261 </div>
262 </div>
263 <?php /* // Temporary comment pattern, it can be enabled in future updates. ?>
264 <div class="inspector__row">
265 <label class="inspector__label"><?php echo esc_html__( 'Pattern', 'booking' ); ?></label>
266 <div class="inspector__control">
267 <input type="text" class="inspector__input" data-inspector-key="pattern" value="{{ data.pattern || '' }}">
268 </div>
269 </div>
270 <?php */ ?>
271 </div>
272 </section>
273
274 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group" data-group="appearance">
275 <button type="button" class="group__header">
276 <h3><?php echo esc_html__( 'Appearance', 'booking' ); ?></h3>
277 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
278 </button>
279 <div class="group__fields">
280 <div class="inspector__row">
281 <label class="inspector__label"><?php echo esc_html__( 'CSS class', 'booking' ); ?></label>
282 <div class="inspector__control">
283 <input type="text" class="inspector__input" data-inspector-key="cssclass" value="{{ data.cssclass || '' }}">
284 </div>
285 </div>
286
287 <div class="inspector__row">
288 <label class="inspector__label"><?php echo esc_html__( 'HTML ID', 'booking' ); ?></label>
289 <div class="inspector__control">
290 <input type="text" class="inspector__input" data-inspector-key="html_id" value="{{ data.html_id || '' }}">
291 </div>
292 </div>
293 </div>
294 </section>
295
296 </div><!-- .wpbc_bfb__inspector__body -->
297 </script>
298 <?php
299 }
300
301
302 /**
303 * (Optional) Register the "Text" palette item in "general/bottom".
304 *
305 * @param string $group Palette group: 'general' | 'advanced' | ...
306 * @param string $position Position: 'top' | 'bottom'
307 * @return void
308 */
309 function wpbc_bfb_palette_register_items__text_wptpl( $group, $position ) {
310
311 // Only inject into the desired palette zone.
312 if ( 'standard' !== $group || 'bottom' !== $position ) {
313 return;
314 }
315
316 ?>
317 <li class="wpbc_bfb__field"
318 data-id="text"
319 data-type="text"
320 data-usage_key="text"
321 data-label="<?php echo esc_attr( __( 'Text', 'booking' ) ); ?>">
322 <i class="menu_icon icon-1x wpbc-bi-input-cursor-text"></i>
323 <span class="wpbc_bfb__field-label"><?php echo esc_html( __( 'Text', 'booking' ) ); ?></span>
324 <span class="wpbc_bfb__field-type">text - wp.tpl</span>
325 </li>
326 <?php
327 }
328 add_action( 'wpbc_bfb_palette_register_items', 'wpbc_bfb_palette_register_items__text_wptpl', 10, 2 );
329