WordPress.org

Make WordPress Core

Ticket #24052: 24052.diff

File 24052.diff, 3.2 KB (added by wonderboymusic, 12 months ago)
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index e74cd02..6b2ecfd 100644
    function get_attached_video( $post_id = 0 ) { 
    18401840 * @param string $content A string which might contain media data. 
    18411841 * @param boolean $html Whether to return HTML or URLs 
    18421842 * @param boolean $remove Whether to remove the found URL from the passed content. 
     1843 * @param int $limit Optional. The number of medias to return 
    18431844 * @return array A list of parsed shortcodes or extracted srcs 
    18441845 */ 
    1845 function get_content_media( $type, &$content, $html = true, $remove = false ) { 
     1846function get_content_media( $type, &$content, $html = true, $remove = false, $limit = 0 ) { 
    18461847        $items = array(); 
    18471848        $matches = array(); 
    18481849 
    function get_content_media( $type, &$content, $html = true, $remove = false ) { 
    18541855                                        $content =& str_replace( $shortcode[0], '', $content, $count ); 
    18551856 
    18561857                                $items[] = do_shortcode_tag( $shortcode ); 
     1858                                if ( $limit > 0 && count( $items ) >= $limit ) 
     1859                                        break; 
    18571860                        } 
    18581861                } 
    18591862        } 
    wp_embed_register_handler( 'wp_video_embed', '#https?://.+?\.(' . join( '|', wp_ 
    20292032 * 
    20302033 * @param string $type Required. 'audio' or 'video' 
    20312034 * @param WP_Post $post Optional. Used instead of global $post when passed. 
     2035 * @param int $limit Optional. The number of medias to remove if content is scanned. 
    20322036 * @return string 
    20332037 */ 
    2034 function get_the_post_format_media( $type, &$post = null ) { 
     2038function get_the_post_format_media( $type, &$post = null, $limit = 0 ) { 
    20352039        global $wp_embed; 
    20362040 
    20372041        if ( empty( $post ) ) 
    function get_the_post_format_media( $type, &$post = null ) { 
    20762080        // these functions expect a reference, so we should make a copy of post content to avoid changing it 
    20772081        $content = $post->post_content; 
    20782082 
    2079         $htmls = get_content_media( $type, $content, true, true ); 
     2083        $htmls = get_content_media( $type, $content, true, true, $limit ); 
    20802084        if ( ! empty( $htmls ) ) { 
    20812085                $html = reset( $htmls ); 
    20822086                $post->split_content = $content; 
    function get_the_post_format_media( $type, &$post = null ) { 
    21192123 * 
    21202124 */ 
    21212125function the_post_format_video() { 
    2122         echo get_the_post_format_media( 'video' ); 
     2126        echo get_the_post_format_media( 'video', null, 1 ); 
    21232127} 
    21242128/** 
    21252129 * Output the first audio  in the current (@global) post's content 
    function the_post_format_video() { 
    21282132 * 
    21292133 */ 
    21302134function the_post_format_audio() { 
    2131         echo get_the_post_format_media( 'audio' ); 
     2135        echo get_the_post_format_media( 'audio', null, 1 ); 
    21322136} 
    21332137 
    21342138/** 
  • wp-includes/query.php

    diff --git wp-includes/query.php wp-includes/query.php
    index e42404c..3b41af4 100644
    function setup_postdata($post) { 
    37023702                                $split_content = $post->split_content; 
    37033703                        break; 
    37043704                case 'audio': 
    3705                         get_the_post_format_media( 'audio', $post ); 
     3705                        get_the_post_format_media( 'audio', $post, 1 ); 
    37063706                        if ( isset( $post->split_content ) ) 
    37073707                                $split_content = $post->split_content; 
    37083708                        break; 
    37093709                case 'video': 
    3710                         get_the_post_format_media( 'video', $post ); 
     3710                        get_the_post_format_media( 'video', $post, 1 ); 
    37113711                        if ( isset( $post->split_content ) ) 
    37123712                                $split_content = $post->split_content; 
    37133713                        break;