diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/class-wp-oembed-controller.php --- a/wp/wp-includes/class-wp-oembed-controller.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/class-wp-oembed-controller.php Tue Dec 15 13:49:49 2020 +0100 @@ -36,12 +36,15 @@ '/embed', array( array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'args' => array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => '__return_true', + 'args' => array( 'url' => array( - 'required' => true, - 'sanitize_callback' => 'esc_url_raw', + 'description' => __( 'The URL of the resource for which to fetch oEmbed data.' ), + 'required' => true, + 'type' => 'string', + 'format' => 'uri', ), 'format' => array( 'default' => 'json', @@ -66,10 +69,10 @@ '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', + 'description' => __( 'The URL of the resource for which to fetch oEmbed data.' ), + 'required' => true, + 'type' => 'string', + 'format' => 'uri', ), 'format' => array( 'description' => __( 'The oEmbed format to use.' ), @@ -92,7 +95,7 @@ 'sanitize_callback' => 'absint', ), 'discover' => array( - 'description' => __( 'Whether to perform an oEmbed discovery request for non-whitelisted providers.' ), + 'description' => __( 'Whether to perform an oEmbed discovery request for unsanctioned providers.' ), 'type' => 'boolean', 'default' => true, ), @@ -110,7 +113,7 @@ * @since 4.4.0 * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|array oEmbed response data or WP_Error on failure. + * @return array|WP_Error oEmbed response data or WP_Error on failure. */ public function get_item( $request ) { $post_id = url_to_postid( $request['url'] ); @@ -191,10 +194,32 @@ $data = _wp_oembed_get_object()->get_data( $url, $args ); if ( false === $data ) { + // Try using a classic embed, instead. + global $wp_embed; + + /* @var WP_Embed $wp_embed */ + $html = $wp_embed->get_embed_handler_html( $args, $url ); + + if ( $html ) { + global $wp_scripts; + // Check if any scripts were enqueued by the shortcode, and include them in the response. + $enqueued_scripts = array(); + + foreach ( $wp_scripts->queue as $script ) { + $enqueued_scripts[] = $wp_scripts->registered[ $script ]->src; + } + + return (object) array( + 'provider_name' => __( 'Embed Handler' ), + 'html' => $html, + 'scripts' => $enqueued_scripts, + ); + } + 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 */ + /** This filter is documented in wp-includes/class-wp-oembed.php */ $data->html = apply_filters( 'oembed_result', _wp_oembed_get_object()->data2html( (object) $data, $url ), $url, $args ); /**