262144 ) {
return $html;
}
$tags = new \WP_HTML_Tag_Processor( $html );
$marker = wp_generate_uuid4();
$attributes = array();
$matches = 0;
$label = null;
while ( $tags->next_tag() ) {
if ( 'wp-submit' !== $tags->get_attribute( 'id' ) ) {
continue;
}
++$matches;
if ( 'INPUT' !== $tags->get_tag() || ( $preview ? 'button' : 'submit' ) !== $tags->get_attribute( 'type' ) || ( ! $preview && 'wp-submit' !== $tags->get_attribute( 'name' ) ) || null !== $tags->get_attribute( 'data-loginstudio-submit-token' ) ) {
return $html;
}
$label = $tags->get_attribute( 'value' );
foreach ( $tags->get_attribute_names_with_prefix( '' ) as $name ) {
if ( ! preg_match( '/^[a-zA-Z_:][a-zA-Z0-9_.:-]*$/D', $name ) ) {
return $html;
}
$attributes[ $name ] = $tags->get_attribute( $name );
}
$tags->set_attribute( 'data-loginstudio-submit-token', $marker );
}
if ( 1 !== $matches || ! is_string( $label ) || '' === $label || strlen( $label ) > 320 ) {
return $html;
}
$button = '';
// The public HTML API cannot rename tags. Match quote-balanced input tokens
// only after that parser has marked the unique real target, not script text.
$count = 0;
$result = preg_replace_callback(
'~]|"[^"]*"|\'[^\']*\')*>~i',
static function ( $matched_input ) use ( $marker, $button, &$count ) {
$token = new \WP_HTML_Tag_Processor( $matched_input[0] );
if ( $token->next_tag() && $marker === $token->get_attribute( 'data-loginstudio-submit-token' ) ) {
++$count;
return $button;
}
return $matched_input[0];
},
$tags->get_updated_html()
);
return is_string( $result ) && 1 === $count ? $result : $html;
}
}