[wp-trac] [WordPress Trac] #43887: Expose Gutenberg Data Format version in the REST API
WordPress Trac
noreply at wordpress.org
Sat Apr 28 00:43:19 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):
A possible direct approach, where we explicitly set the possible values 0
or 1 instead of type casting, could be:
{{{
if ( ! empty( $schema['properties']['block'] ) ) {
$data['block'] = ( false !== strpos( $post->post_content, '<!--
wp:' ) ) ? 1 : 0;
}
}}}
where:
{{{
$schema['properties']['block'] = array(
'description' => __( 'Whether or not the object has blocks.' ),
'type' => 'integer',
'context' => array( 'view' ),
);
}}}
When Gutenberg merges into core, I guess the function
{{{gutenberg_post_has_blocks()}}} will not change it's name. So one could
use (without int typecasting):
{{{
if( function_exists( 'gutenberg_post_has_blocks' ) ) {
$data['block'] = gutenberg_post_has_blocks( $post ) ? 1 : 0;
}
}}}
with above as a fallback.
One could also consider a wrapper method like {{{check_has_block()}}} to
simplify:
{{{
if ( ! empty( $schema['properties']['block'] ) ) {
$data['block'] = $this->check_has_block( $post ) ? 1 : 0;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43887#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list