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
查看更多 >