WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/21/2016 05:29:24 AM (4 years ago)
Author:
pento
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.

Merge of [39620] to the 4.7 branch.

Props dreamon11, ChopinBach.
Fixes #39293.

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

    r39610 r39630  
    19241924                case 'post-formats':
    19251925                    $supports_formats = get_theme_support( 'post-formats' );
     1926
     1927                    // Force to an array. Supports formats can return true even if empty in some cases.
     1928                    $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array();
     1929
     1930                    $supported_formats = array_merge( array( 'standard' ), $supports_formats );
     1931
    19261932                    $schema['properties']['format'] = array(
    19271933                        'description' => __( 'The format for the object.' ),
    19281934                        'type'        => 'string',
    1929                         'enum'        => array_merge( array( 'standard' ), $supports_formats ? array_values( $supports_formats[0] ) : array() ),
     1935                        'enum'        => $supported_formats,
    19301936                        'context'     => array( 'view', 'edit' ),
    19311937                    );
Note: See TracChangeset for help on using the changeset viewer.