use_block_editor_for_post_type()WP 5.0.0

Проверяет, поддерживает ли тип записи редактирование записей через редактор блоков (Гутенберг).

Редактор блоков зависит от REST API, поэтому если при регистрации типа записи параметр show_in_rest=false, функция вернет false.

Используйте use_block_editor_for_post( $post ), чтобы проверить поддержку для отдельной записи.

Работает на основе: post_type_supports(), get_post_type_object()
Основа для: use_block_editor_for_post()
1 раз — 0.000046 сек (очень быстро) | 50000 раз — 0.12 сек (очень быстро)
Хуки из функции

Возвращает

true|false. Вернет true, если типа записи поддерживает редактирование через блочный редактор (Гутенберг) и false в противном случае.

Использование

use_block_editor_for_post_type( $post_type );
$post_type(строка) (обязательный)
Ярлык типа записи.

Примеры

0

#1 Пример использования

Фрагмент кода из плагина "Jetpack – WP Security, Backup, Speed, & Growth":

/**
 * 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;
}

Теперь используем где-либо:

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

Список изменений

С версии 5.0.0 Введена.
С версии 6.1.0 Moved to wp-includes from wp-admin.

Код use_block_editor_for_post_type() WP 6.8.3

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