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


Generated: Mon Dec 9 01:00:03 2019 Cross-referenced by PHPXref 0.7.1