diff --git a/lib/rest-api.php b/lib/rest-api.php index 13fda26f24d57..8f7b3fef6b324 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -87,9 +87,17 @@ function gutenberg_filter_oembed_result( $response, $handler, $request ) { global $wp_embed; $html = $wp_embed->shortcode( array(), $_GET['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 array( 'provider_name' => __( 'Embed Handler', 'gutenberg' ), 'html' => $html, + 'scripts' => $enqueued_scripts, ); } } diff --git a/packages/block-library/src/embed/index.js b/packages/block-library/src/embed/index.js index 9c9103d27dfb4..64646dcd54bb6 100644 --- a/packages/block-library/src/embed/index.js +++ b/packages/block-library/src/embed/index.js @@ -214,6 +214,7 @@ export function getEmbedEdit( title, icon ) { } const html = 'photo' === type ? this.getPhotoHtml( preview ) : preview.html; + const { scripts } = preview; const parsedUrl = parse( url ); const cannotPreview = includes( HOSTS_NO_PREVIEWS, parsedUrl.host.replace( /^www\./, '' ) ); // translators: %s: host providing embed content e.g: www.youtube.com @@ -227,6 +228,7 @@ export function getEmbedEdit( title, icon ) {
diff --git a/packages/components/src/sandbox/index.js b/packages/components/src/sandbox/index.js index bbc5097aa4624..7b90a3d59ed1a 100644 --- a/packages/components/src/sandbox/index.js +++ b/packages/components/src/sandbox/index.js @@ -180,6 +180,9 @@ class Sandbox extends Component { { this.props.title }