diff --git a/wp-includes/media.php b/wp-includes/media.php index e8785718b3..206d5394d6 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2022,110 +2022,6 @@ function get_embedded_video( $content ) { return get_embedded_media( 'video', $content ); } -/** - * Return suitable HTML code for output based on the content related to the global $post - * - * @since 3.6.0 - * - * @param string $type Required. 'audio' or 'video' - * @param WP_Post $post Optional. Used instead of global $post when passed. - * @param int $limit Optional. The number of medias to extract if content is scanned. - * @return string HTML for the media. Blank string if no media is found. - */ -function get_the_post_format_media( $type, &$post = null, $limit = 0 ) { - global $wp_embed; - - if ( empty( $post ) ) - $post = get_post(); - - if ( empty( $post ) ) - return ''; - - $cache_key = "media:{$type}"; - - if ( isset( $post->format_content[ $cache_key ] ) ) - return $post->format_content[ $cache_key ]; - - if ( ! isset( $post->format_content ) ) - $post->format_content = array(); - - $count = 1; - - // these functions expect a reference, so we should make a copy of post content to avoid changing it - $content = $post->post_content; - - $htmls = get_content_media( $type, $content, true, $limit ); - if ( ! empty( $htmls ) ) { - $html = reset( $htmls ); - $post->format_content[ $cache_key ] = $html; - return $post->format_content[ $cache_key ]; - } - - $embeds = get_embedded_media( $type, $content, 1 ); - if ( ! empty( $embeds ) ) { - $embed = reset( $embeds ); - if ( 0 === strpos( $embed, 'http' ) ) { - if ( strstr( $embed, home_url() ) ) { - - $format_content = ''; - $attr = array( 'src' => $embed ); - - if ( 'audio' == $type ) - $format_content = wp_audio_shortcode( $attr ); - elseif ( 'video' == $type ) - $format_content = wp_video_shortcode( $attr ); - - $post->format_content[ $cache_key ] = $format_content; - } else { - $post->format_content[ $cache_key ] = $wp_embed->autoembed( $embed ); - } - } else { - $post->format_content[ $cache_key ] = $embed; - } - return $post->format_content[ $cache_key ]; - } - - $medias = call_user_func( 'get_attached_' . $type, $post->ID ); - if ( ! empty( $medias ) ) { - $media = reset( $medias ); - $url = wp_get_attachment_url( $media->ID ); - - $format_content = ''; - $attr = array( 'src' => $url ); - - if ( 'audio' == $type ) - $format_content = wp_audio_shortcode( $attr ); - elseif ( 'video' == $type ) - $format_content = wp_video_shortcode( $attr ); - - $post->format_content[ $cache_key ] = $format_content; - return $post->format_content[ $cache_key ]; - } - - return ''; -} - -/** - * Output the first video in the current (@global) post's content - * - * @since 3.6.0 - * - */ -function the_post_format_video() { - $null = null; - echo get_the_post_format_media( 'video', $null, 1 ); -} -/** - * Output the first audio in the current (@global) post's content - * - * @since 3.6.0 - * - */ -function the_post_format_audio() { - $null = null; - echo get_the_post_format_media( 'audio', $null, 1 ); -} - /** * Retrieve images attached to the passed post * @@ -2371,116 +2267,6 @@ function get_post_gallery_images( $post_id = 0 ) { return $gallery['src']; } -/** - * Return the first image in the current (@global) post's content - * - * @since 3.6.0 - * - * @param string $attached_size If an attached image is found, the size to display it. - * @param WP_Post $post Optional. Used instead of global $post when passed. - * @return string HTML for the image. Blank string if no image is found. - */ -function get_the_post_format_image( $attached_size = 'full', &$post = null ) { - if ( empty( $post ) ) - $post = get_post(); - - if ( empty( $post ) ) - return ''; - - $cache_key = "image:{$attached_size}"; - - if ( isset( $post->format_content[ $cache_key ] ) ) - return $post->format_content[ $cache_key ]; - - if ( ! isset( $post->format_content ) ) - $post->format_content = array(); - - $matched = false; - $link_fmt = '%s'; - - $medias = get_attached_images( $post->ID ); - if ( ! empty( $medias ) ) { - $media = reset( $medias ); - $sizes = get_intermediate_image_sizes(); - $sizes[] = 'full'; // Add original image source. - - $urls = array(); - foreach ( $sizes as $size ) { - $image = wp_get_attachment_image_src( $media->ID, $size ); - if ( $image ) - $urls[] = reset( $image ); - } - - // Add media permalink. - $urls[] = get_attachment_link( $media->ID ); - - $count = 1; - $content = $post->post_content; - - if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { - foreach ( $matches as $shortcode ) { - if ( 'caption' === $shortcode[2] ) { - foreach ( $urls as $url ) { - if ( strstr( $shortcode[0], $url ) ) { - if ( ! $matched ) - $matched = do_shortcode_tag( $shortcode ); - } - } - } - } - } - - foreach ( array( 'a', 'img' ) as $tag ) { - if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { - foreach ( $matches as $match ) { - foreach ( $urls as $url ) { - if ( strstr( $match[0], $url ) ) { - if ( ! $matched ) - $matched = $match[0]; - } - } - } - } - } - - if ( ! $matched ) { - $image = wp_get_attachment_image( $media->ID, $attached_size ); - $post->format_content[ $cache_key ] = sprintf( $link_fmt, $image ); - } else { - $post->format_content[ $cache_key ] = $matched; - if ( ! empty( $meta['url'] ) && false === stripos( $matched, 'format_content[ $cache_key ] = sprintf( $link_fmt, $matched ); - } - return $post->format_content[ $cache_key ]; - } - - $content = $post->post_content; - $htmls = get_content_images( $content, true, 1 ); - if ( ! empty( $htmls ) ) { - $html = reset( $htmls ); - - $attachment_id = img_html_to_post_id( $html, $matched_html ); - if ( $attachment_id && $matched_html ) - $html = str_replace( $matched_html, wp_get_attachment_image( $attachment_id, $attached_size ), $html ); - - $post->format_content[ $cache_key ] = sprintf( $link_fmt, $html ); - return $post->format_content[ $cache_key ]; - } - - return ''; -} - -/** - * Output the first image in the current (@global) post's content - * - * @since 3.6.0 - * - * @param string $attached_size If an attached image is found, the size to display it. - */ -function the_post_format_image( $attached_size = 'full' ) { - echo get_the_post_format_image( $attached_size ); -} - /** * Retrieve the attachment post id from HTML containing an image. *