use_block_editor_for_post_type()WP 5.0.0

Checks if the post type supports editing posts via the block editor (Gutenberg).

The block editor depends on REST API, so if the post type registration parameter show_in_rest=false, the function will return false.

Use use_block_editor_for_post( $post ) to check support for a single post.

1 time — 0.000046 sec (very fast) | 50000 times — 0.12 sec (very fast)
Hooks from the function

Returns

true|false. Will return true if the post type supports editing via the block editor (Gutenberg) and false otherwise.

Usage

use_block_editor_for_post_type( $post_type );
$post_type(string) (required)
The post type slug.

Examples

0

#1 Example of usage

Code snippet from the "Jetpack – WP Security, Backup, Speed, & Growth" plugin:

/**
 * Checks whether the block editor can be used with the given post type.
 *
 * @param  string $post_type The post type to check.
 * @return bool              Whether the block editor can be used to edit the supplied post type.
 */
function can_edit_post_type( $post_type ) {
	$can_edit = false;

	if ( function_exists( 'gutenberg_can_edit_post_type' ) ) {
		$can_edit = gutenberg_can_edit_post_type( $post_type );
	} elseif ( function_exists( 'use_block_editor_for_post_type' ) ) {
		$can_edit = use_block_editor_for_post_type( $post_type );
	}

	return $can_edit;
}

Now let's use it somewhere:

$post_type = get_post_type( $post );
if ( $post_type && can_edit_post_type( $post_type ) ) {
	remember_editor( $post->ID, 'block-editor' );
}

Changelog

Since 5.0.0 Introduced.
Since 6.1.0 Moved to wp-includes from wp-admin.

use_block_editor_for_post_type() code WP 6.8.1

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 );
}