[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> embed.php (source)

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


Generated: Mon Jul 22 01:00:03 2019 Cross-referenced by PHPXref 0.7.1