'_' . $this->get_name() . '_' . preg_replace( '/[^a-z0-9]/', '', strtolower( (string) ( $s['_id'] ?? '' ) ) ), 'type' => $this->get_field_type(), 'block' => $this->get_block_name(), 'id' => (string) ( $s['_id'] ?? '' ), 'label' => wp_strip_all_tags( (string) ( $s['title'] ?? '' ) ), 'conditions' => self::conditions_of( $s ), 'is_input' => false, ); } } /** Row of columns. */ class Columns_Block extends Layout_Block { public function get_name() { return 'columns'; } public function get_title() { return __( 'Columns', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'columns' ); } public function get_block_supports() { return array_merge( parent::get_block_supports(), array( 'inserter' => false ) ); } public function get_inner_blocks() { return array( 'allowed' => array( 'fwren/column' ), 'template' => array( array( 'fwren/column', array() ), array( 'fwren/column', array() ) ), 'orientation' => 'horizontal', ); } protected function register_layout_controls() { $this->start_controls_section( 'section_columns', array( 'label' => __( 'Columns', 'fieldwren' ) ) ); $this->add_responsive_control( 'gap', array( 'label' => __( 'Gap', 'fieldwren' ), 'type' => Controls::SLIDER, 'size_units' => array( 'px' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 80, 'step' => 1 ) ), 'selectors' => array( '{{WRAPPER}}' => '--fwren-col-gap: {{SIZE}}{{UNIT}};' ), ) ); $this->add_control( 'stack', array( 'label' => __( 'Stack on mobile', 'fieldwren' ), 'type' => Controls::SWITCHER, 'default' => 'yes', 'prefix_class' => 'fwren-stack-' ) ); $this->add_control( 'valign', array( 'label' => __( 'Vertical alignment', 'fieldwren' ), 'type' => Controls::SELECT, 'default' => 'start', 'options' => array( 'start' => __( 'Top', 'fieldwren' ), 'center' => __( 'Middle', 'fieldwren' ), 'end' => __( 'Bottom', 'fieldwren' ) ), 'selectors' => array( '{{WRAPPER}}' => 'align-items: {{VALUE}};' ) ) ); $this->end_controls_section(); } protected function add_render_attributes() { parent::add_render_attributes(); $this->add_render_attribute( '_wrapper', 'class', 'fwren-columns' ); } protected function render_layout( $content ) { echo $content; // phpcs:ignore WordPress.Security.EscapeOutput } } /** One column. */ class Column_Block extends Layout_Block { public function get_name() { return 'column'; } public function get_title() { return __( 'Column', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'align-pull-left' ); } public function get_parent() { return array( 'fwren/columns' ); } public function get_block_supports() { return array_merge( parent::get_block_supports(), array( 'inserter' => false ) ); } public function get_inner_blocks() { return array( 'allowed' => null, 'template' => array(), 'orientation' => 'vertical', ); } protected function register_layout_controls() { $this->start_controls_section( 'section_column', array( 'label' => __( 'Column', 'fieldwren' ) ) ); $this->add_responsive_control( 'col_width', array( 'label' => __( 'Width', 'fieldwren' ), 'type' => Controls::SLIDER, 'size_units' => array( '%', 'px' ), 'range' => array( '%' => array( 'min' => 5, 'max' => 100, 'step' => 1 ), 'px' => array( 'min' => 50, 'max' => 1200, 'step' => 1 ), ), 'selectors' => array( '{{WRAPPER}}' => 'flex: 0 0 {{SIZE}}{{UNIT}}; max-width: {{SIZE}}{{UNIT}};' ), ) ); $this->end_controls_section(); } protected function add_render_attributes() { parent::add_render_attributes(); $this->add_render_attribute( '_wrapper', 'class', 'fwren-column' ); } protected function render_layout( $content ) { echo '
' . $content . '
'; // phpcs:ignore WordPress.Security.EscapeOutput } } /** Section heading with description and divider. */ class Section_Block extends Layout_Block { public function get_name() { return 'section'; } public function get_title() { return __( 'Section Break', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'heading' ); } protected function register_layout_controls() { $this->start_controls_section( 'section_section', array( 'label' => __( 'Section', 'fieldwren' ) ) ); $this->add_control( 'title', array( 'label' => __( 'Title', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Section title', 'fieldwren' ) ) ); $this->add_control( 'tag', array( 'label' => __( 'HTML tag', 'fieldwren' ), 'type' => Controls::SELECT, 'default' => 'h3', 'options' => array( 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'div' => 'div' ) ) ); $this->add_control( 'description', array( 'label' => __( 'Description', 'fieldwren' ), 'type' => Controls::TEXTAREA, 'rows' => 3 ) ); $this->add_control( 'divider', array( 'label' => __( 'Show divider', 'fieldwren' ), 'type' => Controls::SWITCHER, 'default' => 'yes' ) ); $this->end_controls_section(); } protected function register_style_controls() { $this->start_controls_section( 'section_section_style', array( 'label' => __( 'Title', 'fieldwren' ), 'tab' => Controls::TAB_STYLE ) ); $this->add_control( 'title_color', array( 'label' => __( 'Color', 'fieldwren' ), 'type' => Controls::COLOR, 'selectors' => array( '{{WRAPPER}} .fwren-section__title' => 'color: {{VALUE}};' ) ) ); $this->add_group_control( Group_Controls::TYPOGRAPHY, array( 'name' => 'title_typography', 'selector' => '{{WRAPPER}} .fwren-section__title' ) ); $this->end_controls_section(); } protected function render_layout( $content ) { $s = $this->settings; $tag = in_array( $s['tag'], array( 'h2', 'h3', 'h4', 'h5', 'div' ), true ) ? $s['tag'] : 'h3'; echo '
'; if ( '' !== trim( (string) $s['title'] ) ) { printf( '<%1$s class="fwren-section__title">%2$s', esc_html( $tag ), wp_kses_post( $s['title'] ) ); } if ( '' !== trim( (string) $s['description'] ) ) { echo '
' . wp_kses_post( wpautop( $s['description'] ) ) . '
'; } echo '
'; } } /** Custom HTML (smartcodes allowed). */ class Html_Block extends Layout_Block { public function get_name() { return 'html'; } public function get_title() { return __( 'Custom HTML', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'editor-code' ); } protected function register_layout_controls() { $this->start_controls_section( 'section_html', array( 'label' => __( 'HTML', 'fieldwren' ) ) ); $this->add_control( 'html', array( 'label' => __( 'Content', 'fieldwren' ), 'type' => Controls::CODE, 'language' => 'html', 'rows' => 8, 'default' => '

' . __( 'Some helpful text.', 'fieldwren' ) . '

' ) ); $this->end_controls_section(); } protected function render_layout( $content ) { echo '
' . wp_kses_post( Renderer::is_editor() ? $this->settings['html'] : \FWREN\Smartcodes::parse_default( $this->settings['html'], Renderer::current_form_id() ) ) . '
'; } } /** Step break: everything after it is the next step. */ class Step_Block extends Layout_Block { public function get_name() { return 'step'; } public function get_title() { return __( 'Form Step', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'controls-forward' ); } public function get_keywords() { return array( 'step', 'page', 'multi step', 'wizard', 'break' ); } protected function has_conditions() { return false; } protected function register_layout_controls() { $this->start_controls_section( 'section_step', array( 'label' => __( 'Step', 'fieldwren' ) ) ); $this->add_control( 'title', array( 'label' => __( 'Title of the next step', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Step', 'fieldwren' ) ) ); $this->add_control( 'next_text', array( 'label' => __( 'Next button', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Next', 'fieldwren' ) ) ); $this->add_control( 'prev_text', array( 'label' => __( 'Previous button', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Previous', 'fieldwren' ) ) ); $this->add_control( 'first_title', array( 'label' => __( 'Title of the first step', 'fieldwren' ), 'type' => Controls::TEXT, 'description' => __( 'Only read from the first Step block.', 'fieldwren' ) ) ); $this->end_controls_section(); } public function schema( array $s ) { return array_merge( parent::schema( $s ), array( 'step_break' => true, 'next' => $s['next_text'], 'prev' => $s['prev_text'], 'first_title' => $s['first_title'] ) ); } protected function render_layout( $content ) { if ( Renderer::is_editor() ) { echo '
' . esc_html( $this->settings['next_text'] ) . ' →' . esc_html( $this->settings['title'] ) . '
'; } // On the frontend the Renderer splits steps at this block and prints the navigation. } } /** Submit button. */ class Submit_Block extends Layout_Block { public function get_name() { return 'submit'; } public function get_title() { return __( 'Submit Button', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'button' ); } protected function register_layout_controls() { $this->start_controls_section( 'section_submit', array( 'label' => __( 'Button', 'fieldwren' ) ) ); $this->add_control( 'text', array( 'label' => __( 'Text', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Submit', 'fieldwren' ) ) ); $this->add_control( 'loading_text', array( 'label' => __( 'Text while sending', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Sending…', 'fieldwren' ) ) ); $this->add_control( 'align', array( 'label' => __( 'Alignment', 'fieldwren' ), 'type' => Controls::CHOOSE, 'default' => 'left', 'options' => array( 'left' => array( 'title' => __( 'Left', 'fieldwren' ), 'icon' => 'align-left' ), 'center' => array( 'title' => __( 'Center', 'fieldwren' ), 'icon' => 'align-center' ), 'right' => array( 'title' => __( 'Right', 'fieldwren' ), 'icon' => 'align-right' ), 'justify' => array( 'title' => __( 'Full width', 'fieldwren' ), 'icon' => 'align-justify' ) ), 'prefix_class' => 'fwren-btn-align-' ) ); $this->add_control( 'icon', array( 'label' => __( 'Icon', 'fieldwren' ), 'type' => Controls::ICONS ) ); $this->end_controls_section(); } protected function register_style_controls() { $b = '{{WRAPPER}} .fwren-submit'; $this->start_controls_section( 'section_submit_style', array( 'label' => __( 'Button', 'fieldwren' ), 'tab' => Controls::TAB_STYLE ) ); $this->add_group_control( Group_Controls::TYPOGRAPHY, array( 'name' => 'btn_typography', 'selector' => $b ) ); $this->start_controls_tabs( 'btn_tabs' ); $this->start_controls_tab( 'btn_normal', array( 'label' => __( 'Normal', 'fieldwren' ) ) ); $this->add_control( 'btn_color', array( 'label' => __( 'Text color', 'fieldwren' ), 'type' => Controls::COLOR, 'selectors' => array( $b => 'color: {{VALUE}};' ) ) ); $this->add_control( 'btn_bg', array( 'label' => __( 'Background', 'fieldwren' ), 'type' => Controls::COLOR, 'selectors' => array( $b => 'background-color: {{VALUE}}; border-color: {{VALUE}};' ) ) ); $this->end_controls_tab(); $this->start_controls_tab( 'btn_hover', array( 'label' => __( 'Hover', 'fieldwren' ) ) ); $this->add_control( 'btn_color_h', array( 'label' => __( 'Text color', 'fieldwren' ), 'type' => Controls::COLOR, 'selectors' => array( $b . ':hover' => 'color: {{VALUE}};' ) ) ); $this->add_control( 'btn_bg_h', array( 'label' => __( 'Background', 'fieldwren' ), 'type' => Controls::COLOR, 'selectors' => array( $b . ':hover' => 'background-color: {{VALUE}}; border-color: {{VALUE}};' ) ) ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->add_control( 'btn_radius', array( 'label' => __( 'Border radius', 'fieldwren' ), 'type' => Controls::SLIDER, 'size_units' => array( 'px' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, 'step' => 1 ) ), 'separator' => 'before', 'selectors' => array( $b => 'border-radius: {{SIZE}}{{UNIT}};' ) ) ); $this->add_responsive_control( 'btn_padding', array( 'label' => __( 'Padding', 'fieldwren' ), 'type' => Controls::DIMENSIONS, 'size_units' => array( 'px', 'em' ), 'selectors' => array( $b => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ) ) ); $this->end_controls_section(); } public function schema( array $s ) { return array_merge( parent::schema( $s ), array( 'submit' => true ) ); } protected function render_layout( $content ) { $s = $this->settings; $icon = ! empty( $s['icon']['value'] ) || ! empty( $s['icon']['url'] ) ? $this->get_icon_html( $s['icon'] ) : ''; echo Renderer::before_submit(); // phpcs:ignore WordPress.Security.EscapeOutput echo '
'; // phpcs:ignore } } /** Where the captcha goes (type comes from settings). */ class Captcha_Block extends Layout_Block { public function get_name() { return 'captcha'; } public function get_title() { return __( 'Captcha', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'shield-alt' ); } public function get_keywords() { return array( 'recaptcha', 'hcaptcha', 'turnstile', 'spam' ); } protected function has_conditions() { return false; } protected function register_layout_controls() { $this->start_controls_section( 'section_captcha', array( 'label' => __( 'Captcha', 'fieldwren' ) ) ); $this->add_control( 'captcha_note', array( 'type' => Controls::RAW_HTML, 'raw' => esc_html__( 'Shows the captcha chosen in the form\'s Spam settings (or the global default). Without this block the captcha is placed above the submit button.', 'fieldwren' ) ) ); $this->end_controls_section(); } public function schema( array $s ) { return array_merge( parent::schema( $s ), array( 'captcha_slot' => true ) ); } protected function render_layout( $content ) { if ( Renderer::is_editor() ) { echo '
' . \FWREN\Icons::svg( 'shield-alt', 16 ) . ' ' . esc_html__( 'Captcha', 'fieldwren' ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Icons::svg() returns static bundled SVG markup. return; } echo \FWREN\Spam::captcha_markup( Renderer::current_form_id() ); // phpcs:ignore WordPress.Security.EscapeOutput Renderer::$captcha_printed = true; } } /** Save & resume later button. */ class Save_Block extends Layout_Block { public function get_name() { return 'save'; } public function get_title() { return __( 'Save & Resume Button', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'backup' ); } protected function register_layout_controls() { $this->start_controls_section( 'section_save', array( 'label' => __( 'Button', 'fieldwren' ) ) ); $this->add_control( 'text', array( 'label' => __( 'Text', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => __( 'Save and continue later', 'fieldwren' ) ) ); $this->end_controls_section(); } protected function render_layout( $content ) { echo '
'; } } /** Shortcode output. */ class Shortcode_Block extends Layout_Block { public function get_name() { return 'shortcode'; } public function get_title() { return __( 'Shortcode', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'shortcode' ); } protected function register_layout_controls() { $this->start_controls_section( 'section_shortcode', array( 'label' => __( 'Shortcode', 'fieldwren' ) ) ); $this->add_control( 'shortcode', array( 'label' => __( 'Shortcode', 'fieldwren' ), 'type' => Controls::TEXT, 'placeholder' => '[my_shortcode]' ) ); $this->end_controls_section(); } protected function render_layout( $content ) { $sc = (string) $this->settings['shortcode']; if ( Renderer::is_editor() ) { echo '
' . esc_html( $sc ? $sc : '[shortcode]' ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Icons::svg() returns static bundled SVG markup. return; } echo do_shortcode( $sc ); // phpcs:ignore WordPress.Security.EscapeOutput } } /** do_action() point for developers. */ class Hook_Block extends Layout_Block { public function get_name() { return 'hook'; } public function get_title() { return __( 'Action Hook', 'fieldwren' ); } public function get_icon() { return \FWREN\Icons::svg( 'admin-plugins' ); } protected function register_layout_controls() { $this->start_controls_section( 'section_hook', array( 'label' => __( 'Hook', 'fieldwren' ) ) ); $this->add_control( 'hook', array( 'label' => __( 'Hook name', 'fieldwren' ), 'type' => Controls::TEXT, 'default' => 'my_form_hook', 'description' => __( 'Runs do_action( "fwren/form_hook/{name}", $form_id ) here.', 'fieldwren' ) ) ); $this->end_controls_section(); } protected function render_layout( $content ) { $hook = sanitize_key( (string) $this->settings['hook'] ); if ( Renderer::is_editor() ) { echo '
do_action( fwren/form_hook/' . esc_html( $hook ) . ' )
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Icons::svg() returns static bundled SVG markup. return; } do_action( 'fwren/form_hook/' . $hook, Renderer::current_form_id() ); } }