get_media_embedded_in_content

The timeline below displays how wordpress function get_media_embedded_in_content has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Checks the HTML content for an audio, video, object, embed, or iframe tags.
 *
 * @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)) {
        foreach ($matches[0] as $match) {
            $html[] = $match;
        }
    }
    return $html;
}

WordPress Version: 6.1

/**
 * Checks the HTML content for a audio, video, object, embed, or iframe tags.
 *
 * @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)) {
        foreach ($matches[0] as $match) {
            $html[] = $match;
        }
    }
    return $html;
}

WordPress Version: 5.4

/**
 * Check the content HTML for a audio, video, object, embed, or iframe tags.
 *
 * @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)) {
        foreach ($matches[0] as $match) {
            $html[] = $match;
        }
    }
    return $html;
}

WordPress Version: 4.6

/**
 * Check the content blob for an audio, video, object, embed, or iframe tags.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain media data.
 * @param array  $types   An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'.
 * @return array A list of found HTML media embeds.
 */
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;
}

WordPress Version: 4.2

/**
 * Check the content blob for an audio, video, object, embed, or iframe tags.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain media data.
 * @param array  $types   An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'.
 * @return array A list of found HTML media embeds.
 */
function get_media_embedded_in_content($content, $types = null)
{
    $html = array();
    /**
     * Filter 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;
}

WordPress Version: 4.1

/**
 * Check the content blob for an audio, video, object, embed, or iframe tags.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain media data.
 * @param array $types array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'
 * @return array A list of found HTML media embeds
 */
function get_media_embedded_in_content($content, $types = null)
{
    $html = array();
    $allowed_media_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);
    }
    foreach ($allowed_media_types as $tag) {
        if (preg_match('#' . get_tag_regex($tag) . '#', $content, $matches)) {
            $html[] = $matches[0];
        }
    }
    return $html;
}

WordPress Version: 3.7

/**
 * Check the content blob for an <audio>, <video> <object>, <embed>, or <iframe>
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain media data.
 * @param array $types array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'
 * @return array A list of found HTML media embeds
 */
function get_media_embedded_in_content($content, $types = null)
{
    $html = array();
    $allowed_media_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);
    }
    foreach ($allowed_media_types as $tag) {
        if (preg_match('#' . get_tag_regex($tag) . '#', $content, $matches)) {
            $html[] = $matches[0];
        }
    }
    return $html;
}