use_block_editor_for_post_type()
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.
Used By: use_block_editor_for_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
#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. |