WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/27/2017 08:02:43 PM (3 years ago)
Author:
ocean90
Message:

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.

Merge of [40120] and [40121] to the 4.7 branch.

Props JPry, iseulde, davidakennedy, Drivingralle.
Fixes #39232.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r40136 r40137  
    19841984
    19851985                case 'post-formats':
    1986                     $supports_formats = get_theme_support( 'post-formats' );
    1987 
    1988                     // Force to an array. Supports formats can return true even if empty in some cases.
    1989                     $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array();
    1990 
    1991                     $supported_formats = array_merge( array( 'standard' ), $supports_formats );
     1986                    // Get the native post formats and remove the array keys.
     1987                    $formats = array_values( get_post_format_slugs() );
    19921988
    19931989                    $schema['properties']['format'] = array(
    19941990                        'description' => __( 'The format for the object.' ),
    19951991                        'type'        => 'string',
    1996                         'enum'        => $supported_formats,
     1992                        'enum'        => $formats,
    19971993                        'context'     => array( 'view', 'edit' ),
    19981994                    );
Note: See TracChangeset for help on using the changeset viewer.