Skip to content

Commit

Permalink
Plugin: Remove core-defined block detection functions (#13467)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored Jan 25, 2019
1 parent ef1c0e8 commit af916f0
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,32 +310,6 @@ function gutenberg_can_edit_post_type( $post_type ) {
return apply_filters( 'gutenberg_can_edit_post_type', $can_edit, $post_type );
}

if ( ! function_exists( 'has_blocks' ) ) {
/**
* Determine whether a post or content string has 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.
*
* @since 3.6.0
* @see gutenberg_parse_blocks()
*
* @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
* @return bool Whether the post has blocks.
*/
function has_blocks( $post = null ) {
if ( ! is_string( $post ) ) {
$wp_post = get_post( $post );
if ( $wp_post instanceof WP_Post ) {
$post = $wp_post->post_content;
}
}

return false !== strpos( (string) $post, '<!-- wp:' );
}
}

/**
* Determine whether a post has blocks. This test optimizes for performance
* rather than strict accuracy, detecting the pattern of a block but not
Expand Down Expand Up @@ -374,35 +348,6 @@ function gutenberg_content_has_blocks( $content ) {
return has_blocks( $content );
}

if ( ! function_exists( 'has_block' ) ) {
/**
* Determine whether a $post or a string contains a specific block type.
* This test optimizes for performance rather than strict accuracy, detecting
* the block type exists but not validating its structure.
* For strict accuracy, you should use the block parser on post content.
*
* @since 3.6.0
*
* @param string $block_type Full Block type to look for.
* @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
* @return bool Whether the post content contains the specified block.
*/
function has_block( $block_type, $post = null ) {
if ( ! has_blocks( $post ) ) {
return false;
}

if ( ! is_string( $post ) ) {
$wp_post = get_post( $post );
if ( $wp_post instanceof WP_Post ) {
$post = $wp_post->post_content;
}
}

return false !== strpos( $post, '<!-- wp:' . $block_type . ' ' );
}
}

/**
* Returns the current version of the block format that the content string is using.
*
Expand Down

0 comments on commit af916f0

Please sign in to comment.