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
檢視更多 >