wp_restore_image_outer_container

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

wp_restore_image_outer_container: 这是一个WordPress的函数,用于恢复WordPress定制器中一组字段的外部容器。它用于渲染一组相关选项的用户界面,并在wp_restore_group函数之前调用。

对于没有theme.json文件的主题,请确保恢复对齐图像块的外部div,以避免破坏依赖该div的样式。

function wp_restore_image_outer_container( $block_content, $block ) {
	$image_with_align = "
/# 1) everything up to the class attribute contents
(
	^s*
	<figureb
	[^>]*
	bclass=
	["']
)
# 2) the class attribute contents
(
	[^"']*
	bwp-block-imageb
	[^"']*
	b(?:alignleft|alignright|aligncenter)b
	[^"']*
)
# 3) everything after the class attribute contents
(
	["']
	[^>]*
	>
	.*
	</figure>
)/iUx";

	if (
		WP_Theme_JSON_Resolver::theme_has_support() ||
		0 === preg_match( $image_with_align, $block_content, $matches )
	) {
		return $block_content;
	}

	$wrapper_classnames = array( 'wp-block-image' );

	// If the block has a classNames attribute these classnames need to be removed from the content and added back
	// to the new wrapper div also.
	if ( ! empty( $block['attrs']['className'] ) ) {
		$wrapper_classnames = array_merge( $wrapper_classnames, explode( ' ', $block['attrs']['className'] ) );
	}
	$content_classnames          = explode( ' ', $matches[2] );
	$filtered_content_classnames = array_diff( $content_classnames, $wrapper_classnames );

	return '<div class="' . implode( ' ', $wrapper_classnames ) . '">' . $matches[1] . implode( ' ', $filtered_content_classnames ) . $matches[3] . '</div>';
}

常见问题

FAQs
查看更多 >