]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/embed.php
WordPress 4.5.1
[autoinstalls/wordpress.git] / wp-includes / embed.php
1 <?php
2 /**
3  * oEmbed API: Top-level oEmbed functionality
4  *
5  * @package WordPress
6  * @subpackage oEmbed
7  * @since 4.4.0
8  */
9
10 /**
11  * Registers an embed handler.
12  *
13  * Should probably only be used for sites that do not support oEmbed.
14  *
15  * @since 2.9.0
16  *
17  * @global WP_Embed $wp_embed
18  *
19  * @param string   $id       An internal ID/name for the handler. Needs to be unique.
20  * @param string   $regex    The regex that will be used to see if this handler should be used for a URL.
21  * @param callable $callback The callback function that will be called if the regex is matched.
22  * @param int      $priority Optional. Used to specify the order in which the registered handlers will
23  *                           be tested. Default 10.
24  */
25 function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
26         global $wp_embed;
27         $wp_embed->register_handler( $id, $regex, $callback, $priority );
28 }
29
30 /**
31  * Unregisters a previously-registered embed handler.
32  *
33  * @since 2.9.0
34  *
35  * @global WP_Embed $wp_embed
36  *
37  * @param string $id       The handler ID that should be removed.
38  * @param int    $priority Optional. The priority of the handler to be removed. Default 10.
39  */
40 function wp_embed_unregister_handler( $id, $priority = 10 ) {
41         global $wp_embed;
42         $wp_embed->unregister_handler( $id, $priority );
43 }
44
45 /**
46  * Creates default array of embed parameters.
47  *
48  * The width defaults to the content width as specified by the theme. If the
49  * theme does not specify a content width, then 500px is used.
50  *
51  * The default height is 1.5 times the width, or 1000px, whichever is smaller.
52  *
53  * The 'embed_defaults' filter can be used to adjust either of these values.
54  *
55  * @since 2.9.0
56  *
57  * @global int $content_width
58  *
59  * @param string $url Optional. The URL that should be embedded. Default empty.
60  *
61  * @return array Default embed parameters.
62  */
63 function wp_embed_defaults( $url = '' ) {
64         if ( ! empty( $GLOBALS['content_width'] ) )
65                 $width = (int) $GLOBALS['content_width'];
66
67         if ( empty( $width ) )
68                 $width = 500;
69
70         $height = min( ceil( $width * 1.5 ), 1000 );
71
72         /**
73          * Filter the default array of embed dimensions.
74          *
75          * @since 2.9.0
76          *
77          * @param array  $size An array of embed width and height values
78          *                     in pixels (in that order).
79          * @param string $url  The URL that should be embedded.
80          */
81         return apply_filters( 'embed_defaults', compact( 'width', 'height' ), $url );
82 }
83
84 /**
85  * Attempts to fetch the embed HTML for a provided URL using oEmbed.
86  *
87  * @since 2.9.0
88  *
89  * @see WP_oEmbed
90  *
91  * @param string $url  The URL that should be embedded.
92  * @param array  $args Optional. Additional arguments and parameters for retrieving embed HTML.
93  *                     Default empty.
94  * @return false|string False on failure or the embed HTML on success.
95  */
96 function wp_oembed_get( $url, $args = '' ) {
97         require_once( ABSPATH . WPINC . '/class-oembed.php' );
98         $oembed = _wp_oembed_get_object();
99         return $oembed->get_html( $url, $args );
100 }
101
102 /**
103  * Adds a URL format and oEmbed provider URL pair.
104  *
105  * @since 2.9.0
106  *
107  * @see WP_oEmbed
108  *
109  * @param string  $format   The format of URL that this provider can handle. You can use asterisks
110  *                          as wildcards.
111  * @param string  $provider The URL to the oEmbed provider.
112  * @param boolean $regex    Optional. Whether the `$format` parameter is in a RegEx format. Default false.
113  */
114 function wp_oembed_add_provider( $format, $provider, $regex = false ) {
115         require_once( ABSPATH . WPINC . '/class-oembed.php' );
116
117         if ( did_action( 'plugins_loaded' ) ) {
118                 $oembed = _wp_oembed_get_object();
119                 $oembed->providers[$format] = array( $provider, $regex );
120         } else {
121                 WP_oEmbed::_add_provider_early( $format, $provider, $regex );
122         }
123 }
124
125 /**
126  * Removes an oEmbed provider.
127  *
128  * @since 3.5.0
129  *
130  * @see WP_oEmbed
131  *
132  * @param string $format The URL format for the oEmbed provider to remove.
133  * @return bool Was the provider removed successfully?
134  */
135 function wp_oembed_remove_provider( $format ) {
136         require_once( ABSPATH . WPINC . '/class-oembed.php' );
137
138         if ( did_action( 'plugins_loaded' ) ) {
139                 $oembed = _wp_oembed_get_object();
140
141                 if ( isset( $oembed->providers[ $format ] ) ) {
142                         unset( $oembed->providers[ $format ] );
143                         return true;
144                 }
145         } else {
146                 WP_oEmbed::_remove_provider_early( $format );
147         }
148
149         return false;
150 }
151
152 /**
153  * Determines if default embed handlers should be loaded.
154  *
155  * Checks to make sure that the embeds library hasn't already been loaded. If
156  * it hasn't, then it will load the embeds library.
157  *
158  * @since 2.9.0
159  *
160  * @see wp_embed_register_handler()
161  */
162 function wp_maybe_load_embeds() {
163         /**
164          * Filter whether to load the default embed handlers.
165          *
166          * Returning a falsey value will prevent loading the default embed handlers.
167          *
168          * @since 2.9.0
169          *
170          * @param bool $maybe_load_embeds Whether to load the embeds library. Default true.
171          */
172         if ( ! apply_filters( 'load_default_embeds', true ) ) {
173                 return;
174         }
175
176         wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i', 'wp_embed_handler_youtube' );
177
178         wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
179
180         /**
181          * Filter the audio embed handler callback.
182          *
183          * @since 3.6.0
184          *
185          * @param callable $handler Audio embed handler callback function.
186          */
187         wp_embed_register_handler( 'audio', '#^https?://.+?\.(' . join( '|', wp_get_audio_extensions() ) . ')$#i', apply_filters( 'wp_audio_embed_handler', 'wp_embed_handler_audio' ), 9999 );
188
189         /**
190          * Filter the video embed handler callback.
191          *
192          * @since 3.6.0
193          *
194          * @param callable $handler Video embed handler callback function.
195          */
196         wp_embed_register_handler( 'video', '#^https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')$#i', apply_filters( 'wp_video_embed_handler', 'wp_embed_handler_video' ), 9999 );
197 }
198
199 /**
200  * The Google Video embed handler callback.
201  *
202  * Google Video does not support oEmbed.
203  *
204  * @see WP_Embed::register_handler()
205  * @see WP_Embed::shortcode()
206  *
207  * @param array  $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
208  * @param array  $attr    Embed attributes.
209  * @param string $url     The original URL that was matched by the regex.
210  * @param array  $rawattr The original unmodified attributes.
211  * @return string The embed HTML.
212  */
213 function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) {
214         // If the user supplied a fixed width AND height, use it
215         if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
216                 $width  = (int) $rawattr['width'];
217                 $height = (int) $rawattr['height'];
218         } else {
219                 list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] );
220         }
221
222         /**
223          * Filter the Google Video embed output.
224          *
225          * @since 2.9.0
226          *
227          * @param string $html    Google Video HTML embed markup.
228          * @param array  $matches The RegEx matches from the provided regex.
229          * @param array  $attr    An array of embed attributes.
230          * @param string $url     The original URL that was matched by the regex.
231          * @param array  $rawattr The original unmodified attributes.
232          */
233         return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&amp;hl=en&amp;fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
234 }
235
236 /**
237  * YouTube iframe embed handler callback.
238  *
239  * Catches YouTube iframe embed URLs that are not parsable by oEmbed but can be translated into a URL that is.
240  *
241  * @since 4.0.0
242  *
243  * @global WP_Embed $wp_embed
244  *
245  * @param array  $matches The RegEx matches from the provided regex when calling
246  *                        wp_embed_register_handler().
247  * @param array  $attr    Embed attributes.
248  * @param string $url     The original URL that was matched by the regex.
249  * @param array  $rawattr The original unmodified attributes.
250  * @return string The embed HTML.
251  */
252 function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
253         global $wp_embed;
254         $embed = $wp_embed->autoembed( "https://youtube.com/watch?v={$matches[2]}" );
255
256         /**
257          * Filter the YoutTube embed output.
258          *
259          * @since 4.0.0
260          *
261          * @see wp_embed_handler_youtube()
262          *
263          * @param string $embed   YouTube embed output.
264          * @param array  $attr    An array of embed attributes.
265          * @param string $url     The original URL that was matched by the regex.
266          * @param array  $rawattr The original unmodified attributes.
267          */
268         return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
269 }
270
271 /**
272  * Audio embed handler callback.
273  *
274  * @since 3.6.0
275  *
276  * @param array  $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
277  * @param array  $attr Embed attributes.
278  * @param string $url The original URL that was matched by the regex.
279  * @param array  $rawattr The original unmodified attributes.
280  * @return string The embed HTML.
281  */
282 function wp_embed_handler_audio( $matches, $attr, $url, $rawattr ) {
283         $audio = sprintf( '[audio src="%s" /]', esc_url( $url ) );
284
285         /**
286          * Filter the audio embed output.
287          *
288          * @since 3.6.0
289          *
290          * @param string $audio   Audio embed output.
291          * @param array  $attr    An array of embed attributes.
292          * @param string $url     The original URL that was matched by the regex.
293          * @param array  $rawattr The original unmodified attributes.
294          */
295         return apply_filters( 'wp_embed_handler_audio', $audio, $attr, $url, $rawattr );
296 }
297
298 /**
299  * Video embed handler callback.
300  *
301  * @since 3.6.0
302  *
303  * @param array  $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
304  * @param array  $attr    Embed attributes.
305  * @param string $url     The original URL that was matched by the regex.
306  * @param array  $rawattr The original unmodified attributes.
307  * @return string The embed HTML.
308  */
309 function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) {
310         $dimensions = '';
311         if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
312                 $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
313                 $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
314         }
315         $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) );
316
317         /**
318          * Filter the video embed output.
319          *
320          * @since 3.6.0
321          *
322          * @param string $video   Video embed output.
323          * @param array  $attr    An array of embed attributes.
324          * @param string $url     The original URL that was matched by the regex.
325          * @param array  $rawattr The original unmodified attributes.
326          */
327         return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr );
328 }
329
330 /**
331  * Registers the oEmbed REST API route.
332  *
333  * @since 4.4.0
334  */
335 function wp_oembed_register_route() {
336         $controller = new WP_oEmbed_Controller();
337         $controller->register_routes();
338 }
339
340 /**
341  * Adds oEmbed discovery links in the website <head>.
342  *
343  * @since 4.4.0
344  */
345 function wp_oembed_add_discovery_links() {
346         $output = '';
347
348         if ( is_singular() ) {
349                 $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
350
351                 if ( class_exists( 'SimpleXMLElement' ) ) {
352                         $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
353                 }
354         }
355
356         /**
357          * Filter the oEmbed discovery links HTML.
358          *
359          * @since 4.4.0
360          *
361          * @param string $output HTML of the discovery links.
362          */
363         echo apply_filters( 'oembed_discovery_links', $output );
364 }
365
366 /**
367  * Adds the necessary JavaScript to communicate with the embedded iframes.
368  *
369  * @since 4.4.0
370  */
371 function wp_oembed_add_host_js() {
372         wp_enqueue_script( 'wp-embed' );
373 }
374
375 /**
376  * Retrieves the URL to embed a specific post in an iframe.
377  *
378  * @since 4.4.0
379  *
380  * @param int|WP_Post $post Optional. Post ID or object. Defaults to the current post.
381  * @return string|false The post embed URL on success, false if the post doesn't exist.
382  */
383 function get_post_embed_url( $post = null ) {
384         $post = get_post( $post );
385
386         if ( ! $post ) {
387                 return false;
388         }
389
390         $embed_url     = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
391         $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) );
392
393         if ( ! get_option( 'permalink_structure' ) || $path_conflict ) {
394                 $embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) );
395         }
396
397         /**
398          * Filter the URL to embed a specific post.
399          *
400          * @since 4.4.0
401          *
402          * @param string  $embed_url The post embed URL.
403          * @param WP_Post $post      The corresponding post object.
404          */
405         return esc_url_raw( apply_filters( 'post_embed_url', $embed_url, $post ) );
406 }
407
408 /**
409  * Retrieves the oEmbed endpoint URL for a given permalink.
410  *
411  * Pass an empty string as the first argument to get the endpoint base URL.
412  *
413  * @since 4.4.0
414  *
415  * @param string $permalink Optional. The permalink used for the `url` query arg. Default empty.
416  * @param string $format    Optional. The requested response format. Default 'json'.
417  * @return string The oEmbed endpoint URL.
418  */
419 function get_oembed_endpoint_url( $permalink = '', $format = 'json' ) {
420         $url = rest_url( 'oembed/1.0/embed' );
421
422         if ( 'json' === $format ) {
423                 $format = false;
424         }
425
426         if ( '' !== $permalink ) {
427                 $url = add_query_arg( array(
428                         'url'    => urlencode( $permalink ),
429                         'format' => $format,
430                 ), $url );
431         }
432
433         /**
434          * Filter the oEmbed endpoint URL.
435          *
436          * @since 4.4.0
437          *
438          * @param string $url       The URL to the oEmbed endpoint.
439          * @param string $permalink The permalink used for the `url` query arg.
440          * @param string $format    The requested response format.
441          */
442         return apply_filters( 'oembed_endpoint_url', $url, $permalink, $format );
443 }
444
445 /**
446  * Retrieves the embed code for a specific post.
447  *
448  * @since 4.4.0
449  *
450  * @param int         $width  The width for the response.
451  * @param int         $height The height for the response.
452  * @param int|WP_Post $post   Optional. Post ID or object. Default is global `$post`.
453  * @return string|false Embed code on success, false if post doesn't exist.
454  */
455 function get_post_embed_html( $width, $height, $post = null ) {
456         $post = get_post( $post );
457
458         if ( ! $post ) {
459                 return false;
460         }
461
462         $embed_url = get_post_embed_url( $post );
463
464         $output = '<blockquote class="wp-embedded-content"><a href="' . esc_url( get_permalink( $post ) ) . '">' . get_the_title( $post ) . "</a></blockquote>\n";
465
466         $output .= "<script type='text/javascript'>\n";
467         $output .= "<!--//--><![CDATA[//><!--\n";
468         if ( SCRIPT_DEBUG ) {
469                 $output .= file_get_contents( ABSPATH . WPINC . '/js/wp-embed.js' );
470         } else {
471                 /*
472                  * If you're looking at a src version of this file, you'll see an "include"
473                  * statement below. This is used by the `grunt build` process to directly
474                  * include a minified version of wp-embed.js, instead of using the
475                  * file_get_contents() method from above.
476                  *
477                  * If you're looking at a build version of this file, you'll see a string of
478                  * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
479                  * and edit wp-embed.js directly.
480                  */
481                 $output .=<<<JS
482                 !function(a,b){"use strict";function c(){if(!e){e=!0;var a,c,d,f,g=-1!==navigator.appVersion.indexOf("MSIE 10"),h=!!navigator.userAgent.match(/Trident.*rv:11\./),i=b.querySelectorAll("iframe.wp-embedded-content");for(c=0;c<i.length;c++)if(d=i[c],!d.getAttribute("data-secret")){if(f=Math.random().toString(36).substr(2,10),d.src+="#?secret="+f,d.setAttribute("data-secret",f),g||h)a=d.cloneNode(!0),a.removeAttribute("security"),d.parentNode.replaceChild(a,d)}else;}}var d=!1,e=!1;if(b.querySelector)if(a.addEventListener)d=!0;if(a.wp=a.wp||{},!a.wp.receiveEmbedMessage)if(a.wp.receiveEmbedMessage=function(c){var d=c.data;if(d.secret||d.message||d.value)if(!/[^a-zA-Z0-9]/.test(d.secret)){var e,f,g,h,i,j=b.querySelectorAll('iframe[data-secret="'+d.secret+'"]'),k=b.querySelectorAll('blockquote[data-secret="'+d.secret+'"]');for(e=0;e<k.length;e++)k[e].style.display="none";for(e=0;e<j.length;e++)if(f=j[e],c.source===f.contentWindow){if(f.removeAttribute("style"),"height"===d.message){if(g=parseInt(d.value,10),g>1e3)g=1e3;else if(200>~~g)g=200;f.height=g}if("link"===d.message)if(h=b.createElement("a"),i=b.createElement("a"),h.href=f.getAttribute("src"),i.href=d.value,i.host===h.host)if(b.activeElement===f)a.top.location.href=d.value}else;}},d)a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)}(window,document);
483 JS;
484         }
485         $output .= "\n//--><!]]>";
486         $output .= "\n</script>";
487
488         $output .= sprintf(
489                 '<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>',
490                 esc_url( $embed_url ),
491                 absint( $width ),
492                 absint( $height ),
493                 esc_attr(
494                         sprintf(
495                                 /* translators: 1: post title, 2: site name */
496                                 __( '&#8220;%1$s&#8221; &#8212; %2$s' ),
497                                 get_the_title( $post ),
498                                 get_bloginfo( 'name' )
499                         )
500                 )
501         );
502
503         /**
504          * Filter the embed HTML output for a given post.
505          *
506          * @since 4.4.0
507          *
508          * @param string  $output The default HTML.
509          * @param WP_Post $post   Current post object.
510          * @param int     $width  Width of the response.
511          * @param int     $height Height of the response.
512          */
513         return apply_filters( 'embed_html', $output, $post, $width, $height );
514 }
515
516 /**
517  * Retrieves the oEmbed response data for a given post.
518  *
519  * @since 4.4.0
520  *
521  * @param WP_Post|int $post  Post object or ID.
522  * @param int         $width The requested width.
523  * @return array|false Response data on success, false if post doesn't exist.
524  */
525 function get_oembed_response_data( $post, $width ) {
526         $post = get_post( $post );
527
528         if ( ! $post ) {
529                 return false;
530         }
531
532         if ( 'publish' !== get_post_status( $post ) ) {
533                 return false;
534         }
535
536         /**
537          * Filter the allowed minimum and maximum widths for the oEmbed response.
538          *
539          * @since 4.4.0
540          *
541          * @param array $min_max_width {
542          *     Minimum and maximum widths for the oEmbed response.
543          *
544          *     @type int $min Minimum width. Default 200.
545          *     @type int $max Maximum width. Default 600.
546          * }
547          */
548         $min_max_width = apply_filters( 'oembed_min_max_width', array(
549                 'min' => 200,
550                 'max' => 600
551         ) );
552
553         $width  = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
554         $height = max( ceil( $width / 16 * 9 ), 200 );
555
556         $data = array(
557                 'version'       => '1.0',
558                 'provider_name' => get_bloginfo( 'name' ),
559                 'provider_url'  => get_home_url(),
560                 'author_name'   => get_bloginfo( 'name' ),
561                 'author_url'    => get_home_url(),
562                 'title'         => $post->post_title,
563                 'type'          => 'link',
564         );
565
566         $author = get_userdata( $post->post_author );
567
568         if ( $author ) {
569                 $data['author_name'] = $author->display_name;
570                 $data['author_url']  = get_author_posts_url( $author->ID );
571         }
572
573         /**
574          * Filter the oEmbed response data.
575          *
576          * @since 4.4.0
577          *
578          * @param array   $data   The response data.
579          * @param WP_Post $post   The post object.
580          * @param int     $width  The requested width.
581          * @param int     $height The calculated height.
582          */
583         return apply_filters( 'oembed_response_data', $data, $post, $width, $height );
584 }
585
586 /**
587  * Filters the oEmbed response data to return an iframe embed code.
588  *
589  * @since 4.4.0
590  *
591  * @param array   $data   The response data.
592  * @param WP_Post $post   The post object.
593  * @param int     $width  The requested width.
594  * @param int     $height The calculated height.
595  * @return array The modified response data.
596  */
597 function get_oembed_response_data_rich( $data, $post, $width, $height ) {
598         $data['width']  = absint( $width );
599         $data['height'] = absint( $height );
600         $data['type']   = 'rich';
601         $data['html']   = get_post_embed_html( $width, $height, $post );
602
603         // Add post thumbnail to response if available.
604         $thumbnail_id = false;
605
606         if ( has_post_thumbnail( $post->ID ) ) {
607                 $thumbnail_id = get_post_thumbnail_id( $post->ID );
608         }
609
610         if ( 'attachment' === get_post_type( $post ) ) {
611                 if ( wp_attachment_is_image( $post ) ) {
612                         $thumbnail_id = $post->ID;
613                 } else if ( wp_attachment_is( 'video', $post ) ) {
614                         $thumbnail_id = get_post_thumbnail_id( $post );
615                         $data['type'] = 'video';
616                 }
617         }
618
619         if ( $thumbnail_id ) {
620                 list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
621                 $data['thumbnail_url']    = $thumbnail_url;
622                 $data['thumbnail_width']  = $thumbnail_width;
623                 $data['thumbnail_height'] = $thumbnail_height;
624         }
625
626         return $data;
627 }
628
629 /**
630  * Ensures that the specified format is either 'json' or 'xml'.
631  *
632  * @since 4.4.0
633  *
634  * @param string $format The oEmbed response format. Accepts 'json' or 'xml'.
635  * @return string The format, either 'xml' or 'json'. Default 'json'.
636  */
637 function wp_oembed_ensure_format( $format ) {
638         if ( ! in_array( $format, array( 'json', 'xml' ), true ) ) {
639                 return 'json';
640         }
641
642         return $format;
643 }
644
645 /**
646  * Hooks into the REST API output to print XML instead of JSON.
647  *
648  * This is only done for the oEmbed API endpoint,
649  * which supports both formats.
650  *
651  * @access private
652  * @since 4.4.0
653  *
654  * @param bool                      $served  Whether the request has already been served.
655  * @param WP_HTTP_ResponseInterface $result  Result to send to the client. Usually a WP_REST_Response.
656  * @param WP_REST_Request           $request Request used to generate the response.
657  * @param WP_REST_Server            $server  Server instance.
658  * @return true
659  */
660 function _oembed_rest_pre_serve_request( $served, $result, $request, $server ) {
661         $params = $request->get_params();
662
663         if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) {
664                 return $served;
665         }
666
667         if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) {
668                 return $served;
669         }
670
671         // Embed links inside the request.
672         $data = $server->response_to_data( $result, false );
673
674         if ( ! class_exists( 'SimpleXMLElement' ) ) {
675                 status_header( 501 );
676                 die( get_status_header_desc( 501 ) );
677         }
678
679         $result = _oembed_create_xml( $data );
680
681         // Bail if there's no XML.
682         if ( ! $result ) {
683                 status_header( 501 );
684                 return get_status_header_desc( 501 );
685         }
686
687         if ( ! headers_sent() ) {
688                 $server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) );
689         }
690
691         echo $result;
692
693         return true;
694 }
695
696 /**
697  * Creates an XML string from a given array.
698  *
699  * @since 4.4.0
700  * @access private
701  *
702  * @param array            $data The original oEmbed response data.
703  * @param SimpleXMLElement $node Optional. XML node to append the result to recursively.
704  * @return string|false XML string on success, false on error.
705  */
706 function _oembed_create_xml( $data, $node = null ) {
707         if ( ! is_array( $data ) || empty( $data ) ) {
708                 return false;
709         }
710
711         if ( null === $node ) {
712                 $node = new SimpleXMLElement( '<oembed></oembed>' );
713         }
714
715         foreach ( $data as $key => $value ) {
716                 if ( is_numeric( $key ) ) {
717                         $key = 'oembed';
718                 }
719
720                 if ( is_array( $value ) ) {
721                         $item = $node->addChild( $key );
722                         _oembed_create_xml( $value, $item );
723                 } else {
724                         $node->addChild( $key, esc_html( $value ) );
725                 }
726         }
727
728         return $node->asXML();
729 }
730
731 /**
732  * Filters the given oEmbed HTML.
733  *
734  * If the `$url` isn't on the trusted providers list,
735  * we need to filter the HTML heavily for security.
736  *
737  * Only filters 'rich' and 'html' response types.
738  *
739  * @since 4.4.0
740  *
741  * @param string $result The oEmbed HTML result.
742  * @param object $data   A data object result from an oEmbed provider.
743  * @param string $url    The URL of the content to be embedded.
744  * @return string The filtered and sanitized oEmbed result.
745  */
746 function wp_filter_oembed_result( $result, $data, $url ) {
747         if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ) ) ) {
748                 return $result;
749         }
750
751         require_once( ABSPATH . WPINC . '/class-oembed.php' );
752         $wp_oembed = _wp_oembed_get_object();
753
754         // Don't modify the HTML for trusted providers.
755         if ( false !== $wp_oembed->get_provider( $url, array( 'discover' => false ) ) ) {
756                 return $result;
757         }
758
759         $allowed_html = array(
760                 'a'          => array(
761                         'href'         => true,
762                 ),
763                 'blockquote' => array(),
764                 'iframe'     => array(
765                         'src'          => true,
766                         'width'        => true,
767                         'height'       => true,
768                         'frameborder'  => true,
769                         'marginwidth'  => true,
770                         'marginheight' => true,
771                         'scrolling'    => true,
772                         'title'        => true,
773                 ),
774         );
775
776         $html = wp_kses( $result, $allowed_html );
777
778         preg_match( '|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content );
779         // We require at least the iframe to exist.
780         if ( empty( $content[2] ) ) {
781                 return false;
782         }
783         $html = $content[1] . $content[2];
784
785         if ( ! empty( $content[1] ) ) {
786                 // We have a blockquote to fall back on. Hide the iframe by default.
787                 $html = str_replace( '<iframe', '<iframe style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', $html );
788                 $html = str_replace( '<blockquote', '<blockquote class="wp-embedded-content"', $html );
789         }
790
791         $html = str_replace( '<iframe', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $html );
792
793         preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results );
794
795         if ( ! empty( $results ) ) {
796                 $secret = wp_generate_password( 10, false );
797
798                 $url = esc_url( "{$results[1]}#?secret=$secret" );
799
800                 $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html );
801                 $html = str_replace( '<blockquote', "<blockquote data-secret=\"$secret\"", $html );
802         }
803
804         return $html;
805 }
806
807 /**
808  * Filters the string in the 'more' link displayed after a trimmed excerpt.
809  *
810  * Replaces '[...]' (appended to automatically generated excerpts) with an
811  * ellipsis and a "Continue reading" link in the embed template.
812  *
813  * @since 4.4.0
814  *
815  * @param string $more_string Default 'more' string.
816  * @return string 'Continue reading' link prepended with an ellipsis.
817  */
818 function wp_embed_excerpt_more( $more_string ) {
819         if ( ! is_embed() ) {
820                 return $more_string;
821         }
822
823         $link = sprintf( '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>',
824                 esc_url( get_permalink() ),
825                 /* translators: %s: Name of current post */
826                 sprintf( __( 'Continue reading %s' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' )
827         );
828         return ' &hellip; ' . $link;
829 }
830
831 /**
832  * Displays the post excerpt for the embed template.
833  *
834  * Intended to be used in 'The Loop'.
835  *
836  * @since 4.4.0
837  */
838 function the_excerpt_embed() {
839         $output = get_the_excerpt();
840
841         /**
842          * Filter the post excerpt for the embed template.
843          *
844          * @since 4.4.0
845          *
846          * @param string $output The current post excerpt.
847          */
848         echo apply_filters( 'the_excerpt_embed', $output );
849 }
850
851 /**
852  * Filters the post excerpt for the embed template.
853  *
854  * Shows players for video and audio attachments.
855  *
856  * @since 4.4.0
857  *
858  * @param string $content The current post excerpt.
859  * @return string The modified post excerpt.
860  */
861 function wp_embed_excerpt_attachment( $content ) {
862         if ( is_attachment() ) {
863                 return prepend_attachment( '' );
864         }
865
866         return $content;
867 }
868
869 /**
870  * Enqueue embed iframe default CSS and JS & fire do_action('enqueue_embed_scripts')
871  *
872  * Enqueue PNG fallback CSS for embed iframe for legacy versions of IE.
873  *
874  * Allows plugins to queue scripts for the embed iframe end using wp_enqueue_script().
875  * Runs first in oembed_head().
876  *
877  * @since 4.4.0
878  */
879 function enqueue_embed_scripts() {
880         wp_enqueue_style( 'open-sans' );
881         wp_enqueue_style( 'wp-embed-template-ie' );
882
883         /**
884          * Fires when scripts and styles are enqueued for the embed iframe.
885          *
886          * @since 4.4.0
887          */
888         do_action( 'enqueue_embed_scripts' );
889 }
890
891 /**
892  * Prints the CSS in the embed iframe header.
893  *
894  * @since 4.4.0
895  */
896 function print_embed_styles() {
897         ?>
898         <style type="text/css">
899         <?php
900                 if ( SCRIPT_DEBUG ) {
901                         readfile( ABSPATH . WPINC . "/css/wp-embed-template.css" );
902                 } else {
903                         /*
904                          * If you're looking at a src version of this file, you'll see an "include"
905                          * statement below. This is used by the `grunt build` process to directly
906                          * include a minified version of wp-oembed-embed.css, instead of using the
907                          * readfile() method from above.
908                          *
909                          * If you're looking at a build version of this file, you'll see a string of
910                          * minified CSS. If you need to debug it, please turn on SCRIPT_DEBUG
911                          * and edit wp-embed-template.css directly.
912                          */
913                         ?>
914                         body,html{padding:0;margin:0}body{font-family:sans-serif}.screen-reader-text{clip:rect(1px,1px,1px,1px);height:1px;overflow:hidden;position:absolute!important;width:1px}.dashicons{display:inline-block;width:20px;height:20px;background-color:transparent;background-repeat:no-repeat;-webkit-background-size:20px 20px;background-size:20px;background-position:center;-webkit-transition:background .1s ease-in;transition:background .1s ease-in;position:relative;top:5px}.dashicons-no{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2020%2020%27%3E%3Cpath%20d%3D%27M15.55%2013.7l-2.19%202.06-3.42-3.65-3.64%203.43-2.06-2.18%203.64-3.43-3.42-3.64%202.18-2.06%203.43%203.64%203.64-3.42%202.05%202.18-3.64%203.43z%27%20fill%3D%27%23fff%27%2F%3E%3C%2Fsvg%3E")}.dashicons-admin-comments{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2020%2020%27%3E%3Cpath%20d%3D%27M5%202h9q.82%200%201.41.59T16%204v7q0%20.82-.59%201.41T14%2013h-2l-5%205v-5H5q-.82%200-1.41-.59T3%2011V4q0-.82.59-1.41T5%202z%27%20fill%3D%27%2382878c%27%2F%3E%3C%2Fsvg%3E")}.wp-embed-comments a:hover .dashicons-admin-comments{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2020%2020%27%3E%3Cpath%20d%3D%27M5%202h9q.82%200%201.41.59T16%204v7q0%20.82-.59%201.41T14%2013h-2l-5%205v-5H5q-.82%200-1.41-.59T3%2011V4q0-.82.59-1.41T5%202z%27%20fill%3D%27%230073aa%27%2F%3E%3C%2Fsvg%3E")}.dashicons-share{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2020%2020%27%3E%3Cpath%20d%3D%27M14.5%2012q1.24%200%202.12.88T17.5%2015t-.88%202.12-2.12.88-2.12-.88T11.5%2015q0-.34.09-.69l-4.38-2.3Q6.32%2013%205%2013q-1.24%200-2.12-.88T2%2010t.88-2.12T5%207q1.3%200%202.21.99l4.38-2.3q-.09-.35-.09-.69%200-1.24.88-2.12T14.5%202t2.12.88T17.5%205t-.88%202.12T14.5%208q-1.3%200-2.21-.99l-4.38%202.3Q8%209.66%208%2010t-.09.69l4.38%202.3q.89-.99%202.21-.99z%27%20fill%3D%27%2382878c%27%2F%3E%3C%2Fsvg%3E");display:none}.js .dashicons-share{display:inline-block}.wp-embed-share-dialog-open:hover .dashicons-share{background-image:url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2020%2020%27%3E%3Cpath%20d%3D%27M14.5%2012q1.24%200%202.12.88T17.5%2015t-.88%202.12-2.12.88-2.12-.88T11.5%2015q0-.34.09-.69l-4.38-2.3Q6.32%2013%205%2013q-1.24%200-2.12-.88T2%2010t.88-2.12T5%207q1.3%200%202.21.99l4.38-2.3q-.09-.35-.09-.69%200-1.24.88-2.12T14.5%202t2.12.88T17.5%205t-.88%202.12T14.5%208q-1.3%200-2.21-.99l-4.38%202.3Q8%209.66%208%2010t-.09.69l4.38%202.3q.89-.99%202.21-.99z%27%20fill%3D%27%230073aa%27%2F%3E%3C%2Fsvg%3E")}.wp-embed{padding:25px;font:400 14px/1.5 'Open Sans',sans-serif;color:#82878c;background:#fff;border:1px solid #e5e5e5;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05);overflow:auto;zoom:1}.wp-embed a{color:#82878c;text-decoration:none}.wp-embed a:hover{text-decoration:underline}.wp-embed-featured-image{margin-bottom:20px}.wp-embed-featured-image img{width:100%;height:auto;border:none}.wp-embed-featured-image.square{float:left;max-width:160px;margin-right:20px}.wp-embed p{margin:0}p.wp-embed-heading{margin:0 0 15px;font-weight:700;font-size:22px;line-height:1.3}.wp-embed-heading a{color:#32373c}.wp-embed .wp-embed-more{color:#b4b9be}.wp-embed-footer{display:table;width:100%;margin-top:30px}.wp-embed-site-icon{position:absolute;top:50%;left:0;-webkit-transform:translateY(-50%);-ms-transform:translateY(-50%);transform:translateY(-50%);height:25px;width:25px;border:0}.wp-embed-site-title{font-weight:700;line-height:25px}.wp-embed-site-title a{position:relative;display:inline-block;padding-left:35px}.wp-embed-meta,.wp-embed-site-title{display:table-cell}.wp-embed-meta{text-align:right;white-space:nowrap;vertical-align:middle}.wp-embed-comments,.wp-embed-share{display:inline}.wp-embed-comments a,.wp-embed-share-tab-button{display:inline-block}.wp-embed-meta a:hover{text-decoration:none;color:#0073aa}.wp-embed-comments a{line-height:25px}.wp-embed-comments+.wp-embed-share{margin-left:10px}.wp-embed-share-dialog{position:absolute;top:0;left:0;right:0;bottom:0;background-color:#222;background-color:rgba(10,10,10,.9);color:#fff;opacity:1;-webkit-transition:opacity .25s ease-in-out;transition:opacity .25s ease-in-out}.wp-embed-share-dialog.hidden{opacity:0;visibility:hidden}.wp-embed-share-dialog-close,.wp-embed-share-dialog-open{margin:-8px 0 0;padding:0;background:0 0;border:none;cursor:pointer;outline:0}.wp-embed-share-dialog-close .dashicons,.wp-embed-share-dialog-open .dashicons{padding:4px}.wp-embed-share-dialog-open .dashicons{top:8px}.wp-embed-share-dialog-close:focus .dashicons,.wp-embed-share-dialog-open:focus .dashicons{-webkit-box-shadow:0 0 0 1px #5b9dd9,0 0 2px 1px rgba(30,140,190,.8);box-shadow:0 0 0 1px #5b9dd9,0 0 2px 1px rgba(30,140,190,.8);-webkit-border-radius:100%;border-radius:100%}.wp-embed-share-dialog-close{position:absolute;top:20px;right:20px;font-size:22px}.wp-embed-share-dialog-close:hover{text-decoration:none}.wp-embed-share-dialog-close .dashicons{height:24px;width:24px;-webkit-background-size:24px 24px;background-size:24px}.wp-embed-share-dialog-content{height:100%;-webkit-transform-style:preserve-3d;transform-style:preserve-3d;overflow:hidden}.wp-embed-share-dialog-text{margin-top:25px;padding:20px}.wp-embed-share-tabs{margin:0 0 20px;padding:0;list-style:none}.wp-embed-share-tab-button button{margin:0;padding:0;border:none;background:0 0;font-size:16px;line-height:1.3;color:#aaa;cursor:pointer;-webkit-transition:color .1s ease-in;transition:color .1s ease-in}.wp-embed-share-tab-button [aria-selected=true],.wp-embed-share-tab-button button:hover{color:#fff}.wp-embed-share-tab-button+.wp-embed-share-tab-button{margin:0 0 0 10px;padding:0 0 0 11px;border-left:1px solid #aaa}.wp-embed-share-tab[aria-hidden=true]{display:none}p.wp-embed-share-description{margin:0;font-size:14px;line-height:1;font-style:italic;color:#aaa}.wp-embed-share-input{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%;border:none;height:28px;margin:0 0 10px;padding:0 5px;font:400 14px/1.5 'Open Sans',sans-serif;resize:none;cursor:text}textarea.wp-embed-share-input{height:72px}html[dir=rtl] .wp-embed-featured-image.square{float:right;margin-right:0;margin-left:20px}html[dir=rtl] .wp-embed-site-title a{padding-left:0;padding-right:35px}html[dir=rtl] .wp-embed-site-icon{margin-right:0;margin-left:10px;left:auto;right:0}html[dir=rtl] .wp-embed-meta{text-align:left}html[dir=rtl] .wp-embed-share{margin-left:0;margin-right:10px}html[dir=rtl] .wp-embed-share-dialog-close{right:auto;left:20px}html[dir=rtl] .wp-embed-share-tab-button+.wp-embed-share-tab-button{margin:0 10px 0 0;padding:0 11px 0 0;border-left:none;border-right:1px solid #aaa}
915                         <?php
916                 }
917         ?>
918         </style>
919         <?php
920 }
921
922 /**
923  * Prints the JavaScript in the embed iframe header.
924  *
925  * @since 4.4.0
926  */
927 function print_embed_scripts() {
928         ?>
929         <script type="text/javascript">
930         <?php
931                 if ( SCRIPT_DEBUG ) {
932                         readfile( ABSPATH . WPINC . "/js/wp-embed-template.js" );
933                 } else {
934                         /*
935                          * If you're looking at a src version of this file, you'll see an "include"
936                          * statement below. This is used by the `grunt build` process to directly
937                          * include a minified version of wp-embed-template.js, instead of using the
938                          * readfile() method from above.
939                          *
940                          * If you're looking at a build version of this file, you'll see a string of
941                          * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
942                          * and edit wp-embed-template.js directly.
943                          */
944                         ?>
945                         !function(a,b){"use strict";function c(b,c){a.parent.postMessage({message:b,value:c,secret:g},"*")}function d(){function d(){l.className=l.className.replace("hidden",""),b.querySelector('.wp-embed-share-tab-button [aria-selected="true"]').focus()}function e(){l.className+=" hidden",b.querySelector(".wp-embed-share-dialog-open").focus()}function f(a){var c=b.querySelector('.wp-embed-share-tab-button [aria-selected="true"]');c.setAttribute("aria-selected","false"),b.querySelector("#"+c.getAttribute("aria-controls")).setAttribute("aria-hidden","true"),a.target.setAttribute("aria-selected","true"),b.querySelector("#"+a.target.getAttribute("aria-controls")).setAttribute("aria-hidden","false")}function g(a){var c,d,e=a.target,f=e.parentElement.previousElementSibling,g=e.parentElement.nextElementSibling;if(37===a.keyCode)c=f;else{if(39!==a.keyCode)return!1;c=g}"rtl"===b.documentElement.getAttribute("dir")&&(c=c===f?g:f),c&&(d=c.firstElementChild,e.setAttribute("tabindex","-1"),e.setAttribute("aria-selected",!1),b.querySelector("#"+e.getAttribute("aria-controls")).setAttribute("aria-hidden","true"),d.setAttribute("tabindex","0"),d.setAttribute("aria-selected","true"),d.focus(),b.querySelector("#"+d.getAttribute("aria-controls")).setAttribute("aria-hidden","false"))}function h(a){var c=b.querySelector('.wp-embed-share-tab-button [aria-selected="true"]');n!==a.target||a.shiftKey?c===a.target&&a.shiftKey&&(n.focus(),a.preventDefault()):(c.focus(),a.preventDefault())}function i(a){var b,d=a.target;b=d.hasAttribute("href")?d.getAttribute("href"):d.parentElement.getAttribute("href"),b&&(c("link",b),a.preventDefault())}if(!k){k=!0;var j,l=b.querySelector(".wp-embed-share-dialog"),m=b.querySelector(".wp-embed-share-dialog-open"),n=b.querySelector(".wp-embed-share-dialog-close"),o=b.querySelectorAll(".wp-embed-share-input"),p=b.querySelectorAll(".wp-embed-share-tab-button button");if(o)for(j=0;j<o.length;j++)o[j].addEventListener("click",function(a){a.target.select()});if(m&&m.addEventListener("click",function(){d()}),n&&n.addEventListener("click",function(){e()}),p)for(j=0;j<p.length;j++)p[j].addEventListener("click",f),p[j].addEventListener("keydown",g);b.addEventListener("keydown",function(a){27===a.keyCode&&-1===l.className.indexOf("hidden")?e():9===a.keyCode&&h(a)},!1),a.self!==a.top&&(c("height",Math.ceil(b.body.getBoundingClientRect().height)),b.addEventListener("click",i))}}function e(){a.self!==a.top&&(clearTimeout(i),i=setTimeout(function(){c("height",Math.ceil(b.body.getBoundingClientRect().height))},100))}function f(){a.self===a.top||g||(g=a.location.hash.replace(/.*secret=([\d\w]{10}).*/,"$1"),clearTimeout(h),h=setTimeout(function(){f()},100))}var g,h,i,j=b.querySelector&&a.addEventListener,k=!1;j&&(f(),b.documentElement.className=b.documentElement.className.replace(/\bno-js\b/,"")+" js",b.addEventListener("DOMContentLoaded",d,!1),a.addEventListener("load",d,!1),a.addEventListener("resize",e,!1))}(window,document);
946                         <?php
947                 }
948         ?>
949         </script>
950         <?php
951 }
952
953 /**
954  * Prepare the oembed HTML to be displayed in an RSS feed.
955  *
956  * @since 4.4.0
957  * @access private
958  *
959  * @param string $content The content to filter.
960  * @return string The filtered content.
961  */
962 function _oembed_filter_feed_content( $content ) {
963         return str_replace( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content );
964 }
965
966 /**
967  * Prints the necessary markup for the embed comments button.
968  *
969  * @since 4.4.0
970  */
971 function print_embed_comments_button() {
972         if ( is_404() || ! ( get_comments_number() || comments_open() ) ) {
973                 return;
974         }
975         ?>
976         <div class="wp-embed-comments">
977                 <a href="<?php comments_link(); ?>" target="_top">
978                         <span class="dashicons dashicons-admin-comments"></span>
979                         <?php
980                         printf(
981                                 _n(
982                                         '%s <span class="screen-reader-text">Comment</span>',
983                                         '%s <span class="screen-reader-text">Comments</span>',
984                                         get_comments_number()
985                                 ),
986                                 number_format_i18n( get_comments_number() )
987                         );
988                         ?>
989                 </a>
990         </div>
991         <?php
992 }
993
994 /**
995  * Prints the necessary markup for the embed sharing button.
996  *
997  * @since 4.4.0
998  */
999 function print_embed_sharing_button() {
1000         if ( is_404() ) {
1001                 return;
1002         }
1003         ?>
1004         <div class="wp-embed-share">
1005                 <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">
1006                         <span class="dashicons dashicons-share"></span>
1007                 </button>
1008         </div>
1009         <?php
1010 }
1011
1012 /**
1013  * Prints the necessary markup for the embed sharing dialog.
1014  *
1015  * @since 4.4.0
1016  */
1017 function print_embed_sharing_dialog() {
1018         if ( is_404() ) {
1019                 return;
1020         }
1021         ?>
1022         <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>">
1023                 <div class="wp-embed-share-dialog-content">
1024                         <div class="wp-embed-share-dialog-text">
1025                                 <ul class="wp-embed-share-tabs" role="tablist">
1026                                         <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation">
1027                                                 <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button>
1028                                         </li>
1029                                         <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation">
1030                                                 <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button>
1031                                         </li>
1032                                 </ul>
1033                                 <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false">
1034                                         <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly/>
1035
1036                                         <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress">
1037                                                 <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?>
1038                                         </p>
1039                                 </div>
1040                                 <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true">
1041                                         <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea( get_post_embed_html( 600, 400 ) ); ?></textarea>
1042
1043                                         <p class="wp-embed-share-description" id="wp-embed-share-description-html">
1044                                                 <?php _e( 'Copy and paste this code into your site to embed' ); ?>
1045                                         </p>
1046                                 </div>
1047                         </div>
1048
1049                         <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>">
1050                                 <span class="dashicons dashicons-no"></span>
1051                         </button>
1052                 </div>
1053         </div>
1054         <?php
1055 }
1056
1057 /**
1058  * Prints the necessary markup for the site title in an embed template.
1059  *
1060  * @since 4.5.0
1061  */
1062 function the_embed_site_title() {
1063         $site_title = sprintf(
1064                 '<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon"/><span>%s</span></a>',
1065                 esc_url( home_url() ),
1066                 esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ),
1067                 esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ),
1068                 esc_html( get_bloginfo( 'name' ) )
1069         );
1070
1071         $site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>';
1072
1073         /**
1074          * Filter the site title HTML in the embed footer.
1075          *
1076          * @since 4.4.0
1077          *
1078          * @param string $site_title The site title HTML.
1079          */
1080         echo apply_filters( 'embed_site_title_html', $site_title );
1081 }