PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.1
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.1
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / form-builder / integrations / maximum-character-length.php

maximum-character-length.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.1, at form-builder/integrations/maximum-character-length.php

65 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Maximum Character Length ↔ Form Builder bridge.
4 *
5 * Injects `maximum-character-length` into allowlisted field blocks and registers
6 * the ExtraFieldPropertiesPanel control. Stored as string (legacy casts at enforce time).
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) exit;
10
11 // Loaded by wppb_fb_load_addon_integrations(); do not include directly.
12
13 /**
14 * Field types that get the Maximum Character Length control (classic updateFields allowlist).
15 *
16 * @return string[]
17 */
18 function wppb_mcl_fb_supported_field_types() {
19 return array(
20 'Input',
21 'Textarea',
22 'Default - Biographical Info',
23 'URL',
24 'Email',
25 'Default - Website',
26 );
27 }
28
29 /**
30 * Inject `maximum-character-length` into the allowlisted field blocks' schema.
31 */
32 add_filter( 'wppb_fb_block_attributes', 'wppb_mcl_fb_inject_block_attributes', 10, 3 );
33 function wppb_mcl_fb_inject_block_attributes( $attributes, $field_type, $context ) {
34 if ( ! in_array( $field_type, wppb_mcl_fb_supported_field_types(), true ) ) {
35 return $attributes;
36 }
37 if ( ! isset( $attributes['maximum-character-length'] ) ) {
38 $attributes['maximum-character-length'] = array( 'type' => 'string', 'default' => '' );
39 }
40 return $attributes;
41 }
42
43 /**
44 * Publish the client schema mirror and the editable number control.
45 */
46 add_action( 'wppb_fb_enqueue_editor_assets_late', 'wppb_mcl_fb_enqueue_editor_payload' );
47 function wppb_mcl_fb_enqueue_editor_payload() {
48 $field_types = array_intersect( wppb_mcl_fb_supported_field_types(), wppb_fb_all_field_type_labels() );
49 if ( empty( $field_types ) ) return;
50
51 $schema = array( 'maximum-character-length' => array( 'type' => 'string', 'default' => '' ) );
52 $extra = array();
53 foreach ( $field_types as $field_type ) {
54 $extra[ $field_type ] = $schema;
55 }
56 wppb_fb_extra_attributes_inline_script( $extra );
57
58 wppb_fb_register_extra_field_control( array(
59 'attribute' => 'maximum-character-length',
60 'label' => __( 'Maximum Character Length', 'profile-builder' ),
61 'help' => __( 'Specify the maximum number of characters a user can type in this field.', 'profile-builder' ),
62 'control' => 'number',
63 ) );
64 }
65