wp/wp-includes/class-wp-oembed-controller.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    13  * Registers the REST API route and delivers the response data.
    13  * Registers the REST API route and delivers the response data.
    14  * The output format (XML or JSON) is handled by the REST API.
    14  * The output format (XML or JSON) is handled by the REST API.
    15  *
    15  *
    16  * @since 4.4.0
    16  * @since 4.4.0
    17  */
    17  */
       
    18 #[AllowDynamicProperties]
    18 final class WP_oEmbed_Controller {
    19 final class WP_oEmbed_Controller {
    19 	/**
    20 	/**
    20 	 * Register the oEmbed REST API route.
    21 	 * Register the oEmbed REST API route.
    21 	 *
    22 	 *
    22 	 * @since 4.4.0
    23 	 * @since 4.4.0
   157 	 * Returns the JSON object for the proxied item.
   158 	 * Returns the JSON object for the proxied item.
   158 	 *
   159 	 *
   159 	 * @since 4.8.0
   160 	 * @since 4.8.0
   160 	 *
   161 	 *
   161 	 * @see WP_oEmbed::get_html()
   162 	 * @see WP_oEmbed::get_html()
   162 	 * @global WP_Embed $wp_embed
   163 	 * @global WP_Embed   $wp_embed   WordPress Embed object.
       
   164 	 * @global WP_Scripts $wp_scripts
   163 	 *
   165 	 *
   164 	 * @param WP_REST_Request $request Full data about the request.
   166 	 * @param WP_REST_Request $request Full data about the request.
   165 	 * @return object|WP_Error oEmbed response data or WP_Error on failure.
   167 	 * @return object|WP_Error oEmbed response data or WP_Error on failure.
   166 	 */
   168 	 */
   167 	public function get_proxy_item( $request ) {
   169 	public function get_proxy_item( $request ) {
   168 		global $wp_embed;
   170 		global $wp_embed, $wp_scripts;
   169 
   171 
   170 		$args = $request->get_params();
   172 		$args = $request->get_params();
   171 
   173 
   172 		// Serve oEmbed data from cache if set.
   174 		// Serve oEmbed data from cache if set.
   173 		unset( $args['_wpnonce'] );
   175 		unset( $args['_wpnonce'] );
   201 			// Try using a classic embed, instead.
   203 			// Try using a classic embed, instead.
   202 			/* @var WP_Embed $wp_embed */
   204 			/* @var WP_Embed $wp_embed */
   203 			$html = $wp_embed->get_embed_handler_html( $args, $url );
   205 			$html = $wp_embed->get_embed_handler_html( $args, $url );
   204 
   206 
   205 			if ( $html ) {
   207 			if ( $html ) {
   206 				global $wp_scripts;
       
   207 				// Check if any scripts were enqueued by the shortcode, and include them in the response.
   208 				// Check if any scripts were enqueued by the shortcode, and include them in the response.
   208 				$enqueued_scripts = array();
   209 				$enqueued_scripts = array();
   209 
   210 
   210 				foreach ( $wp_scripts->queue as $script ) {
   211 				foreach ( $wp_scripts->queue as $script ) {
   211 					$enqueued_scripts[] = $wp_scripts->registered[ $script ]->src;
   212 					$enqueued_scripts[] = $wp_scripts->registered[ $script ]->src;