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/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r40136 r40137  
    991991    }
    992992
    993     public function test_get_items_no_supported_post_formats() {
    994         // This causes get_theme_support( 'post-formats' ) to return `true` (not an array)
    995         add_theme_support( 'post-formats' );
    996 
     993    public function test_get_items_all_post_formats() {
    997994        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    998995        $response = $this->server->dispatch( $request );
    999996        $data = $response->get_data();
    1000997
    1001         // Set the expected state back for the rest of the tests.
    1002         global $_wp_theme_features;
    1003         unset( $_wp_theme_features['post-formats'] );
    1004         add_theme_support( 'post-formats', array( 'post', 'gallery' ) );
    1005 
    1006         $formats = array( 'standard' );
     998        $formats = array_values( get_post_format_slugs() );
    1007999
    10081000        $this->assertEquals( $formats, $data['schema']['properties']['format']['enum'] );
     
    16521644        $request->set_body_params( $params );
    16531645        $response = $this->server->dispatch( $request );
    1654 
    1655         $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     1646        $this->assertEquals( 201, $response->get_status() );
     1647
     1648        $data = $response->get_data();
     1649        $this->assertEquals( 'link', $data['format'] );
    16561650    }
    16571651
     
    21502144        $request->set_body_params( $params );
    21512145        $response = $this->server->dispatch( $request );
    2152 
    2153         $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     2146        $this->assertEquals( 200, $response->get_status() );
     2147
     2148        $data = $response->get_data();
     2149        $this->assertEquals( 'link', $data['format'] );
    21542150    }
    21552151
Note: See TracChangeset for help on using the changeset viewer.