PluginProbe
Booking Calendar / 11.4
Booking Calendar v11.4
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 / page-form-builder / field-packs / static-text / field-static-text.php

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

201 lines 7.7 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: Static Text (label / paragraph / heading) — Schema-driven, Factory Inspector
4 *
5 * Purpose:
6 * - Non-interactive text block for headings, labels, paragraphs, etc.
7 * - One pack type "static_text" with props: text, tag, align, bold, italic, html_allowed, nl2br, cssclass_extra, html_id, help.
8 * - Inspector is Factory-driven (no WP templates). Preview is rendered by a pure JS renderer class.
9 * - Exporter (JS) emits plain HTML (optionally wrapped with id/class) + optional help.
10 *
11 * Contracts Used:
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 * Files:
17 * ../includes/page-form-builder/field-packs/static-text/field-static-text.php (this file)
18 * ../includes/page-form-builder/field-packs/static-text/_out/static-text.js (renderer + exporter glue)
19 *
20 * @package Booking Calendar
21 * @author wpdevelop
22 * @since 11.0.0
23 * @modified 2025-11-08
24 * @version 1.0.0
25 */
26
27 if ( ! defined( 'ABSPATH' ) ) {
28 exit;
29 }
30
31 /**
32 * Register the "static_text" field pack (Schema-driven Inspector).
33 *
34 * Props stored in schema:
35 * - text : string — content to show
36 * - tag : string — allowed: p,label,span,small,div,h1,h2,h3,h4,h5,h6
37 * - align : string — left|center|right
38 * - bold : int|bool — 0|1
39 * - italic : int|bool — 0|1
40 * - html_allowed : int|bool — 0|1
41 * - nl2br : int|bool — 0|1 (applies only when html_allowed=0)
42 * - cssclass_extra : string — optional extra classes for wrapper element
43 * - html_id : string — optional id
44 * - help : string — optional help text (Inspector-only, exported below content)
45 * - name : string — hidden from Inspector, stored for consistency
46 *
47 * @param array $packs Accumulated packs.
48 * @return array Modified packs with "static_text" field included.
49 */
50 function wpbc_bfb_register_field_packs__field_static_text_schema( $packs ) {
51
52 $tag_options = array(
53 'p' => __( 'Paragraph', 'booking' ),
54 'label' => __( 'Label', 'booking' ),
55 'span' => __( 'Span', 'booking' ),
56 'small' => __( 'Small', 'booking' ),
57 'div' => __( 'Div', 'booking' ),
58 'h1' => 'H1',
59 'h2' => 'H2',
60 'h3' => 'H3',
61 'h4' => 'H4',
62 'h5' => 'H5',
63 'h6' => 'H6',
64 );
65
66 $align_options = array(
67 'left' => __( 'Left', 'booking' ),
68 'center' => __( 'Center', 'booking' ),
69 'right' => __( 'Right', 'booking' ),
70 );
71
72 $packs['static_text'] = array(
73 'kind' => 'field',
74 'type' => 'static_text',
75 'label' => __( 'Static Text', 'booking' ),
76 'icon' => 'text',
77 'usage_key' => 'static_text',
78
79 // === Schema: defaults + coercion handled by Inspector/Factory ===
80 'schema' => array(
81 'props' => array(
82 'text' => array( 'type' => 'string', 'default' => __( 'Add your message here…', 'booking' ) ),
83 'tag' => array( 'type' => 'string', 'enum' => array_keys( $tag_options ), 'default' => 'p' ),
84 'align' => array( 'type' => 'string', 'enum' => array_keys( $align_options ), 'default' => 'left' ),
85 'bold' => array( 'type' => 'int', 'min' => 0, 'max' => 1, 'default' => 0 ),
86 'italic' => array( 'type' => 'int', 'min' => 0, 'max' => 1, 'default' => 0 ),
87 'html_allowed' => array( 'type' => 'int', 'min' => 0, 'max' => 1, 'default' => 0 ),
88 'nl2br' => array( 'type' => 'int', 'min' => 0, 'max' => 1, 'default' => 1 ),
89 'cssclass_extra' => array( 'type' => 'string', 'default' => '' ),
90 'html_id' => array( 'type' => 'string', 'default' => '' ),
91 'help' => array( 'type' => 'string', 'default' => '' ),
92 // "name" is supported in storage but hidden in Inspector.
93 'name' => array( 'type' => 'string', 'default' => '' ),
94 ),
95 ),
96
97 // === Inspector UI (Factory-driven) ===
98 'inspector_ui' => array(
99 'title' => __( 'Static Text', 'booking' ),
100 'description' => __( 'Non-interactive text block (paragraph, label, or heading).', 'booking' ),
101 'header_variant' => 'toolbar',
102 'header_actions' => array( 'deselect', 'scrollto', 'move-up', 'move-down', 'duplicate', 'delete' ),
103 'groups' => array(
104 array(
105 'key' => 'content',
106 'label' => __( 'Content', 'booking' ),
107 'open' => true,
108 'controls' => array(
109 array(
110 'type' => 'textarea',
111 'key' => 'text',
112 'label' => __( 'Text', 'booking' ),
113 'rows' => 3,
114 'placeholder' => __( 'Enter text', 'booking' ) . '...',
115 ),
116 array(
117 'type' => 'select',
118 'key' => 'tag',
119 'label' => __( 'HTML Tag', 'booking' ),
120 'options' => $tag_options,
121 ),
122 array(
123 'type' => 'select',
124 'key' => 'align',
125 'label' => __( 'Alignment', 'booking' ),
126 'options' => $align_options,
127 ),
128 array( 'type' => 'checkbox', 'key' => 'bold', 'label' => __( 'Bold', 'booking' ) ),
129 array( 'type' => 'checkbox', 'key' => 'italic', 'label' => __( 'Italic', 'booking' ) ),
130 // array( 'type' => 'checkbox', 'key' => 'html_allowed', 'label' => __( 'Allow basic HTML', 'booking' ) ),
131 array( 'type' => 'checkbox', 'key' => 'nl2br', 'label' => __( 'Convert newlines to <br> tag', 'booking' ) ),
132 ),
133 ),
134 array(
135 'key' => 'advanced',
136 'label' => __( 'Advanced', 'booking' ),
137 'controls' => array(
138 array( 'type' => 'text', 'key' => 'cssclass_extra', 'label' => __( 'Extra CSS classes', 'booking' ) ),
139 // "name" intentionally omitted from Inspector
140 array( 'type' => 'text', 'key' => 'html_id', 'label' => __( 'HTML ID', 'booking' ) ),
141 // array( 'type' => 'textarea', 'key' => 'help', 'label' => __( 'Help text', 'booking' ), 'rows' => 3 ),
142 ),
143 ),
144 ),
145 ),
146 );
147
148 return $packs;
149 }
150 add_filter( 'wpbc_bfb_register_field_packs', 'wpbc_bfb_register_field_packs__field_static_text_schema' );
151
152 /**
153 * Enqueue the Static Text field pack assets for the Builder page.
154 *
155 * @param string $page Current admin page slug (unused, provided for parity with other packs).
156 * @return void
157 */
158 function wpbc_bfb_enqueue__field_static_text_assets( $page ) {
159
160 wp_enqueue_script(
161 'wpbc-bfb_field_static_text',
162 wpbc_plugin_url( '/includes/page-form-builder/field-packs/static-text/_out/static-text.js' ),
163 array( 'wpbc-bfb' ),
164 WP_BK_VERSION_NUM,
165 true
166 );
167 }
168 add_action( 'wpbc_enqueue_js_field_pack', 'wpbc_bfb_enqueue__field_static_text_assets', 10, 1 );
169
170 /**
171 * (Optional) Register a palette item.
172 *
173 * @param string $group Palette group (e.g., 'general', 'structure').
174 * @param string $position Position: 'top' | 'bottom'.
175 * @return void
176 */
177 function wpbc_bfb_palette_register_items__static_text_schema( $group, $position ) {
178
179 if ( 'essentials' !== $group || 'top' !== $position ) {
180 return;
181 }
182 ?>
183 <li class="wpbc_bfb__field"
184 data-id="static_text"
185 data-type="static_text"
186 data-usage_key="static_text"
187 data-text="<?php echo esc_attr( __( 'Add your message here…', 'booking' ) ); ?>"
188 data-tag="p"
189 data-align="left"
190 data-bold="0"
191 data-italic="0"
192 data-html_allowed="0"
193 data-nl2br="1">
194 <i class="menu_icon icon-1x wpbc-bi-fonts"></i>
195 <span class="wpbc_bfb__field-label"><?php echo esc_html( __( 'Static Text', 'booking' ) ); ?></span>
196 <span class="wpbc_bfb__field-type">static_text</span>
197 </li>
198 <?php
199 }
200 add_action( 'wpbc_bfb_palette_register_items', 'wpbc_bfb_palette_register_items__static_text_schema', 10, 2 );
201