use_block_editor_for_post() WordPress Function

The use_block_editor_for_post() function allows you to decide whether or not to use the block editor for a particular post. This can be useful if you want to use the classic editor for a specific post, or if you want to disable the block editor entirely.

use_block_editor_for_post( int|WP_Post $post ) #

Returns whether the post can be edited in the block editor.


Parameters

$post

(int|WP_Post)(Required)Post ID or WP_Post object.


Top ↑

Return

(bool) Whether the post can be edited in the block editor.


Top ↑

Source

File: wp-admin/includes/post.php

function use_block_editor_for_post( $post ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	// We're in the meta box loader, so don't use the block editor.
	if ( isset( $_GET['meta-box-loader'] ) ) {
		check_admin_referer( 'meta-box-loader', 'meta-box-loader-nonce' );
		return false;
	}

	$use_block_editor = use_block_editor_for_post_type( $post->post_type );

	/**
	 * 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 can be edited or not.
	 * @param WP_Post $post             The post being checked.
	 */
	return apply_filters( 'use_block_editor_for_post', $use_block_editor, $post );
}


Top ↑

Changelog

Changelog
VersionDescription
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More