返回帖子类型是否与块编辑器兼容。
原型
use_block_editor_for_post_type( string $post_type )
描述
块编辑器依赖于REST API,如果REST API中未显示帖子类型,则它将无法与块编辑器一起使用。
参数
$post_type
(string)
(Required)
帖子类型。
返回值
(bool)
是否可以使用块编辑器编辑帖子类型。
源文件
路径:wp-admin/includes/post.php
<?php
...
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;
}
/**
* Filter 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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/use_block_editor_for_post_type/