_wp_add_block_level_presets_class

函数
_wp_add_block_level_presets_class ( $block_content, $block )
Access
Private
参数
  • (string) $block_content Rendered block content.
    Required:
  • (array) $block Block object.
    Required:
返回值
  • (string) Filtered block content.
定义位置
相关方法
_wp_add_block_level_preset_styles_wp_get_presets_class_name_wp_block_theme_register_classic_sidebarswp_get_block_default_classnamewp_get_elements_class_name
引入
6.2.0
弃用
-

_wp_add_block_level_presets_class(): 这个函数在WordPress编辑器中根据预设的设置给一个块元素添加一个自定义的CSS类。

function _wp_add_block_level_presets_class( $block_content, $block ) {
	if ( ! $block_content ) {
		return $block_content;
	}

	// return early if the block doesn't have support for settings.
	$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
	if ( ! block_has_support( $block_type, array( '__experimentalSettings' ), false ) ) {
		return $block_content;
	}

	// return early if no settings are found on the block attributes.
	$block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
	if ( empty( $block_settings ) ) {
		return $block_content;
	}

	// Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
	// Add the class name to the first element, presuming it's the wrapper, if it exists.
	$tags = new WP_HTML_Tag_Processor( $block_content );
	if ( $tags->next_tag() ) {
		$tags->add_class( _wp_get_presets_class_name( $block ) );
	}

	return $tags->get_updated_html();
}

常见问题

FAQs
查看更多 >