Checks the HTML content for an audio, video, object, embed, or iframe tags.
Parameters
$content
stringrequired- A string of HTML which might contain media elements.
$types
string[]optional- An array of media types:
'audio'
,'video'
,'object'
,'embed'
, or'iframe'
.Default:
null
Source
*
* @since 3.6.0
*
* @param string $content A string of HTML which might contain media elements.
* @param string[] $types An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'.
* @return string[] Array of found HTML media elements.
*/
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 ) ) {
Changelog
Version | Description |
---|---|
3.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.