REST API: Allow setting post formats even if they are not supported by the theme.
A `post_format` not used by the current theme, but supported by core is not a wrong/broken piece of information. It's just not used at this point in time. Therefore we should allow setting and retrieving any of the standard post formats supported in core, even if the current theme doesn't use them. After this commit, a post's `format` value can survive a round trip through the API, which is a good general design principle for an API. Props JPry, iseulde, davidakennedy, Drivingralle. Fixes #39232. Built from https://develop.svn.wordpress.org/trunk@40120 git-svn-id: http://core.svn.wordpress.org/trunk@40057 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1989,17 +1989,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
break;
|
||||
|
||||
case 'post-formats':
|
||||
$supports_formats = get_theme_support( 'post-formats' );
|
||||
|
||||
// Force to an array. Supports formats can return true even if empty in some cases.
|
||||
$supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array();
|
||||
|
||||
$supported_formats = array_merge( array( 'standard' ), $supports_formats );
|
||||
// Get the native post formats and remove the array keys.
|
||||
$formats = array_values( get_post_format_slugs() );
|
||||
|
||||
$schema['properties']['format'] = array(
|
||||
'description' => __( 'The format for the object.' ),
|
||||
'type' => 'string',
|
||||
'enum' => $supported_formats,
|
||||
'enum' => $formats,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user