Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin: Remove core-defined block detection functions #13467

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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