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/tests/phpunit/tests/rest-api.php

    r44123 r44172  
    722722        $this->assertTrue( is_array( rest_preload_api_request( 0, '/' ) ) );
    723723    }
     724
     725    function test_rest_preload_api_request_with_method() {
     726        $rest_server               = $GLOBALS['wp_rest_server'];
     727        $GLOBALS['wp_rest_server'] = null;
     728
     729        $preload_paths = array(
     730            '/wp/v2/types',
     731            array( '/wp/v2/media', 'OPTIONS' ),
     732        );
     733
     734        $preload_data = array_reduce(
     735            $preload_paths,
     736            'rest_preload_api_request',
     737            array()
     738        );
     739
     740        $this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS' ) );
     741        $this->assertTrue( isset( $preload_data['OPTIONS']['/wp/v2/media'] ) );
     742
     743        $GLOBALS['wp_rest_server'] = $rest_server;
     744    }
    724745}
Note: See TracChangeset for help on using the changeset viewer.