检查音频,视频,对象,嵌入或iframe标记的内容blob。

原型

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

参数

$content (string) (Required) 可能包含媒体数据的字符串。

$types (array) (Optional) 一系列媒体类型:“音频”,“视频”,“对象”,“嵌入”或“iframe”。

返回值

(array)  找到的HTML媒体嵌入列表。

源文件

路径:wp-includes/media.php

<?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 . ')[^<]*?(?:>[sS]*?</(?P=tag)>|s*/>)#', $content, $matches ) ) {
		foreach ( $matches[0] as $match ) {
			$html[] = $match;
		}
	}
	return $html;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_media_embedded_in_content/