Make WordPress Core


Ignore:
Timestamp:
12/20/2016 12:55:04 AM (8 years ago)
Author:
jnylen0
Message:

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.

Props dreamon11, ChopinBach.
Fixes #39293.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r39595 r39620  
    857857        $this->assertCount( 1, $data );
    858858        $this->assertEquals( $post2, $data[0]['id'] );
     859    }
     860
     861    public function test_get_items_no_supported_post_formats() {
     862        // This causes get_theme_support( 'post-formats' ) to return `true` (not an array)
     863        add_theme_support( 'post-formats' );
     864
     865        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
     866        $response = $this->server->dispatch( $request );
     867        $data = $response->get_data();
     868
     869        // Set the expected state back for the rest of the tests.
     870        global $_wp_theme_features;
     871        unset( $_wp_theme_features['post-formats'] );
     872        add_theme_support( 'post-formats', array( 'post', 'gallery' ) );
     873
     874        $formats = array( 'standard' );
     875
     876        $this->assertEquals( $formats, $data['schema']['properties']['format']['enum'] );
    859877    }
    860878
Note: See TracChangeset for help on using the changeset viewer.