返回介绍

get_oembed_response_data()

发布于 2017-09-10 23:39:44 字数 3394 浏览 1023 评论 0 收藏 0

get_oembed_response_data( WP_Post|int $post,  int $width )

Retrieves the oEmbed response data for a given post.


description


参数

$post

(WP_Post|int) (Required) Post object or ID.

$width

(int) (Required) The requested width.


返回值

(array|false) Response data on success, false if post doesn't exist.


源代码

File: wp-includes/embed.php

function get_oembed_response_data( $post, $width ) {
	$post  = get_post( $post );
	$width = absint( $width );

	if ( ! $post ) {
		return false;
	}

	if ( 'publish' !== get_post_status( $post ) ) {
		return false;
	}

	/**
	 * Filters the allowed minimum and maximum widths for the oEmbed response.
	 *
	 * @since 4.4.0
	 *
	 * @param array $min_max_width {
	 *     Minimum and maximum widths for the oEmbed response.
	 *
	 *     @type int $min Minimum width. Default 200.
	 *     @type int $max Maximum width. Default 600.
	 * }
	 */
	$min_max_width = apply_filters( 'oembed_min_max_width', array(
		'min' => 200,
		'max' => 600
	) );

	$width  = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
	$height = max( ceil( $width / 16 * 9 ), 200 );

	$data = array(
		'version'       => '1.0',
		'provider_name' => get_bloginfo( 'name' ),
		'provider_url'  => get_home_url(),
		'author_name'   => get_bloginfo( 'name' ),
		'author_url'    => get_home_url(),
		'title'         => $post->post_title,
		'type'          => 'link',
	);

	$author = get_userdata( $post->post_author );

	if ( $author ) {
		$data['author_name'] = $author->display_name;
		$data['author_url']  = get_author_posts_url( $author->ID );
	}

	/**
	 * Filters the oEmbed response data.
	 *
	 * @since 4.4.0
	 *
	 * @param array   $data   The response data.
	 * @param WP_Post $post   The post object.
	 * @param int     $width  The requested width.
	 * @param int     $height The calculated height.
	 */
	return apply_filters( 'oembed_response_data', $data, $post, $width, $height );
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/embed.php: oembed_min_max_width
  • wp-includes/embed.php: oembed_response_data
  • wp-includes/pluggable.php: get_userdata()
  • wp-includes/general-template.php: get_bloginfo()
  • wp-includes/functions.php: absint()
  • wp-includes/link-template.php: get_home_url()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_post()
  • wp-includes/post.php: get_post_status()
  • wp-includes/author-template.php: get_author_posts_url()
  • Show 5 more uses Hide more uses

Used By

  • wp-includes/embed.php: wp_filter_pre_oembed_result()
  • wp-includes/class-wp-oembed-controller.php: WP_oEmbed_Controller::get_item()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文