Brak opisu

embed.php 47KB

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