Make WordPress Core


Ignore:
Timestamp:
12/14/2018 06:01:24 AM (6 years ago)
Author:
pento
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.

Merges [43833] from the 5.0 branch to trunk.

Props imath, mattheu, danielbachhuber.
Fixes #45194.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/rest-api.php

    r44150 r44172  
    13431343    }
    13441344
     1345    $method = 'GET';
     1346    if ( is_array( $path ) && 2 === count( $path ) ) {
     1347        $method = end( $path );
     1348        $path   = reset( $path );
     1349
     1350        if ( ! in_array( $method, array( 'GET', 'OPTIONS' ), true ) ) {
     1351            $method = 'GET';
     1352        }
     1353    }
     1354
    13451355    $path_parts = parse_url( $path );
    13461356    if ( false === $path_parts ) {
     
    13481358    }
    13491359
    1350     $request = new WP_REST_Request( 'GET', $path_parts['path'] );
     1360    $request = new WP_REST_Request( $method, $path_parts['path'] );
    13511361    if ( ! empty( $path_parts['query'] ) ) {
    13521362        parse_str( $path_parts['query'], $query_params );
     
    13671377        }
    13681378
    1369         $memo[ $path ] = array(
    1370             'body'    => $data,
    1371             'headers' => $response->headers,
    1372         );
     1379        if ( 'OPTIONS' === $method ) {
     1380            $response = rest_send_allow_header( $response, $server, $request );
     1381
     1382            $memo[ $method ][ $path ] = array(
     1383                'body'    => $data,
     1384                'headers' => $response->headers,
     1385            );
     1386        } else {
     1387            $memo[ $path ] = array(
     1388                'body'    => $data,
     1389                'headers' => $response->headers,
     1390            );
     1391        }
    13731392    }
    13741393
Note: See TracChangeset for help on using the changeset viewer.