• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / get_oembed_response_data_for_url() – Retrieves the oEmbed response data for a given URL.

You appear to be a bot. Output may be restricted

Description

Retrieves the oEmbed response data for a given URL.

Usage

$object|false = get_oembed_response_data_for_url( $url, $args );

Parameters

$url
( string ) required – The URL that should be inspected for discovery <link> tags.
$args
( array ) required – oEmbed remote get arguments.

Returns

object|false oEmbed response data if the URL does belong to the current site. False otherwise.

Source

File name: wordpress/wp-includes/embed.php


Lines:

1 to 68 of 68
function get_oembed_response_data_for_url( $url, $args ) {
  $switched_blog = false;

  if ( is_multisite() ) {
    $url_parts = wp_parse_args(
      wp_parse_url( $url ),
      array(
        'host' => '',
        'path' => '/',
      )
    );

    $qv = array(
      'domain'                 => $url_parts['host'],
      'path'                   => '/',
      'update_site_meta_cache' => false,
    );

    // In case of subdirectory configs, set the path.
    if ( ! is_subdomain_install() ) {
      $path = explode( '/', ltrim( $url_parts['path'], '/' ) );
      $path = reset( $path );

      if ( $path ) {
        $qv['path'] = get_network()->path . $path . '/';
      }
    }

    $sites = get_sites( $qv );
    $site  = reset( $sites );

    // Do not allow embeds for deleted/archived/spam sites.
    if ( ! empty( $site->deleted ) || ! empty( $site->spam ) || ! empty( $site->archived ) ) {
      return false;
    }

    if ( $site && get_current_blog_id() !== (int) $site->blog_id ) {
      switch_to_blog( $site->blog_id );
      $switched_blog = true;
    }
  }

  $post_id = url_to_postid( $url );

  
/** This filter is documented in wp-includes/class-wp-oembed-controller.php */
  $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url );

  if ( ! $post_id ) {
    if ( $switched_blog ) {
      restore_current_blog();
    }

    return false;
  }

  $width = isset( $args['width'] ) ? $args['width'] : 0;

  $data = get_oembed_response_data( $post_id, $width );

  if ( $switched_blog ) {
    restore_current_blog();
  }

  return $data ? (object) $data : false;
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 9th December 2020

Primary Sidebar

Information

Function name: get_oembed_response_data_for_url
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/embed.php
File ref: wp-includes/embed.php
Deprecated?: No
API Letters: D,F,G,O,R

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites