get_oembed_response_data_for_url()
最后更新于:2021-11-26 10:32:41
get_oembed_response_data_for_url( string$url, array$args)Retrieves the oEmbed response data for a given URL.
参数
- $url
-
(string) (Required) The URL that should be inspected for discovery
<link>
tags. - $args
-
(array) (Required) oEmbed remote get arguments.
响应
(object|false) oEmbed response data if the URL does belong to the current site. False otherwise.
源文件
文件: gc-includes/embed.php
function get_oembed_response_data_for_url( $url, $args ) {
$switched_blog = false;
if ( is_multisite() ) {
$url_parts = gc_parse_args(
gc_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 gc-includes/class-gc-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;
}