You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1088 lines
43 KiB

  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. * Registers an embed handler.
  11. *
  12. * Should probably only be used for sites that do not support oEmbed.
  13. *
  14. * @since 2.9.0
  15. *
  16. * @global WP_Embed $wp_embed
  17. *
  18. * @param string $id An internal ID/name for the handler. Needs to be unique.
  19. * @param string $regex The regex that will be used to see if this handler should be used for a URL.
  20. * @param callable $callback The callback function that will be called if the regex is matched.
  21. * @param int $priority Optional. Used to specify the order in which the registered handlers will
  22. * be tested. Default 10.
  23. */
  24. function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
  25. global $wp_embed;
  26. $wp_embed->register_handler( $id, $regex, $callback, $priority );
  27. }
  28. /**
  29. * Unregisters a previously-registered embed handler.
  30. *
  31. * @since 2.9.0
  32. *
  33. * @global WP_Embed $wp_embed
  34. *
  35. * @param string $id The handler ID that should be removed.
  36. * @param int $priority Optional. The priority of the handler to be removed. Default 10.
  37. */
  38. function wp_embed_unregister_handler( $id, $priority = 10 ) {
  39. global $wp_embed;
  40. $wp_embed->unregister_handler( $id, $priority );
  41. }
  42. /**
  43. * Creates default array of embed parameters.
  44. *
  45. * The width defaults to the content width as specified by the theme. If the
  46. * theme does not specify a content width, then 500px is used.
  47. *
  48. * The default height is 1.5 times the width, or 1000px, whichever is smaller.
  49. *
  50. * The {@see 'embed_defaults'} filter can be used to adjust either of these values.
  51. *
  52. * @since 2.9.0
  53. *
  54. * @global int $content_width
  55. *
  56. * @param string $url Optional. The URL that should be embedded. Default empty.
  57. *
  58. * @return array Default embed parameters.
  59. */
  60. function wp_embed_defaults( $url = '' ) {
  61. if ( ! empty( $GLOBALS['content_width'] ) )
  62. $width = (int) $GLOBALS['content_width'];
  63. if ( empty( $width ) )
  64. $width = 500;
  65. $height = min( ceil( $width * 1.5 ), 1000 );
  66. /**
  67. * Filters the default array of embed dimensions.
  68. *
  69. * @since 2.9.0
  70. *
  71. * @param array $size An array of embed width and height values
  72. * in pixels (in that order).
  73. * @param string $url The URL that should be embedded.
  74. */
  75. return apply_filters( 'embed_defaults', compact( 'width', 'height' ), $url );
  76. }
  77. /**
  78. * Attempts to fetch the embed HTML for a provided URL using oEmbed.
  79. *
  80. * @since 2.9.0
  81. *
  82. * @see WP_oEmbed
  83. *
  84. * @param string $url The URL that should be embedded.
  85. * @param array $args Optional. Additional arguments and parameters for retrieving embed HTML.
  86. * Default empty.
  87. * @return false|string False on failure or the embed HTML on success.
  88. */
  89. function wp_oembed_get( $url, $args = '' ) {
  90. $oembed = _wp_oembed_get_object();
  91. return $oembed->get_html( $url, $args );
  92. }
  93. /**
  94. * Returns the initialized WP_oEmbed object.
  95. *
  96. * @since 2.9.0
  97. * @access private
  98. *
  99. * @staticvar WP_oEmbed $wp_oembed
  100. *
  101. * @return WP_oEmbed object.
  102. */
  103. function _wp_oembed_get_object() {
  104. static $wp_oembed = null;
  105. if ( is_null( $wp_oembed ) ) {
  106. $wp_oembed = new WP_oEmbed();
  107. }
  108. return $wp_oembed;
  109. }
  110. /**
  111. * Adds a URL format and oEmbed provider URL pair.
  112. *
  113. * @since 2.9.0
  114. *
  115. * @see WP_oEmbed
  116. *
  117. * @param string $format The format of URL that this provider can handle. You can use asterisks
  118. * as wildcards.
  119. * @param string $provider The URL to the oEmbed provider.
  120. * @param boolean $regex Optional. Whether the `$format` parameter is in a RegEx format. Default false.
  121. */
  122. function wp_oembed_add_provider( $format, $provider, $regex = false ) {
  123. if ( did_action( 'plugins_loaded' ) ) {
  124. $oembed = _wp_oembed_get_object();
  125. $oembed->providers[$format] = array( $provider, $regex );
  126. } else {
  127. WP_oEmbed::_add_provider_early( $format, $provider, $regex );
  128. }
  129. }
  130. /**
  131. * Removes an oEmbed provider.
  132. *
  133. * @since 3.5.0
  134. *
  135. * @see WP_oEmbed
  136. *
  137. * @param string $format The URL format for the oEmbed provider to remove.
  138. * @return bool Was the provider removed successfully?
  139. */
  140. function wp_oembed_remove_provider( $format ) {
  141. if ( did_action( 'plugins_loaded' ) ) {
  142. $oembed = _wp_oembed_get_object();
  143. if ( isset( $oembed->providers[ $format ] ) ) {
  144. unset( $oembed->providers[ $format ] );
  145. return true;
  146. }
  147. } else {
  148. WP_oEmbed::_remove_provider_early( $format );
  149. }
  150. return false;
  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. * Filters 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. wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i', 'wp_embed_handler_youtube' );
  176. /**
  177. * Filters the audio embed handler callback.
  178. *
  179. * @since 3.6.0
  180. *
  181. * @param callable $handler Audio embed handler callback function.
  182. */
  183. wp_embed_register_handler( 'audio', '#^https?://.+?\.(' . join( '|', wp_get_audio_extensions() ) . ')$#i', apply_filters( 'wp_audio_embed_handler', 'wp_embed_handler_audio' ), 9999 );
  184. /**
  185. * Filters the video embed handler callback.
  186. *
  187. * @since 3.6.0
  188. *
  189. * @param callable $handler Video embed handler callback function.
  190. */
  191. wp_embed_register_handler( 'video', '#^https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')$#i', apply_filters( 'wp_video_embed_handler', 'wp_embed_handler_video' ), 9999 );
  192. }
  193. /**
  194. * YouTube iframe embed handler callback.
  195. *
  196. * Catches YouTube iframe embed URLs that are not parsable by oEmbed but can be translated into a URL that is.
  197. *
  198. * @since 4.0.0
  199. *
  200. * @global WP_Embed $wp_embed
  201. *
  202. * @param array $matches The RegEx matches from the provided regex when calling
  203. * wp_embed_register_handler().
  204. * @param array $attr Embed attributes.
  205. * @param string $url The original URL that was matched by the regex.
  206. * @param array $rawattr The original unmodified attributes.
  207. * @return string The embed HTML.
  208. */
  209. function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
  210. global $wp_embed;
  211. $embed = $wp_embed->autoembed( sprintf( "https://youtube.com/watch?v=%s", urlencode( $matches[2] ) ) );
  212. /**
  213. * Filters the YoutTube embed output.
  214. *
  215. * @since 4.0.0
  216. *
  217. * @see wp_embed_handler_youtube()
  218. *
  219. * @param string $embed YouTube embed output.
  220. * @param array $attr An array of embed attributes.
  221. * @param string $url The original URL that was matched by the regex.
  222. * @param array $rawattr The original unmodified attributes.
  223. */
  224. return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
  225. }
  226. /**
  227. * Audio embed handler callback.
  228. *
  229. * @since 3.6.0
  230. *
  231. * @param array $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
  232. * @param array $attr Embed attributes.
  233. * @param string $url The original URL that was matched by the regex.
  234. * @param array $rawattr The original unmodified attributes.
  235. * @return string The embed HTML.
  236. */
  237. function wp_embed_handler_audio( $matches, $attr, $url, $rawattr ) {
  238. $audio = sprintf( '[audio src="%s" /]', esc_url( $url ) );
  239. /**
  240. * Filters the audio embed output.
  241. *
  242. * @since 3.6.0
  243. *
  244. * @param string $audio Audio embed output.
  245. * @param array $attr An array of embed attributes.
  246. * @param string $url The original URL that was matched by the regex.
  247. * @param array $rawattr The original unmodified attributes.
  248. */
  249. return apply_filters( 'wp_embed_handler_audio', $audio, $attr, $url, $rawattr );
  250. }
  251. /**
  252. * Video embed handler callback.
  253. *
  254. * @since 3.6.0
  255. *
  256. * @param array $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
  257. * @param array $attr Embed attributes.
  258. * @param string $url The original URL that was matched by the regex.
  259. * @param array $rawattr The original unmodified attributes.
  260. * @return string The embed HTML.
  261. */
  262. function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) {
  263. $dimensions = '';
  264. if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
  265. $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
  266. $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
  267. }
  268. $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) );
  269. /**
  270. * Filters the video embed output.
  271. *
  272. * @since 3.6.0
  273. *
  274. * @param string $video Video embed output.
  275. * @param array $attr An array of embed attributes.
  276. * @param string $url The original URL that was matched by the regex.
  277. * @param array $rawattr The original unmodified attributes.
  278. */
  279. return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr );
  280. }
  281. /**
  282. * Registers the oEmbed REST API route.
  283. *
  284. * @since 4.4.0
  285. */
  286. function wp_oembed_register_route() {
  287. $controller = new WP_oEmbed_Controller();
  288. $controller->register_routes();
  289. }
  290. /**
  291. * Adds oEmbed discovery links in the website <head>.
  292. *
  293. * @since 4.4.0
  294. */
  295. function wp_oembed_add_discovery_links() {
  296. $output = '';
  297. if ( is_singular() ) {
  298. $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
  299. if ( class_exists( 'SimpleXMLElement' ) ) {
  300. $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
  301. }
  302. }
  303. /**
  304. * Filters the oEmbed discovery links HTML.
  305. *
  306. * @since 4.4.0
  307. *
  308. * @param string $output HTML of the discovery links.
  309. */
  310. echo apply_filters( 'oembed_discovery_links', $output );
  311. }
  312. /**
  313. * Adds the necessary JavaScript to communicate with the embedded iframes.
  314. *
  315. * @since 4.4.0
  316. */
  317. function wp_oembed_add_host_js() {
  318. wp_enqueue_script( 'wp-embed' );
  319. }
  320. /**
  321. * Retrieves the URL to embed a specific post in an iframe.
  322. *
  323. * @since 4.4.0
  324. *
  325. * @param int|WP_Post $post Optional. Post ID or object. Defaults to the current post.
  326. * @return string|false The post embed URL on success, false if the post doesn't exist.
  327. */
  328. function get_post_embed_url( $post = null ) {
  329. $post = get_post( $post );
  330. if ( ! $post ) {
  331. return false;
  332. }
  333. $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
  334. $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) );
  335. if ( ! get_option( 'permalink_structure' ) || $path_conflict ) {
  336. $embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) );
  337. }
  338. /**
  339. * Filters the URL to embed a specific post.
  340. *
  341. * @since 4.4.0
  342. *
  343. * @param string $embed_url The post embed URL.
  344. * @param WP_Post $post The corresponding post object.
  345. */
  346. return esc_url_raw( apply_filters( 'post_embed_url', $embed_url, $post ) );
  347. }
  348. /**
  349. * Retrieves the oEmbed endpoint URL for a given permalink.
  350. *
  351. * Pass an empty string as the first argument to get the endpoint base URL.
  352. *
  353. * @since 4.4.0
  354. *
  355. * @param string $permalink Optional. The permalink used for the `url` query arg. Default empty.
  356. * @param string $format Optional. The requested response format. Default 'json'.
  357. * @return string The oEmbed endpoint URL.
  358. */
  359. function get_oembed_endpoint_url( $permalink = '', $format = 'json' ) {
  360. $url = rest_url( 'oembed/1.0/embed' );
  361. if ( '' !== $permalink ) {
  362. $url = add_query_arg( array(
  363. 'url' => urlencode( $permalink ),
  364. 'format' => ( 'json' !== $format ) ? $format : false,
  365. ), $url );
  366. }
  367. /**
  368. * Filters the oEmbed endpoint URL.
  369. *
  370. * @since 4.4.0
  371. *
  372. * @param string $url The URL to the oEmbed endpoint.
  373. * @param string $permalink The permalink used for the `url` query arg.
  374. * @param string $format The requested response format.
  375. */
  376. return apply_filters( 'oembed_endpoint_url', $url, $permalink, $format );
  377. }
  378. /**
  379. * Retrieves the embed code for a specific post.
  380. *
  381. * @since 4.4.0
  382. *
  383. * @param int $width The width for the response.
  384. * @param int $height The height for the response.
  385. * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`.
  386. * @return string|false Embed code on success, false if post doesn't exist.
  387. */
  388. function get_post_embed_html( $width, $height, $post = null ) {
  389. $post = get_post( $post );
  390. if ( ! $post ) {
  391. return false;
  392. }
  393. $embed_url = get_post_embed_url( $post );
  394. $output = '<blockquote class="wp-embedded-content"><a href="' . esc_url( get_permalink( $post ) ) . '">' . get_the_title( $post ) . "</a></blockquote>\n";
  395. $output .= "<script type='text/javascript'>\n";
  396. $output .= "<!--//--><![CDATA[//><!--\n";
  397. if ( SCRIPT_DEBUG ) {
  398. $output .= file_get_contents( ABSPATH . WPINC . '/js/wp-embed.js' );
  399. } else {
  400. /*
  401. * If you're looking at a src version of this file, you'll see an "include"
  402. * statement below. This is used by the `grunt build` process to directly
  403. * include a minified version of wp-embed.js, instead of using the
  404. * file_get_contents() method from above.
  405. *
  406. * If you're looking at a build version of this file, you'll see a string of
  407. * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
  408. * and edit wp-embed.js directly.
  409. */
  410. $output .=<<<JS
  411. !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"))f=Math.random().toString(36).substr(2,10),d.src+="#?secret="+f,d.setAttribute("data-secret",f);if(g||h)a=d.cloneNode(!0),a.removeAttribute("security"),d.parentNode.replaceChild(a,d)}}}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(~~g<200)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);
  412. JS;
  413. }
  414. $output .= "\n//--><!]]>";
  415. $output .= "\n</script>";
  416. $output .= sprintf(
  417. '<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>',
  418. esc_url( $embed_url ),
  419. absint( $width ),
  420. absint( $height ),
  421. esc_attr(
  422. sprintf(
  423. /* translators: 1: post title, 2: site name */
  424. __( '&#8220;%1$s&#8221; &#8212; %2$s' ),
  425. get_the_title( $post ),
  426. get_bloginfo( 'name' )
  427. )
  428. )
  429. );
  430. /**
  431. * Filters the embed HTML output for a given post.
  432. *
  433. * @since 4.4.0
  434. *
  435. * @param string $output The default HTML.
  436. * @param WP_Post $post Current post object.
  437. * @param int $width Width of the response.
  438. * @param int $height Height of the response.
  439. */
  440. return apply_filters( 'embed_html', $output, $post, $width, $height );
  441. }
  442. /**
  443. * Retrieves the oEmbed response data for a given post.
  444. *
  445. * @since 4.4.0
  446. *
  447. * @param WP_Post|int $post Post object or ID.
  448. * @param int $width The requested width.
  449. * @return array|false Response data on success, false if post doesn't exist.
  450. */
  451. function get_oembed_response_data( $post, $width ) {
  452. $post = get_post( $post );
  453. $width = absint( $width );
  454. if ( ! $post ) {
  455. return false;
  456. }
  457. if ( 'publish' !== get_post_status( $post ) ) {
  458. return false;
  459. }
  460. /**
  461. * Filters the allowed minimum and maximum widths for the oEmbed response.
  462. *
  463. * @since 4.4.0
  464. *
  465. * @param array $min_max_width {
  466. * Minimum and maximum widths for the oEmbed response.
  467. *
  468. * @type int $min Minimum width. Default 200.
  469. * @type int $max Maximum width. Default 600.
  470. * }
  471. */
  472. $min_max_width = apply_filters( 'oembed_min_max_width', array(
  473. 'min' => 200,
  474. 'max' => 600
  475. ) );
  476. $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
  477. $height = max( ceil( $width / 16 * 9 ), 200 );
  478. $data = array(
  479. 'version' => '1.0',
  480. 'provider_name' => get_bloginfo( 'name' ),
  481. 'provider_url' => get_home_url(),
  482. 'author_name' => get_bloginfo( 'name' ),
  483. 'author_url' => get_home_url(),
  484. 'title' => $post->post_title,
  485. 'type' => 'link',
  486. );
  487. $author = get_userdata( $post->post_author );
  488. if ( $author ) {
  489. $data['author_name'] = $author->display_name;
  490. $data['author_url'] = get_author_posts_url( $author->ID );
  491. }
  492. /**
  493. * Filters the oEmbed response data.
  494. *
  495. * @since 4.4.0
  496. *
  497. * @param array $data The response data.
  498. * @param WP_Post $post The post object.
  499. * @param int $width The requested width.
  500. * @param int $height The calculated height.
  501. */
  502. return apply_filters( 'oembed_response_data', $data, $post, $width, $height );
  503. }
  504. /**
  505. * Filters the oEmbed response data to return an iframe embed code.
  506. *
  507. * @since 4.4.0
  508. *
  509. * @param array $data The response data.
  510. * @param WP_Post $post The post object.
  511. * @param int $width The requested width.
  512. * @param int $height The calculated height.
  513. * @return array The modified response data.
  514. */
  515. function get_oembed_response_data_rich( $data, $post, $width, $height ) {
  516. $data['width'] = absint( $width );
  517. $data['height'] = absint( $height );
  518. $data['type'] = 'rich';
  519. $data['html'] = get_post_embed_html( $width, $height, $post );
  520. // Add post thumbnail to response if available.
  521. $thumbnail_id = false;
  522. if ( has_post_thumbnail( $post->ID ) ) {
  523. $thumbnail_id = get_post_thumbnail_id( $post->ID );
  524. }
  525. if ( 'attachment' === get_post_type( $post ) ) {
  526. if ( wp_attachment_is_image( $post ) ) {
  527. $thumbnail_id = $post->ID;
  528. } else if ( wp_attachment_is( 'video', $post ) ) {
  529. $thumbnail_id = get_post_thumbnail_id( $post );
  530. $data['type'] = 'video';
  531. }
  532. }
  533. if ( $thumbnail_id ) {
  534. list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
  535. $data['thumbnail_url'] = $thumbnail_url;
  536. $data['thumbnail_width'] = $thumbnail_width;
  537. $data['thumbnail_height'] = $thumbnail_height;
  538. }
  539. return $data;
  540. }
  541. /**
  542. * Ensures that the specified format is either 'json' or 'xml'.
  543. *
  544. * @since 4.4.0
  545. *
  546. * @param string $format The oEmbed response format. Accepts 'json' or 'xml'.
  547. * @return string The format, either 'xml' or 'json'. Default 'json'.
  548. */
  549. function wp_oembed_ensure_format( $format ) {
  550. if ( ! in_array( $format, array( 'json', 'xml' ), true ) ) {
  551. return 'json';
  552. }
  553. return $format;
  554. }
  555. /**
  556. * Hooks into the REST API output to print XML instead of JSON.
  557. *
  558. * This is only done for the oEmbed API endpoint,
  559. * which supports both formats.
  560. *
  561. * @access private
  562. * @since 4.4.0
  563. *
  564. * @param bool $served Whether the request has already been served.
  565. * @param WP_HTTP_ResponseInterface $result Result to send to the client. Usually a WP_REST_Response.
  566. * @param WP_REST_Request $request Request used to generate the response.
  567. * @param WP_REST_Server $server Server instance.
  568. * @return true
  569. */
  570. function _oembed_rest_pre_serve_request( $served, $result, $request, $server ) {
  571. $params = $request->get_params();
  572. if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) {
  573. return $served;
  574. }
  575. if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) {
  576. return $served;
  577. }
  578. // Embed links inside the request.
  579. $data = $server->response_to_data( $result, false );
  580. if ( ! class_exists( 'SimpleXMLElement' ) ) {
  581. status_header( 501 );
  582. die( get_status_header_desc( 501 ) );
  583. }
  584. $result = _oembed_create_xml( $data );
  585. // Bail if there's no XML.
  586. if ( ! $result ) {
  587. status_header( 501 );
  588. return get_status_header_desc( 501 );
  589. }
  590. if ( ! headers_sent() ) {
  591. $server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) );
  592. }
  593. echo $result;
  594. return true;
  595. }
  596. /**
  597. * Creates an XML string from a given array.
  598. *
  599. * @since 4.4.0
  600. * @access private
  601. *
  602. * @param array $data The original oEmbed response data.
  603. * @param SimpleXMLElement $node Optional. XML node to append the result to recursively.
  604. * @return string|false XML string on success, false on error.
  605. */
  606. function _oembed_create_xml( $data, $node = null ) {
  607. if ( ! is_array( $data ) || empty( $data ) ) {
  608. return false;
  609. }
  610. if ( null === $node ) {
  611. $node = new SimpleXMLElement( '<oembed></oembed>' );
  612. }
  613. foreach ( $data as $key => $value ) {
  614. if ( is_numeric( $key ) ) {
  615. $key = 'oembed';
  616. }
  617. if ( is_array( $value ) ) {
  618. $item = $node->addChild( $key );
  619. _oembed_create_xml( $value, $item );
  620. } else {
  621. $node->addChild( $key, esc_html( $value ) );
  622. }
  623. }
  624. return $node->asXML();
  625. }
  626. /**
  627. * Filters the given oEmbed HTML.
  628. *
  629. * If the `$url` isn't on the trusted providers list,
  630. * we need to filter the HTML heavily for security.
  631. *
  632. * Only filters 'rich' and 'html' response types.
  633. *
  634. * @since 4.4.0
  635. *
  636. * @param string $result The oEmbed HTML result.
  637. * @param object $data A data object result from an oEmbed provider.
  638. * @param string $url The URL of the content to be embedded.
  639. * @return string The filtered and sanitized oEmbed result.
  640. */
  641. function wp_filter_oembed_result( $result, $data, $url ) {
  642. if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ) ) ) {
  643. return $result;
  644. }
  645. $wp_oembed = _wp_oembed_get_object();
  646. // Don't modify the HTML for trusted providers.
  647. if ( false !== $wp_oembed->get_provider( $url, array( 'discover' => false ) ) ) {
  648. return $result;
  649. }
  650. $allowed_html = array(
  651. 'a' => array(
  652. 'href' => true,
  653. ),
  654. 'blockquote' => array(),
  655. 'iframe' => array(
  656. 'src' => true,
  657. 'width' => true,
  658. 'height' => true,
  659. 'frameborder' => true,
  660. 'marginwidth' => true,
  661. 'marginheight' => true,
  662. 'scrolling' => true,
  663. 'title' => true,
  664. ),
  665. );
  666. $html = wp_kses( $result, $allowed_html );
  667. preg_match( '|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content );
  668. // We require at least the iframe to exist.
  669. if ( empty( $content[2] ) ) {
  670. return false;
  671. }
  672. $html = $content[1] . $content[2];
  673. if ( ! empty( $content[1] ) ) {
  674. // We have a blockquote to fall back on. Hide the iframe by default.
  675. $html = str_replace( '<iframe', '<iframe style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', $html );
  676. $html = str_replace( '<blockquote', '<blockquote class="wp-embedded-content"', $html );
  677. }
  678. $html = str_replace( '<iframe', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $html );
  679. preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results );
  680. if ( ! empty( $results ) ) {
  681. $secret = wp_generate_password( 10, false );
  682. $url = esc_url( "{$results[1]}#?secret=$secret" );
  683. $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html );
  684. $html = str_replace( '<blockquote', "<blockquote data-secret=\"$secret\"", $html );
  685. }
  686. return $html;
  687. }
  688. /**
  689. * Filters the string in the 'more' link displayed after a trimmed excerpt.
  690. *
  691. * Replaces '[...]' (appended to automatically generated excerpts) with an
  692. * ellipsis and a "Continue reading" link in the embed template.
  693. *
  694. * @since 4.4.0
  695. *
  696. * @param string $more_string Default 'more' string.
  697. * @return string 'Continue reading' link prepended with an ellipsis.
  698. */
  699. function wp_embed_excerpt_more( $more_string ) {
  700. if ( ! is_embed() ) {
  701. return $more_string;
  702. }
  703. $link = sprintf( '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>',
  704. esc_url( get_permalink() ),
  705. /* translators: %s: Name of current post */
  706. sprintf( __( 'Continue reading %s' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' )
  707. );
  708. return ' &hellip; ' . $link;
  709. }
  710. /**
  711. * Displays the post excerpt for the embed template.
  712. *
  713. * Intended to be used in 'The Loop'.
  714. *
  715. * @since 4.4.0
  716. */
  717. function the_excerpt_embed() {
  718. $output = get_the_excerpt();
  719. /**
  720. * Filters the post excerpt for the embed template.
  721. *
  722. * @since 4.4.0
  723. *
  724. * @param string $output The current post excerpt.
  725. */
  726. echo apply_filters( 'the_excerpt_embed', $output );
  727. }
  728. /**
  729. * Filters the post excerpt for the embed template.
  730. *
  731. * Shows players for video and audio attachments.
  732. *
  733. * @since 4.4.0
  734. *
  735. * @param string $content The current post excerpt.
  736. * @return string The modified post excerpt.
  737. */
  738. function wp_embed_excerpt_attachment( $content ) {
  739. if ( is_attachment() ) {
  740. return prepend_attachment( '' );
  741. }
  742. return $content;
  743. }
  744. /**
  745. * Enqueue embed iframe default CSS and JS & fire do_action('enqueue_embed_scripts')
  746. *
  747. * Enqueue PNG fallback CSS for embed iframe for legacy versions of IE.
  748. *
  749. * Allows plugins to queue scripts for the embed iframe end using wp_enqueue_script().
  750. * Runs first in oembed_head().
  751. *
  752. * @since 4.4.0
  753. */
  754. function enqueue_embed_scripts() {
  755. wp_enqueue_style( 'wp-embed-template-ie' );
  756. /**
  757. * Fires when scripts and styles are enqueued for the embed iframe.
  758. *
  759. * @since 4.4.0
  760. */
  761. do_action( 'enqueue_embed_scripts' );
  762. }
  763. /**
  764. * Prints the CSS in the embed iframe header.
  765. *
  766. * @since 4.4.0
  767. */
  768. function print_embed_styles() {
  769. ?>
  770. <style type="text/css">
  771. <?php
  772. if ( SCRIPT_DEBUG ) {
  773. readfile( ABSPATH . WPINC . "/css/wp-embed-template.css" );
  774. } else {
  775. /*
  776. * If you're looking at a src version of this file, you'll see an "include"
  777. * statement below. This is used by the `grunt build` process to directly
  778. * include a minified version of wp-oembed-embed.css, instead of using the
  779. * readfile() method from above.
  780. *
  781. * If you're looking at a build version of this file, you'll see a string of
  782. * minified CSS. If you need to debug it, please turn on SCRIPT_DEBUG
  783. * and edit wp-embed-template.css directly.
  784. */
  785. ?>
  786. body,html{padding:0;margin:0}body{font-family:sans-serif}.wp-embed,.wp-embed-share-input{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",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-size:14px;font-weight:400;line-height:1.5;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:600;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:600;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-size:14px;font-weight:400;line-height:1.5;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}
  787. <?php
  788. }
  789. ?>
  790. </style>
  791. <?php
  792. }
  793. /**
  794. * Prints the JavaScript in the embed iframe header.
  795. *
  796. * @since 4.4.0
  797. */
  798. function print_embed_scripts() {
  799. ?>
  800. <script type="text/javascript">
  801. <?php
  802. if ( SCRIPT_DEBUG ) {
  803. readfile( ABSPATH . WPINC . "/js/wp-embed-template.js" );
  804. } else {
  805. /*
  806. * If you're looking at a src version of this file, you'll see an "include"
  807. * statement below. This is used by the `grunt build` process to directly
  808. * include a minified version of wp-embed-template.js, instead of using the
  809. * readfile() method from above.
  810. *
  811. * If you're looking at a build version of this file, you'll see a string of
  812. * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
  813. * and edit wp-embed-template.js directly.
  814. */
  815. ?>
  816. !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"),q=b.querySelector(".wp-embed-featured-image img");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)),q&&q.addEventListener("load",function(){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);
  817. <?php
  818. }
  819. ?>
  820. </script>
  821. <?php
  822. }
  823. /**
  824. * Prepare the oembed HTML to be displayed in an RSS feed.
  825. *
  826. * @since 4.4.0
  827. * @access private
  828. *
  829. * @param string $content The content to filter.
  830. * @return string The filtered content.
  831. */
  832. function _oembed_filter_feed_content( $content ) {
  833. 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 );
  834. }
  835. /**
  836. * Prints the necessary markup for the embed comments button.
  837. *
  838. * @since 4.4.0
  839. */
  840. function print_embed_comments_button() {
  841. if ( is_404() || ! ( get_comments_number() || comments_open() ) ) {
  842. return;
  843. }
  844. ?>
  845. <div class="wp-embed-comments">
  846. <a href="<?php comments_link(); ?>" target="_top">
  847. <span class="dashicons dashicons-admin-comments"></span>
  848. <?php
  849. printf(
  850. _n(
  851. '%s <span class="screen-reader-text">Comment</span>',
  852. '%s <span class="screen-reader-text">Comments</span>',
  853. get_comments_number()
  854. ),
  855. number_format_i18n( get_comments_number() )
  856. );
  857. ?>
  858. </a>
  859. </div>
  860. <?php
  861. }
  862. /**
  863. * Prints the necessary markup for the embed sharing button.
  864. *
  865. * @since 4.4.0
  866. */
  867. function print_embed_sharing_button() {
  868. if ( is_404() ) {
  869. return;
  870. }
  871. ?>
  872. <div class="wp-embed-share">
  873. <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">
  874. <span class="dashicons dashicons-share"></span>
  875. </button>
  876. </div>
  877. <?php
  878. }
  879. /**
  880. * Prints the necessary markup for the embed sharing dialog.
  881. *
  882. * @since 4.4.0
  883. */
  884. function print_embed_sharing_dialog() {
  885. if ( is_404() ) {
  886. return;
  887. }
  888. ?>
  889. <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>">
  890. <div class="wp-embed-share-dialog-content">
  891. <div class="wp-embed-share-dialog-text">
  892. <ul class="wp-embed-share-tabs" role="tablist">
  893. <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation">
  894. <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button>
  895. </li>
  896. <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation">
  897. <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button>
  898. </li>
  899. </ul>
  900. <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false">
  901. <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly/>
  902. <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress">
  903. <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?>
  904. </p>
  905. </div>
  906. <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true">
  907. <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>
  908. <p class="wp-embed-share-description" id="wp-embed-share-description-html">
  909. <?php _e( 'Copy and paste this code into your site to embed' ); ?>
  910. </p>
  911. </div>
  912. </div>
  913. <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>">
  914. <span class="dashicons dashicons-no"></span>
  915. </button>
  916. </div>
  917. </div>
  918. <?php
  919. }
  920. /**
  921. * Prints the necessary markup for the site title in an embed template.
  922. *
  923. * @since 4.5.0
  924. */
  925. function the_embed_site_title() {
  926. $site_title = sprintf(
  927. '<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>',
  928. esc_url( home_url() ),
  929. esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ),
  930. esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ),
  931. esc_html( get_bloginfo( 'name' ) )
  932. );
  933. $site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>';
  934. /**
  935. * Filters the site title HTML in the embed footer.
  936. *
  937. * @since 4.4.0
  938. *
  939. * @param string $site_title The site title HTML.
  940. */
  941. echo apply_filters( 'embed_site_title_html', $site_title );
  942. }
  943. /**
  944. * Filters the oEmbed result before any HTTP requests are made.
  945. *
  946. * If the URL belongs to the current site, the result is fetched directly instead of
  947. * going through the oEmbed discovery process.
  948. *
  949. * @since 4.5.3
  950. *
  951. * @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null.
  952. * @param string $url The URL that should be inspected for discovery `<link>` tags.
  953. * @param array $args oEmbed remote get arguments.
  954. * @return null|string The UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
  955. * Null if the URL does not belong to the current site.
  956. */
  957. function wp_filter_pre_oembed_result( $result, $url, $args ) {
  958. $post_id = url_to_postid( $url );
  959. /** This filter is documented in wp-includes/class-wp-oembed-controller.php */
  960. $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url );
  961. if ( ! $post_id ) {
  962. return $result;
  963. }
  964. $width = isset( $args['width'] ) ? $args['width'] : 0;
  965. $data = get_oembed_response_data( $post_id, $width );
  966. $data = _wp_oembed_get_object()->data2html( (object) $data, $url );
  967. if ( ! $data ) {
  968. return $result;
  969. }
  970. return $data;
  971. }