Make WordPress Core


Ignore:
Timestamp:
10/29/2018 12:23:11 AM (6 years ago)
Author:
danielbachhuber
Message:

Block Editor: Preload wp/v2/media with OPTIONS for caps check.

Also introduces a block_editor_preload_paths filter for plugins and themes to preload additional data.

Props imath, mattheu.
Fixes #45194.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api.php

    r43805 r43833  
    13441344    }
    13451345
     1346    $method = 'GET';
     1347    if ( is_array( $path ) && 2 === count( $path ) ) {
     1348        $method = end( $path );
     1349        $path   = reset( $path );
     1350
     1351        if ( ! in_array( $method, array( 'GET', 'OPTIONS' ), true ) ) {
     1352            $method = 'GET';
     1353        }
     1354    }
     1355
    13461356    $path_parts = parse_url( $path );
    13471357    if ( false === $path_parts ) {
     
    13491359    }
    13501360
    1351     $request = new WP_REST_Request( 'GET', $path_parts['path'] );
     1361    $request = new WP_REST_Request( $method, $path_parts['path'] );
    13521362    if ( ! empty( $path_parts['query'] ) ) {
    13531363        parse_str( $path_parts['query'], $query_params );
     
    13681378        }
    13691379
    1370         $memo[ $path ] = array(
    1371             'body'    => $data,
    1372             'headers' => $response->headers,
    1373         );
     1380        if ( 'OPTIONS' === $method ) {
     1381            $response = rest_send_allow_header( $response, $server, $request );
     1382
     1383            $memo[ $method ][ $path ] = array(
     1384                'body'    => $data,
     1385                'headers' => $response->headers,
     1386            );
     1387        } else {
     1388            $memo[ $path ] = array(
     1389                'body'    => $data,
     1390                'headers' => $response->headers,
     1391            );
     1392        }
    13741393    }
    13751394
Note: See TracChangeset for help on using the changeset viewer.