Skip to content

Add has_block() function #3773

Closed
Closed

Description

Issue Overview

The idea is to add an has_block() function or similar to check if a post uses a specific block. This would be similar to the has_shortcode() function.

Possible Solution

Implementation could be similar to the gutenberg_content_has_blocks() function:

function gutenberg_content_has_blocks( $content ) {

This function is optimized for speed and simply uses strpos to check for <!-- wp:. has_block() could similarly check for <!-- wp:blockname.

Alternatively, we could load all of the blocks for the post and loop through them until we found a block with that name. Maybe both implementations should be available (different functions or use a flag parameter) for different use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    FrameworkIssues related to broader framework topics, especially as it relates to javascript[Feature] Block APIAPI that allows to express the block paradigm.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions