get_media_embedded_in_content() - WordPress 函数参考中文文档

返回介绍

get_media_embedded_in_content()

发布于 2017-09-10 字数2210 浏览 940 评论 0

get_media_embedded_in_content( string $content,  array $types = null )

Check the content blob for an audio, video, object, embed, or iframe tags.


描述


参数

$content

(string)
(Required)
A string which might contain media data.

$types

(array)
(Optional)
An array of media types: ‘audio’, ‘video’, ‘object’, ’embed’, or ‘iframe’.

Default value: null


返回值

(array) A list of found HTML media embeds.


源代码

File: wp-includes/media.php

function get_media_embedded_in_content( $content, $types = null ) {
	$html = array();

	/**
	 * Filters the embedded media types that are allowed to be returned from the content blob.
	 *
	 * @since 4.2.0
	 *
	 * @param array $allowed_media_types An array of allowed media types. Default media types are
	 *                                   'audio', 'video', 'object', 'embed', and 'iframe'.
	 */
	$allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );

	if ( ! empty( $types ) ) {
		if ( ! is_array( $types ) ) {
			$types = array( $types );
		}

		$allowed_media_types = array_intersect( $allowed_media_types, $types );
	}

	$tags = implode( '|', $allowed_media_types );

	if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) {
		foreach ( $matches[0] as $match ) {
			$html[] = $match;
		}
	}

	return $html;
}

更新日志

Version 描述
3.6.0 Introduced.

相关函数

Uses

  • wp-includes/media.php:
    media_embedded_in_content_allowed_types
  • wp-includes/plugin.php:
    apply_filters()

User Contributed Notes

上一篇:get_main_network_id()

下一篇:get_media_item()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!