Block Editor Filters

In WordPress 5.0, the block editor is the default editor for all post types that both:

  • When registered (or using add_post_type_support()) declare that they support the editorfeature.
  • When registered, set their show_in_rest setting to true (the default is false).

In the Gutenberg plugin, there are two filters available to determine if a particular post, or a particular post type should use the block editor. gutenberg_can_edit_post, and gutenberg_can_edit_post_type, respectively.

In WordPress 5.0, the equivalent filters are use_block_editor_for_post, and use_block_editor_for_post_type. You can use them like so:

function my_post_filter( $use_block_editor, $post ) {
	$author = get_userdata( $post->post_author );
	if ( 'pento' === $author->user_login ) {
		return (bool) random_int( 0, 1 );
	}

	return $use_block_editor;
}
add_filter( 'use_block_editor_for_post', 'my_post_filter', 10, 2 );

function my_post_type_filter( $use_block_editor, $post_type ) {
	if ( 'my_mystical_post_type' === $post_type ) {
		return false;
	}

	return $use_block_editor;
}
add_filter( 'use_block_editor_for_post_type', 'my_post_type_filter', 10, 2 );
#5-0 #dev-notes