use_block_editor_for_post_type

函式
use_block_editor_for_post_type ( $post_type )
引數
  • (string) $post_type The post type.
    Required:
返回值
  • (bool) Whether the post type can be edited with the block editor.
定義位置
相關方法
use_block_editor_for_post_disable_block_editor_for_navigation_post_typeuser_can_edit_post_dateget_block_editor_theme_styles_enable_content_editor_for_navigation_post_type
引入
5.0.0
棄用
-

use_block_editor_for_post_type: 此函式決定新的區塊編輯器是否應該用於特定的文章型別。

返回一個文章型別是否與區塊編輯器相容。

區塊編輯器依賴於REST API,如果文章型別沒有在REST API中顯示,那麼它就不能與區塊編輯器一起工作。

function use_block_editor_for_post_type( $post_type ) {
	if ( ! post_type_exists( $post_type ) ) {
		return false;
	}

	if ( ! post_type_supports( $post_type, 'editor' ) ) {
		return false;
	}

	$post_type_object = get_post_type_object( $post_type );
	if ( $post_type_object && ! $post_type_object->show_in_rest ) {
		return false;
	}

	/**
	 * Filters whether a post is able to be edited in the block editor.
	 *
	 * @since 5.0.0
	 *
	 * @param bool   $use_block_editor  Whether the post type can be edited or not. Default true.
	 * @param string $post_type         The post type being checked.
	 */
	return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
}

常見問題

FAQs
檢視更多 >