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


Generated: Thu Jul 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1