register_block_from_metadata( 'url' );
}
public function render( $atts ) {
if ( ! $this->allow_render_now( $atts ) ) {
return '';
}
$label = isset( $atts['label'] ) ? $atts['label'] : 'Website';
$name = isset( $atts['name'] ) ? $atts['name'] : 'url_field';
$name = sanitize_key( $name );
$ph = isset( $atts['placeholder'] ) ? esc_attr( $atts['placeholder'] ) : '';
$required = ! empty( $atts['required'] );
$reqAttr = $this->get_field_boolean_attr( $atts, 'required', 'required' );
$defVal = isset( $atts['defaultValue'] ) ? esc_attr( $atts['defaultValue'] ) : '';
$disabled= $this->get_field_boolean_attr( $atts, 'disabled', 'disabled' );
$readonly= $this->get_field_boolean_attr( $atts, 'readOnly', 'readonly' );
$labelPos= $this->get_field_label_position( $atts );
$class = $this->build_field_wrapper_class( 'url', $atts );
$style_rules = $this->get_field_wrapper_style_rules( $atts );
$prefix = isset( $atts['prefix'] ) ? esc_html( $atts['prefix'] ) : '';
$suffix = isset( $atts['suffix'] ) ? esc_html( $atts['suffix'] ) : '';
$help_context = $this->get_field_help_context( $atts, $name );
$ariaLabel = $this->get_field_aria_label_attr( $atts );
$ariaDesc = $help_context['aria_describedby'];
$id = 'stacklar-url-' . $name . '-' . wp_generate_password( 6, false, false );
$input_rules = $this->get_input_style_rules( $atts );
$inputStyle = $this->build_style_attribute( $input_rules );
$labelHtml = $this->render_field_label( $id, $label, $required, $labelPos, $atts );
$inputHtml = $this->render_input_wrap(
( $prefix !== '' ? ''. $prefix .'' : '' ) .
'' .
( $suffix !== '' ? ''. $suffix .'' : '' )
);
$contentHtml = $this->render_field_content( $labelHtml, $inputHtml, $labelPos, $help_context['help_html'] );
$html = $this->render_wrapper_open(
$atts,
$class,
$style_rules,
array(
'label' => '> label, .stacklar__inline > label',
'input' => 'input[type="url"]',
)
);
$html .= $contentHtml;
$html .= $this->render_wrapper_close();
return $html;
}
}