use_block_editor_for_post_type()
Проверяет, поддерживает ли тип записи редактирование записей через редактор блоков (Гутенберг).
Редактор блоков зависит от 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(строка) (обязательный)
- Ярлык типа записи.
Примеры
#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. |