wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema
wp_render_custom_css_class_name › WordPress Function
Desde7.0.0
Obsoleton/a
› wp_render_custom_css_class_name ( $block_content, $block )
| Parâmetros: (2) |
|
| Retorna: |
|
| Definido em: |
|
| Codex: | |
| Log de mudanças: |
|
Applies the custom CSS class name to the block's rendered HTML.
Uses the class name that Ver página de detalhe para wp_render_custom_css_support_styles »" href="https://pt.wpseek.com/function/%5Cwp_render_custom_css_support_styles/">wp_render_custom_css_support_styles stored in the block attributes. Blocks that a parent parsed and rendered itself never reach that filter, so the class name is generated here instead via Ver página de detalhe para wp_generate_custom_css_class_name »" href="https://pt.wpseek.com/function/%5Cwp_generate_custom_css_class_name/">wp_generate_custom_css_class_name.Fonte
function wp_render_custom_css_class_name( $block_content, $block ) {
$class_name_attr = $block['attrs']['className'] ?? null;
$class_name_prefix = 'wp-custom-css-';
$matched_class_name = null;
// Parse out the 'wp-custom-css-*' class name added by wp_render_custom_css_support_styles().
if ( is_string( $class_name_attr ) && str_contains( $class_name_attr, $class_name_prefix ) ) {
$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 );
}
}
// Direct WP_Block::render() calls skip render_block_data for the block itself.
if ( null === $matched_class_name ) {
$matched_class_name = wp_generate_custom_css_class_name( $block );
}
if ( null === $matched_class_name ) {
return $block_content;
}
$tags = new WP_HTML_Tag_Processor( $block_content );
if ( $tags->next_tag() ) {
$tags->add_class( 'has-custom-css' );
$tags->add_class( $matched_class_name );
}
return $tags->get_updated_html();
}