Skip to content

Commit

Permalink
Add Embed Preview support for classic embed providers (#6345)
Browse files Browse the repository at this point in the history
Fixes #3499.

Co-Authored-By: Andrew Duthie <aduth@users.noreply.github.com>
  • Loading branch information
pento and aduth committed Apr 30, 2018
1 parent 56d2968 commit 081f931
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,20 @@ function gutenberg_filter_oembed_result( $response, $handler, $request ) {
$post_id = url_to_postid( $_GET['url'] );
$data = get_oembed_response_data( $post_id, apply_filters( 'oembed_default_width', 600 ) );

if ( ! $data ) {
// Not a local post, return the original error.
return $response;
if ( $data ) {
// It's a local post!
$response = (object) $data;
} else {
// Try using a classic embed, instead.
global $wp_embed;
$html = $wp_embed->shortcode( array(), $_GET['url'] );
if ( $html ) {
return array(
'provider_name' => __( 'Embed Handler', 'gutenberg' ),
'html' => $html,
);
}
}
$response = (object) $data;
}

// Make sure the HTML is run through the oembed sanitisation routines.
Expand Down

0 comments on commit 081f931

Please sign in to comment.