PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
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-secondname / field-text-secondname-preset.php

field-text-secondname-preset.php in Booking Calendar 11.2, at includes/page-form-builder/field-packs/text-secondname/field-text-secondname-preset.php

116 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPBC BFB Preset: Second Name (prefilled Text field)
4 *
5 * Purpose:
6 * - Adds a ready-to-use “Second Name” item to the palette that reuses the Text field pack (type="text").
7 * - Prefills ONLY these props: min_width, label, placeholder, required, help, name, cssclass.
8 *
9 * How it works:
10 * - The palette <li> carries data-* attributes mirroring field props.
11 * - On drop, the Builder merges these attributes into the new field’s data object and normalizes via the Text pack schema.
12 *
13 * File:
14 * - /includes/page-form-builder/field-packs/text-secondname/field-text-secondname-preset.php
15 *
16 * @package Booking Calendar
17 * @author wpdevelop, oplugins
18 * @since 11.0.0
19 * @modified 2025-10-19
20 * @version 1.0.0
21 */
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 /**
28 * Class-like wrapper (snake_case) for the “Second Name” prefilled Text preset.
29 */
30 class wpbc_bfb_preset_text_secondname {
31
32 /**
33 * Bootstrap — attach hooks.
34 *
35 * @return void
36 */
37 public static function init() {
38 add_action( 'wpbc_bfb_palette_register_items', array( __CLASS__, 'palette_register_items' ), 10, 2 );
39 }
40
41 /**
42 * Prefilled props for the Second Name preset.
43 *
44 * @return array Prefilled properties for the field data object.
45 */
46 public static function get_preset_props() {
47 $props = array(
48 // Renderer/type contract.
49 'type' => 'text',
50
51 // Visual / UX (prefilled).
52 'min_width' => '8em',
53 'label' => __( 'Last Name', 'booking' ),
54 'placeholder' => __( 'Example: "Smith"', 'booking' ),
55 'required' => 1,
56 'help' => __( 'Enter your last name.', 'booking' ),
57
58 // Naming / CSS (prefilled).
59 'name' => 'secondname',
60 'cssclass' => 'secondname lastname',
61 );
62
63 /**
64 * Filter: allow customizing preset props at runtime.
65 *
66 * @param array $props
67 */
68 return apply_filters( 'wpbc_bfb_preset_text_secondname_props', $props );
69 }
70
71 /**
72 * Register the prefilled “Second Name” item in the Builder palette.
73 *
74 * @param string $group Palette group slug (e.g., 'general').
75 * @param string $position Palette position (e.g., 'top' or 'bottom').
76 *
77 * @return void
78 */
79 public static function palette_register_items( $group, $position ) {
80 // User requested 'general' group.
81 if ( 'essentials' !== $group || 'top' !== $position ) {
82 return;
83 }
84
85 $props = self::get_preset_props();
86
87 // Safety esc for attributes.
88 $esc = function ( $v ) {
89 return is_scalar( $v ) ? $v : wp_json_encode( $v );
90 };
91 ?>
92 <li class="wpbc_bfb__field"
93 data-id="text-secondname"
94 data-type="text"
95 data-usage_key="text"
96 data-label="<?php echo esc_attr( $esc( $props['label'] ) ); ?>"
97
98 <?php // Prefilled props (merged into the new field’s data on drop). ?>
99 data-name="<?php echo esc_attr( $esc( $props['name'] ) ); ?>"
100 data-placeholder="<?php echo esc_attr( $esc( $props['placeholder'] ) ); ?>"
101 data-required="<?php echo esc_attr( $esc( $props['required'] ) ); ?>"
102 data-help="<?php echo esc_attr( $esc( $props['help'] ) ); ?>"
103 data-cssclass="<?php echo esc_attr( $esc( $props['cssclass'] ) ); ?>"
104 data-min_width="<?php echo esc_attr( $esc( $props['min_width'] ) ); ?>"
105 >
106 <i class="menu_icon icon-1x wpbc-bi-person"></i>
107 <span class="wpbc_bfb__field-label"><?php echo esc_html( $props['label'] ); ?></span>
108 <span class="wpbc_bfb__field-type">secondname | text</span>
109 </li>
110 <?php
111 }
112 }
113
114 // Initialize preset.
115 wpbc_bfb_preset_text_secondname::init();
116