_block_template_render_without_post_block_context

函式
_block_template_render_without_post_block_context ( $context )
Access
Private
引數
  • (array) $context Default context.
    Required:
返回值
  • (array) Filtered context.
定義位置
相關方法
_block_template_render_title_tag_build_block_template_result_from_file_build_block_template_result_from_postblock_core_comment_template_render_comments_block_template_viewport_meta_tag
引入
5.8.0
棄用
-

_block_template_render_without_post_block_context: 這個函式用於在沒有post block的情況下渲染一個block模板。它用於在塊編輯器中渲染塊模板的預覽。

在渲染區塊模板時,從區塊上下文中刪除文章細節。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _block_template_render_without_post_block_context( $context ) {
/*
* When loading a template directly and not through a page that resolves it,
* the top-level post ID and type context get set to that of the template.
* Templates are just the structure of a site, and they should not be available
* as post context because blocks like Post Content would recurse infinitely.
*/
if ( isset( $context['postType'] ) && 'wp_template' === $context['postType'] ) {
unset( $context['postId'] );
unset( $context['postType'] );
}
return $context;
}
function _block_template_render_without_post_block_context( $context ) { /* * When loading a template directly and not through a page that resolves it, * the top-level post ID and type context get set to that of the template. * Templates are just the structure of a site, and they should not be available * as post context because blocks like Post Content would recurse infinitely. */ if ( isset( $context['postType'] ) && 'wp_template' === $context['postType'] ) { unset( $context['postId'] ); unset( $context['postType'] ); } return $context; }
function _block_template_render_without_post_block_context( $context ) {
	/*
	 * When loading a template directly and not through a page that resolves it,
	 * the top-level post ID and type context get set to that of the template.
	 * Templates are just the structure of a site, and they should not be available
	 * as post context because blocks like Post Content would recurse infinitely.
	 */
	if ( isset( $context['postType'] ) && 'wp_template' === $context['postType'] ) {
		unset( $context['postId'] );
		unset( $context['postType'] );
	}

	return $context;
}

常見問題

FAQs
檢視更多 >