функция
since 3.6.0
get_media_embedded_in_content()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_media_embedded_in_content( string $content, string[] $types = null ): string[]
Описание
Проверяет HTML-содержимое на наличие тегов audio, video, object, embed или iframe.
Параметры
$content
string
обязательный
Строка HTML, которая может содержать медиа-элементы.
$types
string[]
необязательный
= null
Массив типов медиа: 'audio', 'video', 'object', 'embed' или 'iframe'.
Возвращаемое значение
string[]
Исходный код
wp-includes/media.php:5214
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 string[] $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;
}
История изменений
| Версия | Описание |
|---|---|
| 3.6.0 | Introduced. |

