has_blocks()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
has_blocks( int|string|WP_Post|null $post = null ): bool
Описание
Эта проверка оптимизирована для скорости, а не для строгой точности: она обнаруживает шаблон блока, но не проверяет его структуру. Для строгой точности следует применять парсер блоков к содержимому записи.
См. alsoparse_blocks()
Оригинал (английский)
This test optimizes for performance rather than strict accuracy, detecting the pattern of a block but not validating its structure. For strict accuracy, you should use the block parser on post content.
Параметры
$post
int|string|WP_Post|null
необязательный
= null
Возвращаемое значение
bool
Исходный код
wp-includes/blocks.php:818
function has_blocks( $post = null ) {
if ( ! is_string( $post ) ) {
$wp_post = get_post( $post );
if ( ! $wp_post instanceof WP_Post ) {
return false;
}
$post = $wp_post->post_content;
}
return str_contains( (string) $post, '<!-- wp:' );
}
История изменений
| Версия | Описание |
|---|---|
| 5.0.0 | Introduced. |

