register_block_from_metadata( 'acceptance' ); } public function render( $atts ) { if ( ! $this->allow_render_now( $atts ) ) { return ''; } $label = isset( $atts['label'] ) ? (string) $atts['label'] : __( 'Terms & Conditions', 'stacklar-forms' ); $name = isset( $atts['name'] ) ? sanitize_key( $atts['name'] ) : 'acceptance'; if ( $name === '' ) { $name = 'acceptance'; } $description = isset( $atts['description'] ) ? (string) $atts['description'] : __( 'I agree to the terms and conditions.', 'stacklar-forms' ); $required = ! empty( $atts['required'] ); $checked = ! empty( $atts['checkedByDefault'] ); $instructions = isset( $atts['instructions'] ) ? (string) $atts['instructions'] : ''; $help_text = isset( $atts['helpText'] ) ? (string) $atts['helpText'] : ''; $label_pos = isset( $atts['labelPosition'] ) ? (string) $atts['labelPosition'] : 'top'; $class = 'stacklar-field stacklar-field--acceptance'; if ( ! empty( $atts['className'] ) ) { $class .= ' ' . sanitize_html_class( $atts['className'] ); } $width = isset( $atts['width'] ) ? intval( $atts['width'] ) : 100; $style_rules = array(); $style_rules[] = '--stacklar-field-width:' . max( 1, min( 100, $width ) ) . '%;'; if ( ! empty( $atts['hidden'] ) ) { $style_rules[] = 'display:none;'; } $label_style = $this->get_label_style( $atts ); $input_rules = $this->get_input_style_rules( $atts ); $input_style_attr = $this->build_style_attribute( $input_rules ); $id = 'stacklar-acceptance-' . $name . '-' . wp_generate_password( 6, false, false ); $instructions_id = ''; $help_id = ''; $described = array(); if ( $instructions !== '' ) { $instructions_id = 'stacklar-acceptance-instr-' . $name . '-' . wp_generate_password( 6, false, false ); $described[] = $instructions_id; } if ( $help_text !== '' ) { $help_id = 'stacklar-acceptance-help-' . $name . '-' . wp_generate_password( 6, false, false ); $described[] = $help_id; } if ( ! empty( $atts['ariaDescribedby'] ) ) { $described[] = trim( (string) $atts['ariaDescribedby'] ); } $aria_desc_attr = ! empty( $described ) ? ' aria-describedby="' . esc_attr( implode( ' ', $described ) ) . '"' : ''; $aria_label_attr = ''; if ( ! empty( $atts['ariaLabel'] ) ) { $aria_label_attr = ' aria-label="' . esc_attr( $atts['ariaLabel'] ) . '"'; } $instructions_html = ''; if ( $instructions !== '' ) { $instructions_html = '
' . nl2br( esc_html( $instructions ) ) . '
'; } $help_html = ''; if ( $help_text !== '' ) { $help_html = '' . esc_html( $help_text ) . ''; } $label_html = ''; if ( $label_pos !== 'hidden' ) { $label_html = ''; } $input_html = '