WordPress.org

Make WordPress Core

Changeset 39353


Ignore:
Timestamp:
11/24/2016 12:07:50 AM (18 months ago)
Author:
joehoyle
Message:

REST API: Special case the “standard” post format to always be allowed.

Fixes #38916.

Location:
trunk
Files:
2 edited

Legend:

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

    r39352 r39353  
    19091909                        'description' => __( 'The format for the object.' ),
    19101910                        'type'        => 'string',
    1911                         'enum'        => $supports_formats ? array_values( $supports_formats[0] ) : array(),
     1911                        'enum'        => array_merge( array( 'standard' ), $supports_formats ? array_values( $supports_formats[0] ) : array() ),
    19121912                        'context'     => array( 'view', 'edit' ),
    19131913                    );
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r39352 r39353  
    12881288    }
    12891289
     1290    public function test_create_post_with_standard_format() {
     1291        wp_set_current_user( self::$editor_id );
     1292
     1293        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     1294        $params = $this->set_post_data( array(
     1295            'format' => 'standard',
     1296        ) );
     1297        $request->set_body_params( $params );
     1298        $response = $this->server->dispatch( $request );
     1299
     1300        $data = $response->get_data();
     1301        $new_post = get_post( $data['id'] );
     1302        $this->assertEquals( 'standard', $data['format'] );
     1303        $this->assertFalse( get_post_format( $new_post->ID ) );
     1304    }
     1305
    12901306    public function test_create_post_with_invalid_format() {
    12911307        wp_set_current_user( self::$editor_id );
     
    17521768        $this->assertEquals( 'gallery', $data['format'] );
    17531769        $this->assertEquals( 'gallery', get_post_format( $new_post->ID ) );
     1770    }
     1771
     1772    public function test_update_post_with_standard_format() {
     1773        wp_set_current_user( self::$editor_id );
     1774
     1775        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1776        $params = $this->set_post_data( array(
     1777            'format' => 'standard',
     1778        ) );
     1779        $request->set_body_params( $params );
     1780        $response = $this->server->dispatch( $request );
     1781
     1782        $data = $response->get_data();
     1783        $new_post = get_post( $data['id'] );
     1784        $this->assertEquals( 'standard', $data['format'] );
     1785        $this->assertFalse( get_post_format( $new_post->ID ) );
    17541786    }
    17551787
Note: See TracChangeset for help on using the changeset viewer.