register_form_structure_controls(); $this->register_style_tab_controls(); do_action( 'frontend_admin/styles_controls', $this ); } protected function register_form_structure_controls() { $this->start_controls_section( 'fields_section', array( 'label' => __( 'Field', 'frontend-admin' ), 'tab' => Controls_Manager::TAB_CONTENT, ) ); $this->add_control( 'choose_from', array( 'label' => __( 'Choose From', 'frontend-admin' ), 'type' => Controls_Manager::SELECT, 'label_block' => true, 'options' => array( 'field_group' => __( 'Field Group', 'frontend-admin' ), 'field' => __( 'Field', 'frontend-admin' ), ), 'default' => 'field_group', ) ); $this->add_control( 'acf_field_group', array( 'label' => __( 'Select Field Group', 'frontend-admin' ), 'type' => 'fea_select', 'label_block' => true, 'action' => 'acf-field-groups', 'options' => [], 'default' => '', 'multiple' => true, 'condition' => array( 'choose_from' => 'field_group', ), ) ); $this->add_control( 'acf_field', array( 'label' => __( 'Select Field', 'frontend-admin' ), 'type' => 'fea_select', 'label_block' => true, 'action' => 'acf-fields', 'options' => [], 'default' => '', 'multiple' => true, 'condition' => array( 'choose_from' => 'field', ), ) ); //display mode $this->add_control( 'field_display_mode', array( 'label' => __( 'Display Mode', 'frontend-admin' ), 'type' => Controls_Manager::SELECT, 'default' => 'edit', 'options' => array( 'edit' => __( 'Edit', 'frontend-admin' ), 'read_only' => __( 'Read Only', 'frontend-admin' ), 'hidden' => __( 'Hidden', 'frontend-admin' ), ) ) ); //if read only, add "allow edit" option $this->add_control( 'field_inline_edit', array( 'label' => __( 'Inline Edit', 'frontend-admin' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Yes', 'frontend-admin' ), 'label_off' => __( 'No', 'frontend-admin' ), 'return_value' => 'true', 'default' => '', 'condition' => array( 'field_display_mode' => 'read_only', ), ) ); //no value placeholder textarea $this->add_control( 'no_values_message', array( 'label' => __( 'No Value Message', 'frontend-admin' ), 'type' => Controls_Manager::TEXTAREA, 'label_block' => true, 'placeholder' => __( 'Undefined Value', 'frontend-admin' ), 'dynamic' => array( 'active' => true, ), 'condition' => array( 'field_display_mode' => 'read_only', ), ) ); $this->custom_fields_control(); $this->end_controls_section(); } public function custom_fields_control( $repeater = false ) { $cf_save = 'post'; if ( $this->get_name() != 'acf_ele_form' ) { $cf_save = str_replace( array( 'new_', 'edit_', 'duplicate_' ), '', $this->get_name() ); } $controls_settings = array( 'label' => __( 'Save Custom Fields to...', 'frontend-admin' ), 'type' => Controls_Manager::SELECT, 'default' => $cf_save, ); $custom_fields_options = array( 'submission' => __( 'Submission', 'frontend-admin' ), 'post' => __( 'Post', 'frontend-admin' ), 'user' => __( 'User', 'frontend-admin' ), 'term' => __( 'Term', 'frontend-admin' ), ); if ( ! empty( fea_instance()->pro_features ) ) { $custom_fields_options['options'] = __( 'Site Options', 'frontend-admin' ); if ( class_exists( 'woocommerce' ) ) { $custom_fields_options['product'] = __( 'Product', 'frontend-admin' ); } } $controls_settings['options'] = $custom_fields_options; $this->add_control( 'custom_fields_save', $controls_settings ); } public function register_style_tab_controls() { $this->start_controls_section( 'display_section', array( 'label' => __( 'Display Options', 'frontend-admin' ), 'tab' => Controls_Manager::TAB_STYLE, ) ); $this->add_control( 'fields_spacing', array( 'label' => __( 'Spacing Between Fields', 'frontend-admin' ), 'type' => Controls_Manager::SLIDER, 'default' => array( 'size' => 20, ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 60, ), ), 'selectors' => array( '{{WRAPPER}}' => 'display:flex; flex-direction:column; gap: {{SIZE}}{{UNIT}};', ), 'size_units' => [ 'px', 'em', 'rem', 'vw', 'custom' ], ) ); //margin around fields $this->add_control( 'fields_margin', array( 'label' => __( 'Fields Margin', 'frontend-admin' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', 'em', '%' ), 'default' => array( 'top' => '0', 'right' => '0', 'bottom' => '0', 'left' => '0', 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} .acf-fields' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ) ); //padding around fields $this->add_control( 'fields_padding', array( 'label' => __( 'Fields Padding', 'frontend-admin' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', 'em', '%' ), 'selectors' => array( '{{WRAPPER}} .acf-fields' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ) ); $this->add_control( 'hide_field_labels', array( 'label' => __( 'Hide Field Labels', 'frontend-admin' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Hide', 'frontend-admin' ), 'label_off' => __( 'Show', 'frontend-admin' ), 'return_value' => 'true', 'separator' => 'before', 'selectors' => array( '{{WRAPPER}} .acf-label' => 'display: none', ), ) ); $this->add_control( 'field_label_position', array( 'label' => __( 'Label Position', 'frontend-admin' ), 'type' => Controls_Manager::SELECT, 'options' => array( 'top' => __( 'Above', 'frontend-admin' ), 'left' => __( 'Inline', 'frontend-admin' ), ), 'default' => 'top', 'condition' => array( 'hide_field_labels!' => 'true', ), ) ); $this->add_control( 'hide_mark_required', array( 'label' => __( 'Hide Required Mark', 'frontend-admin' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Hide', 'frontend-admin' ), 'label_off' => __( 'Show', 'frontend-admin' ), 'return_value' => 'true', 'condition' => array( 'hide_field_labels!' => 'true', ), 'selectors' => array( '{{WRAPPER}} .acf-required' => 'display: none', ), ) ); $this->add_control( 'field_instruction_position', array( 'label' => __( 'Instruction Position', 'frontend-admin' ), 'type' => Controls_Manager::SELECT, 'options' => array( 'label' => __( 'Above Field', 'frontend-admin' ), 'field' => __( 'Below Field', 'frontend-admin' ), ), 'default' => 'label', 'separator' => 'before', ) ); $this->add_control( 'field_seperator', array( 'label' => __( 'Field Seperator', 'frontend-admin' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Hide', 'frontend-admin' ), 'label_off' => __( 'Show', 'frontend-admin' ), 'default' => 'true', 'return_value' => 'true', 'separator' => 'before', 'selectors' => array( '{{WRAPPER}} .acf-fields>.acf-field' => 'border-top: none', '{{WRAPPER}} .acf-field[data-width]+.acf-field[data-width]' => 'border-left: none', ), ) ); $this->end_controls_section(); if ( empty( fea_instance()->pro_features ) ) { $this->start_controls_section( 'style_promo_section', array( 'label' => __( 'Styles', 'frontend-admin' ), 'tab' => Controls_Manager::TAB_STYLE, ) ); $this->add_control( 'styles_promo', array( 'type' => Controls_Manager::RAW_HTML, 'raw' => __( '

Go Pro to unlock styles.

', 'frontend-admin' ), 'content_classes' => 'acf-fields-note', ) ); $this->end_controls_section(); } else { do_action( 'frontend_admin/style_tab_settings', $this ); } } public function has_widget_inner_wrapper(): bool { return false; } /** * Render fields widget output on the frontend. * * @since 1.0.0 * @access protected */ protected function render() { global $fea_form, $fea_instance; $wg_id = $this->get_id(); $settings = $this->get_settings_for_display(); $chosen = $settings['choose_from']; if( 'field' == $chosen ){ $field_ids = $settings['acf_field'] ?? []; if( is_string( $field_ids ) ){ $field_ids = explode( ',', $field_ids ); } foreach( $field_ids as $field_id ){ $field = acf_get_field( $field_id ); $this->render_field( $field, $settings ); } return; } if( $chosen == 'field_group' ){ $form_ids = $settings['acf_field_group'] ?? []; } foreach( $form_ids as $form_id ){ $fields = acf_get_fields( $form_id ); if( $fields ){ foreach( $fields as $field ){ if( false === $field ) continue; $this->render_field( $field, $settings ); } } } } public function render_field( $field, $settings ){ global $fea_form, $fea_instance; $form_display = $fea_instance->form_display; if( $settings['field_display_mode'] == 'read_only' ){ $field['frontend_admin_display_mode'] = 'read_only'; $field['with_edit'] = $settings['field_inline_edit']; $field['no_values_message'] = $field['no_values_message'] ?? $settings['no_values_message']; } $field = $this->prepare_field( $field ); if( ! $field ) return; if( $settings['field_display_mode'] == 'read_only' ){ echo $fea_instance->dynamic_values->render_field_display( $field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rendered field markup, escaped where it is built. }else{ $form_display->render_field_wrap( $field ); $fea_form['rendered_field'] = true; } } public function prepare_field( $field ){ if( ! $field ) return false; global $fea_form, $fea_instance; $form_display = $fea_instance->form_display; $field['builder'] = 'elementor'; $field = $form_display->get_field_data_type( $field, $fea_form ); if( ! $field ) return false; if ( ! isset( $field['value'] ) || $field['value'] === null ) { $field = $form_display->get_field_value( $field, $fea_form ); } return $field; } }