mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-29 23:57:41 +02:00
Editor: Use WP_HTML_Tag_Processor
in wp_render_elements_support()
.
Props ntsekouras. Fixes #57642. Built from https://develop.svn.wordpress.org/trunk@55235 git-svn-id: http://core.svn.wordpress.org/trunk@54768 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
53c7f7a8a7
commit
ee7b88a862
@ -56,29 +56,14 @@ function wp_render_elements_support( $block_content, $block ) {
|
|||||||
return $block_content;
|
return $block_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
$class_name = wp_get_elements_class_name( $block );
|
|
||||||
|
|
||||||
// Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
|
// Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
|
||||||
// Retrieve the opening tag of the first HTML element.
|
// Add the class name to the first element, presuming it's the wrapper, if it exists.
|
||||||
$html_element_matches = array();
|
$tags = new WP_HTML_Tag_Processor( $block_content );
|
||||||
preg_match( '/<[^>]+>/', $block_content, $html_element_matches, PREG_OFFSET_CAPTURE );
|
if ( $tags->next_tag() ) {
|
||||||
$first_element = $html_element_matches[0][0];
|
$tags->add_class( wp_get_elements_class_name( $block ) );
|
||||||
// If the first HTML element has a class attribute just add the new class
|
|
||||||
// as we do on layout and duotone.
|
|
||||||
if ( strpos( $first_element, 'class="' ) !== false ) {
|
|
||||||
$content = preg_replace(
|
|
||||||
'/' . preg_quote( 'class="', '/' ) . '/',
|
|
||||||
'class="' . $class_name . ' ',
|
|
||||||
$block_content,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// If the first HTML element has no class attribute we should inject the attribute before the attribute at the end.
|
|
||||||
$first_element_offset = $html_element_matches[0][1];
|
|
||||||
$content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $content;
|
return $tags->get_updated_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-alpha-55234';
|
$wp_version = '6.2-alpha-55235';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user