WordPress.org

Make WordPress Core

Ticket #26675: 26675.patch

File 26675.patch, 2.0 KB (added by kopepasah, 4 years ago)
  • wp-includes/media.php

     
    19771977}
    19781978
    19791979/**
    1980  * Check the content blob for an <audio>, <video> <object>, <embed>, or <iframe>
     1980 * Check the content blob for an <img>, <audio>, <video> <object>, <embed>, or <iframe>
    19811981 *
    19821982 * @since 3.6.0
    19831983 *
    19841984 * @param string $content A string which might contain media data.
    1985  * @param array $types array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'
     1985 * @param array $types array of media types: 'img', 'audio', 'video', 'object', 'embed', or 'iframe'
     1986 * @param string $sortby A string which defines how to sort the results.
    19861987 * @return array A list of found HTML media embeds
    19871988 */
    1988 function get_media_embedded_in_content( $content, $types = null ) {
     1989function get_media_embedded_in_content( $content, $types = null, $sortby = 'type' ) {
    19891990        $html = array();
    1990         $allowed_media_types = array( 'audio', 'video', 'object', 'embed', 'iframe' );
     1991
     1992        $allowed_media_types = array( 'audio', 'video', 'object', 'embed', 'iframe', 'img' );
    19911993        if ( ! empty( $types ) ) {
    1992                 if ( ! is_array( $types ) )
     1994                if ( ! is_array( $types ) ) {
    19931995                        $types = array( $types );
     1996                }
    19941997                $allowed_media_types = array_intersect( $allowed_media_types, $types );
    19951998        }
    19961999
    1997         foreach ( $allowed_media_types as $tag ) {
    1998                 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
    1999                         $html[] = $matches[0];
     2000        if ( 'source' == $sortby ) {
     2001                $tags = implode( '|', $allowed_media_types );
     2002
     2003                if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) {
     2004                        foreach ( $matches[0] as $match ) {
     2005                                $html[] = $match;
     2006                        }
     2007                }
     2008        } else {
     2009                foreach ( $allowed_media_types as $tag ) {
     2010                        if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
     2011                                foreach ( $matches[0] as $match ) {
     2012                                        $html[] = $match;
     2013                                }
     2014                        }
    20002015                }
    20012016        }
    20022017