Make WordPress Core


Ignore:
Timestamp:
02/24/2017 11:29:04 PM (8 years ago)
Author:
jnylen0
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.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r40108 r40120  
    19901990
    19911991                case 'post-formats':
    1992                     $supports_formats = get_theme_support( 'post-formats' );
    1993 
    1994                     // Force to an array. Supports formats can return true even if empty in some cases.
    1995                     $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array();
    1996 
    1997                     $supported_formats = array_merge( array( 'standard' ), $supports_formats );
     1992                    // Get the native post formats and remove the array keys.
     1993                    $formats = array_values( get_post_format_slugs() );
    19981994
    19991995                    $schema['properties']['format'] = array(
    20001996                        'description' => __( 'The format for the object.' ),
    20011997                        'type'        => 'string',
    2002                         'enum'        => $supported_formats,
     1998                        'enum'        => $formats,
    20031999                        'context'     => array( 'view', 'edit' ),
    20042000                    );
Note: See TracChangeset for help on using the changeset viewer.