| 1 |
<?php |
| 2 |
/** |
| 3 |
* Custom CSS Classes ↔ Form Builder bridge. |
| 4 |
* |
| 5 |
* Injects `class-field` into allowlisted field blocks and registers the |
| 6 |
* ExtraFieldPropertiesPanel control. Key already round-trips via optional_addon_properties. |
| 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 CSS Class control (classic updateFields allowlist, for parity). |
| 15 |
* |
| 16 |
* @return string[] |
| 17 |
*/ |
| 18 |
function wppb_ccc_fb_supported_field_types() { |
| 19 |
return array( |
| 20 |
'Default - Name (Heading)', 'Default - Contact Info (Heading)', 'Default - About Yourself (Heading)', |
| 21 |
'Default - Username', 'Default - First Name', 'Default - Last Name', 'Default - Nickname', |
| 22 |
'Default - E-mail', 'Default - Website', 'Default - AIM', 'Default - Yahoo IM', |
| 23 |
'Default - Jabber / Google Talk', 'Default - Password', 'Default - Repeat Password', |
| 24 |
'Default - Biographical Info', 'Default - Display name publicly as', |
| 25 |
'Heading', 'Input', 'Textarea', 'WYSIWYG', 'Select', 'Datepicker', 'Select (Multiple)', |
| 26 |
'Checkbox', 'Radio', 'Upload', 'Phone', 'Timepicker', 'Colorpicker', 'Validation', |
| 27 |
'Select (User Role)', 'Select (CPT)', 'Select (Timezone)', 'Select (Country)', 'Select (Currency)', |
| 28 |
'Email', 'URL', 'GDPR Checkbox', 'GDPR Delete Button', 'Map', 'Number', 'Avatar', |
| 29 |
'Input (Hidden)', 'International Telephone Input', 'Language', 'HTML', 'Select2', |
| 30 |
'Checkbox (Terms and Conditions)', 'reCAPTCHA', 'Select2 (Multiple)', 'Honeypot', 'Email Confirmation', |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Inject `class-field` into the allowlisted field blocks' schema. |
| 36 |
*/ |
| 37 |
add_filter( 'wppb_fb_block_attributes', 'wppb_ccc_fb_inject_block_attributes', 10, 3 ); |
| 38 |
function wppb_ccc_fb_inject_block_attributes( $attributes, $field_type, $context ) { |
| 39 |
if ( ! in_array( $field_type, wppb_ccc_fb_supported_field_types(), true ) ) { |
| 40 |
return $attributes; |
| 41 |
} |
| 42 |
if ( ! isset( $attributes['class-field'] ) ) { |
| 43 |
$attributes['class-field'] = array( 'type' => 'string', 'default' => '' ); |
| 44 |
} |
| 45 |
return $attributes; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Publish the client schema mirror and the editable text control. |
| 50 |
*/ |
| 51 |
add_action( 'wppb_fb_enqueue_editor_assets_late', 'wppb_ccc_fb_enqueue_editor_payload' ); |
| 52 |
function wppb_ccc_fb_enqueue_editor_payload() { |
| 53 |
$field_types = array_intersect( wppb_ccc_fb_supported_field_types(), wppb_fb_all_field_type_labels() ); |
| 54 |
if ( empty( $field_types ) ) return; |
| 55 |
|
| 56 |
$schema = array( 'class-field' => array( 'type' => 'string', 'default' => '' ) ); |
| 57 |
$extra = array(); |
| 58 |
foreach ( $field_types as $field_type ) { |
| 59 |
$extra[ $field_type ] = $schema; |
| 60 |
} |
| 61 |
wppb_fb_extra_attributes_inline_script( $extra ); |
| 62 |
|
| 63 |
wppb_fb_register_extra_field_control( array( |
| 64 |
'attribute' => 'class-field', |
| 65 |
'label' => __( 'CSS Class', 'profile-builder' ), |
| 66 |
'help' => __( 'Add a class to a field. Should not contain dots(.) and for multiple classes separate by space.', 'profile-builder' ), |
| 67 |
'control' => 'text', |
| 68 |
) ); |
| 69 |
} |
| 70 |
|