wpseek.com
WordPress开发者和主题制作者的搜索引擎
wp_render_elements_class_name › WordPress Function
Since6.6.0
已弃用n/a
› wp_render_elements_class_name ( $block_content, $block )
| 参数: (2) |
|
| 查看: | |
| 返回: |
|
| 定义在: |
|
| 文档: |
Ensure the elements block support class name generated, and added to block attributes, in the `render_block_data` filter gets applied to the block's markup.
源码
function wp_render_elements_class_name( $block_content, $block ) {
$class_name_attr = $block['attrs']['className'] ?? null;
$class_name_prefix = 'wp-elements-';
if ( ! is_string( $class_name_attr ) || ! str_contains( $class_name_attr, $class_name_prefix ) ) {
return $block_content;
}
// Parse out the 'wp-elements-*' class name.
$matched_class_name = null;
$token_delimiter = " \t\f\r\n";
$class_token = strtok( $class_name_attr, $token_delimiter );
while ( false !== $class_token ) {
if ( str_starts_with( $class_token, $class_name_prefix ) ) {
$matched_class_name = $class_token;
break;
}
$class_token = strtok( $token_delimiter );
}
if ( null === $matched_class_name ) {
return $block_content;
}
$tags = new WP_HTML_Tag_Processor( $block_content );
if ( $tags->next_tag() ) {
$tags->add_class( $matched_class_name );
}
return $tags->get_updated_html();
}