--- a/wp/wp-includes/class-wp-oembed-controller.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/class-wp-oembed-controller.php Mon Oct 14 18:28:13 2019 +0200
@@ -31,67 +31,75 @@
*/
$maxwidth = apply_filters( 'oembed_default_width', 600 );
- register_rest_route( 'oembed/1.0', '/embed', array(
+ register_rest_route(
+ 'oembed/1.0',
+ '/embed',
array(
- 'methods' => WP_REST_Server::READABLE,
- 'callback' => array( $this, 'get_item' ),
- 'args' => array(
- 'url' => array(
- 'required' => true,
- 'sanitize_callback' => 'esc_url_raw',
- ),
- 'format' => array(
- 'default' => 'json',
- 'sanitize_callback' => 'wp_oembed_ensure_format',
- ),
- 'maxwidth' => array(
- 'default' => $maxwidth,
- 'sanitize_callback' => 'absint',
+ array(
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => array( $this, 'get_item' ),
+ 'args' => array(
+ 'url' => array(
+ 'required' => true,
+ 'sanitize_callback' => 'esc_url_raw',
+ ),
+ 'format' => array(
+ 'default' => 'json',
+ 'sanitize_callback' => 'wp_oembed_ensure_format',
+ ),
+ 'maxwidth' => array(
+ 'default' => $maxwidth,
+ 'sanitize_callback' => 'absint',
+ ),
),
),
- ),
- ) );
+ )
+ );
- register_rest_route( 'oembed/1.0', '/proxy', array(
+ register_rest_route(
+ 'oembed/1.0',
+ '/proxy',
array(
- 'methods' => WP_REST_Server::READABLE,
- 'callback' => array( $this, 'get_proxy_item' ),
- 'permission_callback' => array( $this, 'get_proxy_item_permissions_check' ),
- 'args' => array(
- 'url' => array(
- 'description' => __( 'The URL of the resource for which to fetch oEmbed data.' ),
- 'type' => 'string',
- 'required' => true,
- 'sanitize_callback' => 'esc_url_raw',
- ),
- 'format' => array(
- 'description' => __( 'The oEmbed format to use.' ),
- 'type' => 'string',
- 'default' => 'json',
- 'enum' => array(
- 'json',
- 'xml',
+ array(
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => array( $this, 'get_proxy_item' ),
+ 'permission_callback' => array( $this, 'get_proxy_item_permissions_check' ),
+ 'args' => array(
+ 'url' => array(
+ 'description' => __( 'The URL of the resource for which to fetch oEmbed data.' ),
+ 'type' => 'string',
+ 'required' => true,
+ 'sanitize_callback' => 'esc_url_raw',
+ ),
+ 'format' => array(
+ 'description' => __( 'The oEmbed format to use.' ),
+ 'type' => 'string',
+ 'default' => 'json',
+ 'enum' => array(
+ 'json',
+ 'xml',
+ ),
+ ),
+ 'maxwidth' => array(
+ 'description' => __( 'The maximum width of the embed frame in pixels.' ),
+ 'type' => 'integer',
+ 'default' => $maxwidth,
+ 'sanitize_callback' => 'absint',
+ ),
+ 'maxheight' => array(
+ 'description' => __( 'The maximum height of the embed frame in pixels.' ),
+ 'type' => 'integer',
+ 'sanitize_callback' => 'absint',
+ ),
+ 'discover' => array(
+ 'description' => __( 'Whether to perform an oEmbed discovery request for non-whitelisted providers.' ),
+ 'type' => 'boolean',
+ 'default' => true,
),
),
- 'maxwidth' => array(
- 'description' => __( 'The maximum width of the embed frame in pixels.' ),
- 'type' => 'integer',
- 'default' => $maxwidth,
- 'sanitize_callback' => 'absint',
- ),
- 'maxheight' => array(
- 'description' => __( 'The maximum height of the embed frame in pixels.' ),
- 'type' => 'integer',
- 'sanitize_callback' => 'absint',
- ),
- 'discover' => array(
- 'description' => __( 'Whether to perform an oEmbed discovery request for non-whitelisted providers.' ),
- 'type' => 'boolean',
- 'default' => true,
- ),
),
- ),
- ) );
+ )
+ );
}
/**
@@ -157,7 +165,7 @@
// Serve oEmbed data from cache if set.
unset( $args['_wpnonce'] );
$cache_key = 'oembed_' . md5( serialize( $args ) );
- $data = get_transient( $cache_key );
+ $data = get_transient( $cache_key );
if ( ! empty( $data ) ) {
return $data;
}
@@ -173,12 +181,22 @@
$args['height'] = $args['maxheight'];
}
+ // Short-circuit process for URLs belonging to the current site.
+ $data = get_oembed_response_data_for_url( $url, $args );
+
+ if ( $data ) {
+ return $data;
+ }
+
$data = _wp_oembed_get_object()->get_data( $url, $args );
if ( false === $data ) {
return new WP_Error( 'oembed_invalid_url', get_status_header_desc( 404 ), array( 'status' => 404 ) );
}
+ /** This filter is documented in wp-includes/class-oembed.php */
+ $data->html = apply_filters( 'oembed_result', _wp_oembed_get_object()->data2html( (object) $data, $url ), $url, $args );
+
/**
* Filters the oEmbed TTL value (time to live).
*