__CLASS__, 'attributes' => $attributes, 'block_ids' => self::$block_ids, ] ); if ( class_exists( 'WP_HTML_Tag_Processor' ) ) { $processor = new WP_HTML_Tag_Processor( $block_content ); $tag_name = $is_group ? 'legend' : 'label'; if ( $processor->next_tag( $tag_name ) ) { if ( ! $is_group ) { $processor->set_attribute( 'for', GenerateBlocks_Block_Form_Field::get_field_id( $unique_id, $field_name ) ); } $block_content = $processor->get_updated_html(); } } return $required ? self::append_required_marker( $block_content, $is_group ? 'legend' : 'label' ) : $block_content; } /** * Append the runtime required marker inside the saved label/legend markup. * * @param string $html Label block HTML. * @param string $tag_name Label tag name. * @return string */ private static function append_required_marker( $html, $tag_name ) { if ( false !== strpos( $html, 'gb-form-field__required' ) ) { return $html; } $tag_name = tag_escape( $tag_name ); $updated = preg_replace( sprintf( '#\s*$#i', preg_quote( $tag_name, '#' ) ), '', $html, 1 ); return is_string( $updated ) ? $updated : $html; } }