[wp-trac] [WordPress Trac] #43887: Expose Gutenberg Data Format version in the REST API

WordPress Trac noreply at wordpress.org
Fri Apr 27 23:45:24 UTC 2018


#43887: Expose Gutenberg Data Format version in the REST API
------------------------------------------+-----------------------
 Reporter:  danielbachhuber               |       Owner:  (none)
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:  5.0
Component:  REST API                      |     Version:
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:  rest-api
------------------------------------------+-----------------------

Comment (by birgire):

 For
 [https://github.com/WordPress/gutenberg/blob/3c54f0419dbef912878334340c4af5995f4a6991/lib/register.php#L313
 reference] here are Gutenberg's functions to determine if the post or the
 content has blocks:

 {{{
 /**
  * Determine whether a post 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.
  *
  * @see gutenberg_parse_blocks()
  *
  * @since 0.5.0
  *
  * @param object $post Post.
  * @return bool  Whether the post has blocks.
  */
 function gutenberg_post_has_blocks( $post ) {
         $post = get_post( $post );
         return $post && gutenberg_content_has_blocks( $post->post_content
 );
 }

 /**
  * Determine whether a content string contains 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 1.6.0
  * @see gutenberg_parse_blocks()
  *
  * @param string $content Content to test.
  * @return bool Whether the content contains blocks.
  */
 function gutenberg_content_has_blocks( $content ) {
         return false !== strpos( $content, '<!-- wp:' );
 }

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43887#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list