register_block_from_metadata( 'hidden' );
}
public function render( $atts ) {
if ( ! $this->allow_render_now( $atts ) ) {
return '';
}
$name = isset( $atts['name'] ) ? sanitize_key( $atts['name'] ) : 'hidden_field';
if ( '' === $name ) {
$name = 'hidden_field';
}
$value = isset( $atts['defaultValue'] ) ? (string) $atts['defaultValue'] : '';
$allow_query = ! empty( $atts['overwriteFromQuery'] );
$query_key = isset( $atts['queryKey'] ) ? trim( (string) $atts['queryKey'] ) : '';
// Prefills the field from the page URL when the form allows it; nothing is saved here.
if ( $allow_query && $query_key !== '' && isset( $_GET[ $query_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$value = sanitize_text_field( wp_unslash( $_GET[ $query_key ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
$required = ! empty( $atts['required'] );
$meta_payload = array( 'required' => $required ? 1 : 0 );
$meta_input = '';
$input = '';
// Hidden fields have no visible wrapper; still respect conditional logic by using wrapper but keeping it hidden.
$class = 'stacklar-field stacklar-field--hidden';
$style_rules = array( 'display:none;' );
$html = $this->render_wrapper_open( $atts, $class, $style_rules );
$html .= $input . $meta_input;
$html .= $this->render_wrapper_close();
return $html;
}
}