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