Improve `get_media_embedded_in_content()` so that it returns the media it finds in the same order that it appears in the content.

Adds unit test, updates another.

Props kopepasah.
See #26675.

Built from https://develop.svn.wordpress.org/trunk@31574


git-svn-id: http://core.svn.wordpress.org/trunk@31555 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-02-27 16:11:25 +00:00
parent d2f0abf85f
commit 295af37bd0
2 changed files with 12 additions and 6 deletions

View File

@ -3220,16 +3220,22 @@ function get_attached_media( $type, $post = 0 ) {
*/
function get_media_embedded_in_content( $content, $types = null ) {
$html = array();
$allowed_media_types = array( 'audio', 'video', 'object', 'embed', 'iframe' );
$allowed_media_types = apply_filters( 'get_media_embedded_in_content_allowed', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );
if ( ! empty( $types ) ) {
if ( ! is_array( $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];
$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;
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-alpha-31573';
$wp_version = '4.2-alpha-31574';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.