REST API: Fix PHP warnings when `get_theme_support( 'post-formats' )` is not an array.

If `add_theme_support( 'post-formats' )` is called with no additional arguments, then `get_theme_support( 'post-formats' )` returns `true` rather than an array of supported formats. Avoid generating PHP warnings in this situation.

Merge of [39620] to the 4.7 branch.

Props dreamon11, ChopinBach.
Fixes #39293.


Built from https://develop.svn.wordpress.org/branches/4.7@39630


git-svn-id: http://core.svn.wordpress.org/branches/4.7@39570 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2016-12-21 05:30:34 +00:00
parent bba21b983c
commit cf9b1dbc1f
2 changed files with 8 additions and 2 deletions

View File

@ -1923,10 +1923,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
case 'post-formats': case 'post-formats':
$supports_formats = get_theme_support( '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 );
$schema['properties']['format'] = array( $schema['properties']['format'] = array(
'description' => __( 'The format for the object.' ), 'description' => __( 'The format for the object.' ),
'type' => 'string', 'type' => 'string',
'enum' => array_merge( array( 'standard' ), $supports_formats ? array_values( $supports_formats[0] ) : array() ), 'enum' => $supported_formats,
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
); );
break; break;

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7.1-alpha-39629'; $wp_version = '4.7.1-alpha-39630';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.