start_controls_section( 'section_vehicle_types', array( 'label' => __( 'Vehicle Types', 'ab-veh-take' ), ) ); $repeater = new \Elementor\Repeater(); $repeater->add_control( 'vehicle_name', array( 'type' => \Elementor\Controls_Manager::TEXT, 'label' => __( 'Vehicle Name', 'ab-veh-take' ), 'placeholder' => __( 'e.g. Van', 'ab-veh-take' ), 'default' => '', ) ); $default_vehicle_rows = array(); foreach ( AB_Veh_Take_Settings::get_vehicle_types() as $type ) { $default_vehicle_rows[] = array( 'vehicle_name' => $type ); } $this->add_control( 'vehicle_types', array( 'type' => \Elementor\Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), 'default' => $default_vehicle_rows, 'title_field' => '{{{ vehicle_name }}}', 'prevent_empty' => false, 'description' => __( 'Add, remove, rename, or reorder the vehicle options for this form. Leave empty to use the global default from the plugin Settings page.', 'ab-veh-take' ), ) ); $this->end_controls_section(); /* ---------------- Layout ---------------- */ $this->start_controls_section( 'section_layout', array( 'label' => __( 'Layout', 'ab-veh-take' ), ) ); foreach ( AB_Veh_Take_Settings::layout_fields() as $key => $field ) { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::NUMBER, 'label' => $field['label'], 'min' => $field['min'], 'max' => $field['max'], 'default' => $field['default'], 'description' => $field['description'], ) ); } $this->end_controls_section(); /* ---------------- Typography ---------------- */ $this->start_controls_section( 'section_typography', array( 'label' => __( 'Typography', 'ab-veh-take' ), ) ); foreach ( AB_Veh_Take_Settings::typography_fields() as $key => $field ) { if ( 'font_family' === $key ) { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::TEXT, 'label' => $field['label'], 'default' => $field['default'], 'description' => __( 'CSS font-family name (e.g. Manrope, Montserrat, Inter, system-ui).', 'ab-veh-take' ), ) ); } elseif ( false !== strpos( $key, 'weight' ) ) { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::SELECT, 'label' => $field['label'], 'default' => $field['default'], 'options' => array( '300' => '300', '400' => '400', '500' => '500', '600' => '600', '700' => '700', '800' => '800', '900' => '900', ), ) ); } else { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::NUMBER, 'label' => $field['label'], 'min' => $field['min'], 'max' => $field['max'], 'step' => $field['step'] ?? 1, 'default' => $field['default'], ) ); } } $this->end_controls_section(); /* ---------------- Colors ---------------- */ $this->start_controls_section( 'section_colors', array( 'label' => __( 'Colors', 'ab-veh-take' ), ) ); foreach ( AB_Veh_Take_Settings::color_fields() as $key => $field ) { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::COLOR, 'label' => $field['label'], 'default' => $field['default'], ) ); } $this->end_controls_section(); /* ---------------- Content & Text ---------------- */ $this->start_controls_section( 'section_text', array( 'label' => __( 'Form Text', 'ab-veh-take' ), ) ); foreach ( AB_Veh_Take_Settings::text_fields() as $key => $field ) { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::TEXT, 'label' => $field['label'], 'default' => $field['default'], ) ); } foreach ( AB_Veh_Take_Settings::content_fields() as $key => $field ) { $this->add_control( $key, array( 'type' => \Elementor\Controls_Manager::TEXT, 'label' => $field['label'], 'default' => $field['default'], ) ); } $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); // Normalize vehicles repeater into a plain string array $vehicles = array(); if ( ! empty( $settings['vehicle_types'] ) && is_array( $settings['vehicle_types'] ) ) { foreach ( $settings['vehicle_types'] as $row ) { if ( is_array( $row ) && ! empty( $row['vehicle_name'] ) && is_scalar( $row['vehicle_name'] ) ) { $name = trim( sanitize_text_field( (string) $row['vehicle_name'] ) ); if ( '' !== $name ) { $vehicles[] = $name; } } } } // Whitelist override keys to prevent unintended data exposure $allowed_keys = array_merge( array_keys( AB_Veh_Take_Settings::layout_fields() ), array_keys( AB_Veh_Take_Settings::typography_fields() ), array_keys( AB_Veh_Take_Settings::color_fields() ), array_keys( AB_Veh_Take_Settings::text_fields() ), array_keys( AB_Veh_Take_Settings::content_fields() ) ); $overrides = array(); foreach ( $allowed_keys as $key ) { if ( isset( $settings[ $key ] ) && is_scalar( $settings[ $key ] ) && '' !== $settings[ $key ] ) { $overrides[ $key ] = $settings[ $key ]; } } if ( ! empty( $vehicles ) ) { $overrides['vehicle_types'] = $vehicles; } $shortcode = AB_Veh_Take_Shortcode::instance() ?: new AB_Veh_Take_Shortcode(); echo $shortcode->render_form( $overrides ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } }