REST API: Use WP_REST_Request::from_url() when embedding.

See #35803.

Built from https://develop.svn.wordpress.org/trunk@36674


git-svn-id: http://core.svn.wordpress.org/trunk@36641 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan McCue 2016-02-24 04:20:25 +00:00
parent 0b7e133054
commit 937b0c3241
2 changed files with 6 additions and 22 deletions

View File

@ -532,40 +532,24 @@ class WP_REST_Server {
foreach ( $links as $item ) {
// Determine if the link is embeddable.
if ( empty( $item['embeddable'] ) || strpos( $item['href'], $api_root ) !== 0 ) {
if ( empty( $item['embeddable'] ) ) {
// Ensure we keep the same order.
$embeds[] = array();
continue;
}
// Run through our internal routing and serve.
$route = substr( $item['href'], strlen( untrailingslashit( $api_root ) ) );
$query_params = array();
// Parse out URL query parameters.
$parsed = parse_url( $route );
if ( empty( $parsed['path'] ) ) {
$request = WP_REST_Request::from_url( $item['href'] );
if ( ! $request ) {
$embeds[] = array();
continue;
}
if ( ! empty( $parsed['query'] ) ) {
parse_str( $parsed['query'], $query_params );
// Ensure magic quotes are stripped.
if ( get_magic_quotes_gpc() ) {
$query_params = stripslashes_deep( $query_params );
}
}
// Embedded resources get passed context=embed.
if ( empty( $query_params['context'] ) ) {
$query_params['context'] = 'embed';
if ( empty( $request['context'] ) ) {
$request['context'] = 'embed';
}
$request = new WP_REST_Request( 'GET', $parsed['path'] );
$request->set_query_params( $query_params );
$response = $this->dispatch( $request );
/** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36673';
$wp_version = '4.5-alpha-36674';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.