namespace WPForms\Forms\Fields\Html;
use WPForms\Forms\Fields\Traits\ProField as ProFieldTrait;
class Field extends WPForms_Field {
* Primary class constructor.
// Define field type information.
$this->name = esc_html__( 'HTML', 'wpforms-lite' );
$this->keywords = esc_html__( 'code', 'wpforms-lite' );
$this->allow_read_only = false;
$this->default_settings = [
protected function hooks() {
* Extend from `parent::field_option()` to add `name` option.
* @param string $option Field option to render.
* @param array $field Field data and settings.
* @param array $args Field preview arguments.
* @param bool $do_echo Print or return the value. Print by default.
* @noinspection PhpMissingReturnTypeInspection
* @noinspection ReturnTypeCanBeDeclaredInspection
public function field_option( $option, $field, $args = [], $do_echo = true ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.echoFound
if ( $option !== 'name' ) {
return parent::field_option( $option, $field, $args, $do_echo );
$output = $this->field_element(
'value' => esc_html__( 'Label', 'wpforms-lite' ),
'tooltip' => esc_html__( 'Enter text for the form field label. It will help identify your HTML blocks inside the form builder, but will not be displayed in the form.', 'wpforms-lite' ),
$output .= $this->field_element(
'value' => ! empty( $field['name'] ) ? esc_attr( $field['name'] ) : '',
$output = $this->field_element(
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
* Field options panel inside the builder.
* @param array $field Field settings.
public function field_options( $field ) {
'after_title' => $this->get_field_options_notice(),
$this->field_option( 'name', $field );
$this->field_option( 'code', $field );
// Set the label to disable.
'slug' => 'label_disable',
$this->field_element( 'text', $field, $args );
$this->field_option( 'basic-options', $field, $args );
* Advanced field options.
$this->field_option( 'advanced-options', $field, $args );
$this->field_option( 'css', $field );
$this->field_option( 'advanced-options', $field, $args );
* Field preview inside the builder.
* @param array $field Field settings.
public function field_preview( $field ) {
$label = ! empty( $field['name'] ) ? $field['name'] : '';
$label_badge = empty( $label ) ? '' : $this->get_field_preview_badge();
$code_badge = empty( $label ) ? $this->get_field_preview_badge() : '';
<label class="label-title">
<?php echo esc_html( $label ) . $label_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<i class="fa fa-code"></i>
<?php esc_html_e( 'HTML / Code Block', 'wpforms-lite' ); ?>
<?php echo $code_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="description"><?php esc_html_e( 'Contents of this field are not displayed in the form builder preview.', 'wpforms-lite' ); ?></div>
* Field display on the form front-end.
* @param array $field Field data and settings.
* @param array $deprecated Deprecated field attributes. Use field properties.
* @param array $form_data Form data and settings.
* @noinspection HtmlUnknownAttribute
public function field_display( $field, $deprecated, $form_data ) {