Changeset 31574
- Timestamp:
- 02/27/2015 04:11:00 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r31530 r31574 3221 3221 function get_media_embedded_in_content( $content, $types = null ) { 3222 3222 $html = array(); 3223 $allowed_media_types = array( 'audio', 'video', 'object', 'embed', 'iframe' ); 3223 3224 $allowed_media_types = apply_filters( 'get_media_embedded_in_content_allowed', array( 'audio', 'video', 'object', 'embed', 'iframe' ) ); 3225 3224 3226 if ( ! empty( $types ) ) { 3225 if ( ! is_array( $types ) ) 3227 if ( ! is_array( $types ) ) { 3226 3228 $types = array( $types ); 3229 } 3230 3227 3231 $allowed_media_types = array_intersect( $allowed_media_types, $types ); 3228 3232 } 3229 3233 3230 foreach ( $allowed_media_types as $tag ) { 3231 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) { 3232 $html[] = $matches[0]; 3234 $tags = implode( '|', $allowed_media_types ); 3235 3236 if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) { 3237 foreach ( $matches[0] as $match ) { 3238 $html[] = $match; 3233 3239 } 3234 3240 } -
trunk/tests/phpunit/tests/media.php
r31239 r31574 379 379 CONTENT; 380 380 381 $types = array( ' audio', 'video', 'object', 'embed', 'iframe' );381 $types = array( 'object', 'embed', 'iframe', 'audio', 'video' ); 382 382 $contents = array_values( compact( $types ) ); 383 383 … … 399 399 $matches = get_media_embedded_in_content( $content, $types ); 400 400 $this->assertEquals( $contents, $matches ); 401 } 402 403 function test_get_media_embedded_in_content_order() { 404 $audio =<<<AUDIO 405 <audio preload="none"> 406 <source /> 407 </audio> 408 AUDIO; 409 $video =<<<VIDEO 410 <video preload="none"> 411 <source /> 412 </video> 413 VIDEO; 414 $content = $audio . $video; 415 416 $matches1 = get_media_embedded_in_content( $content, array( 'audio', 'video' ) ); 417 $this->assertEquals( array( $audio, $video ), $matches1 ); 418 419 $reversed = $video . $audio; 420 $matches2 = get_media_embedded_in_content( $reversed, array( 'audio', 'video' ) ); 421 $this->assertEquals( array( $video, $audio ), $matches2 ); 401 422 } 402 423
Note: See TracChangeset
for help on using the changeset viewer.