block_core_navigation_typographic_presets_backcompatibility

函数
block_core_navigation_typographic_presets_backcompatibility ( $parsed_block )
参数
  • (array) $parsed_block The block being rendered.
    Required:
返回值
  • (array) The block being rendered without typographic presets.
定义位置
相关方法
block_core_gallery_data_id_backcompatibilityblock_core_navigation_get_fallback_blocksblock_core_navigation_get_post_idsblock_core_navigation_get_menu_items_at_locationblock_core_navigation_render_submenu_icon
引入
-
弃用
-

block_core_navigation_typographic_presets_backcompatibility: 这个函数用于保持与旧版本的WordPress的向后兼容性,该版本的导航菜单使用了排版预置。它将排版预设设置转换为当前版本的WordPress中使用的新的排版设置。

过滤器,改变包含排版预设的导航块的解析属性值,直接包含该值。

function block_core_navigation_typographic_presets_backcompatibility( $parsed_block ) {
	if ( 'core/navigation' === $parsed_block['blockName'] ) {
		$attribute_to_prefix_map = array(
			'fontStyle'      => 'var:preset|font-style|',
			'fontWeight'     => 'var:preset|font-weight|',
			'textDecoration' => 'var:preset|text-decoration|',
			'textTransform'  => 'var:preset|text-transform|',
		);
		foreach ( $attribute_to_prefix_map as $style_attribute => $prefix ) {
			if ( ! empty( $parsed_block['attrs']['style']['typography'][ $style_attribute ] ) ) {
				$prefix_len      = strlen( $prefix );
				$attribute_value = &$parsed_block['attrs']['style']['typography'][ $style_attribute ];
				if ( 0 === strncmp( $attribute_value, $prefix, $prefix_len ) ) {
					$attribute_value = substr( $attribute_value, $prefix_len );
				}
				if ( 'textDecoration' === $style_attribute && 'strikethrough' === $attribute_value ) {
					$attribute_value = 'line-through';
				}
			}
		}
	}

	return $parsed_block;
}

常见问题

FAQs
查看更多 >