diff --git a/wp-includes/media.php b/wp-includes/media.php index 070ac2ae02..0e18bea944 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1821,6 +1821,135 @@ function get_attached_video( $post_id = 0 ) { return $children; } +/** + * Extract the srcs from the post's [{media type}] s + * + * @since 3.6.0 + * + * @param string $content A string which might contain media data. + * @param boolean $remove Whether to remove the found URL from the passed content. + * @return array A list of lists. Each item has a list of sources corresponding + * to a [{media type}]'s primary src and specified fallbacks + */ +function get_content_media( $type, &$content, $remove = false ) { + $src = ''; + $items = array(); + $matches = array(); + + if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { + foreach ( $matches as $shortcode ) { + if ( $type === $shortcode[2] ) { + $srcs = array(); + $count = 1; + if ( $remove ) + $content = str_replace( $shortcode[0], '', $content, $count ); + + $item = do_shortcode_tag( $shortcode ); + preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER ); + if ( ! empty( $src ) ) { + foreach ( $src as $s ) + $srcs[] = $s[1]; + + $items[] = array_values( array_unique( $srcs ) ); + } + } + } + } + return $items; +} + +/** + * Check the content blob for an <{media type}>, , , or