Make WordPress Core

Ticket #24202: 24202.3.diff

File 24202.3.diff, 22.5 KB (added by kovshenin, 13 years ago)
  • wp-includes/post-formats.php

     
    353353                                if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) {
    354354                                        $url = $meta['link_url'];
    355355                                } else {
    356                                         $url = get_content_url( $content, true );
     356                                        $url = get_content_url( $content, array( 'remove' => true ) );
    357357                                }
    358358                        } else {
    359359                                $content_before = $content;
    360                                 $url = get_content_url( $content, true );
     360                                $url = get_content_url( $content, array( 'remove' => true ) );
    361361                                if ( $content_before == $content )
    362362                                        $url = '';
    363363                        }
     
    418418                        $quote = get_the_post_format_quote( $post );
    419419
    420420                        // Replace the existing quote in-place.
    421                         if ( ! empty( $quote ) )
    422                                 get_content_quote( $content, true, $quote );
     421                        if ( ! empty( $quote ) ) {
     422                                get_content_quote( $content, array(
     423                                        'remove'  => true,
     424                                        'replace' => $quote,
     425                                ) );
     426                        }
    423427                        break;
    424428
    425429                case 'video':
     
    523527 *     )
    524528 * )
    525529 *
     530 * $args contents:
     531 * - remove - Whether to remove the found data from the passed content.
     532 *
    526533 * @since 3.6.0
    527534 *
    528535 * @param string $content A string which might contain chat data, passed by reference.
    529  * @param boolean $remove Whether to remove the found data from the passed content.
     536 * @param array $args (optional) arguments.
    530537 * @return array A chat log as structured data
    531538 */
    532 function get_content_chat( &$content, $remove = false ) {
     539function get_content_chat( &$content, $args = array() ) {
    533540        global $_wp_chat_parsers;
    534541
     542        $defaults = array(
     543                'remove' => false,
     544        );
     545
     546        $args = wp_parse_args( $args, $defaults );
     547
    535548        $trimmed = strip_tags( trim( $content ) );
    536549        if ( empty( $trimmed ) )
    537550                return array();
     
    620633        if ( ! empty( $stanza ) )
    621634                $stanzas[] = $stanza;
    622635
    623         if ( $remove ) {
     636        if ( $args['remove'] ) {
    624637                if ( 0 === $found_index ) {
    625638                        $removed = array_slice( $lines, $last_index );
    626639                } else {
     
    639652 *
    640653 * @since 3.6.0
    641654 *
    642  * @param int $id (optional) The post ID.
     655 * @uses get_content_chat()
     656 *
     657 * @param int $post_id (optional) The post ID.
    643658 * @return array The chat content.
    644659 */
    645 function get_the_post_format_chat( $id = 0 ) {
    646         $post = empty( $id ) ? clone get_post() : get_post( $id );
     660function get_the_post_format_chat( $post_id = 0 ) {
     661        $post = empty( $post_id ) ? clone get_post() : get_post( $post_id );
    647662        if ( empty( $post ) )
    648663                return array();
    649664
    650         $data = get_content_chat( get_paged_content( $post->post_content ) );
     665        $content = get_paged_content( $post->post_content );
     666        $data = get_content_chat( $content );
    651667        if ( empty( $data ) )
    652668                return array();
    653669
     
    697713 * If $content does not have a blockquote, assume the whole string
    698714 * is the quote.
    699715 *
     716 * $args contents:
     717 * - remove - Whether to remove the quote from the content.
     718 * - replace - Content to replace the quote content with.
     719 *
    700720 * @since 3.6.0
    701721 *
    702722 * @param string $content A string which might contain chat data, passed by reference.
    703  * @param bool $remove (optional) Whether to remove the quote from the content.
    704  * @param string $replace (optional) Content to replace the quote content with.
     723 * @param array $args An optional array of arguments.
    705724 * @return string The quote content.
    706725 */
    707 function get_content_quote( &$content, $remove = false, $replace = '' ) {
     726function get_content_quote( &$content, $args = array() ) {
     727        $defaults = array(
     728                'remove'  => false,
     729                'replace' => '',
     730        );
     731
     732        $args = wp_parse_args( $args, $defaults );
     733
    708734        if ( empty( $content ) )
    709735                return '';
    710736
    711737        if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $content, $matches ) ) {
    712738                $quote = $content;
    713                 if ( $remove || ! empty( $replace ) )
    714                         $content = $replace;
     739                if ( $args['remove'] || ! empty( $args['replace'] ) )
     740                        $content = $args['replace'];
    715741                return $quote;
    716742        }
    717743
    718         if ( $remove || ! empty( $replace ) )
    719                 $content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $replace, '\\$' ), $content, 1 );
     744        if ( $args['remove'] || ! empty( $args['replace'] ) )
     745                $content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $args['replace'], '\\$' ), $content, 1 );
    720746
    721747        return $matches[1];
    722748}
     
    740766                return '';
    741767
    742768        $content = $post->post_content;
    743         $quote = get_content_quote( $content, true );
     769        $quote = get_content_quote( $content, array(
     770                'remove' => true,
     771        ) );
     772
    744773        $post->split_content = $content;
    745774
    746775        if ( ! empty( $quote ) )
     
    773802 * Extract a URL from passed content, if possible
    774803 * Checks for a URL on the first line of the content or the first encountered href attribute.
    775804 *
     805 * $args contents:
     806 * - remove - Whether to remove the found URL from the passed content.
     807 *
    776808 * @since 3.6.0
    777809 *
    778810 * @param string $content A string which might contain a URL, passed by reference.
    779  * @param boolean $remove Whether to remove the found URL from the passed content.
     811 * @param array $args An optional array of arguments.
    780812 * @return string The found URL.
    781813 */
    782 function get_content_url( &$content, $remove = false ) {
     814function get_content_url( &$content, $args = array() ) {
     815        $defaults = array(
     816                'remove' => false,
     817        );
     818
     819        $args = wp_parse_args( $args, $defaults );
     820
    783821        if ( empty( $content ) )
    784822                return '';
    785823
    786824        // the content is a URL
    787825        $trimmed = trim( $content );
    788826        if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) {
    789                 if ( $remove )
     827                if ( $args['content'] )
    790828                        $content = '';
    791829
    792830                return $trimmed;
     
    800838
    801839        // the content is a URL followed by content
    802840        if ( 0 === stripos( $line, 'http' ) ) {
    803                 if ( $remove )
     841                if ( $args['remove'] )
    804842                        $content = trim( join( "\n", $lines ) );
    805843
    806844                return esc_url_raw( $line );
  • wp-includes/media.php

     
    18971897/**
    18981898 * Extract and parse {media type} shortcodes or srcs from the passed content
    18991899 *
     1900 * $args contents:
     1901 * - type - Type of media: audio or video.
     1902 * - return -  Whether to return HTML or URLs.
     1903 * - remove - Whether to remove the found URL from the passed content.
     1904 * - limit - The number of medias to return.
     1905 *
    19001906 * @since 3.6.0
    19011907 *
    1902  * @param string $type Type of media: audio or video
    19031908 * @param string $content A string which might contain media data.
    1904  * @param boolean $html Whether to return HTML or URLs
    1905  * @param boolean $remove Whether to remove the found URL from the passed content.
    1906  * @param int $limit Optional. The number of medias to return
     1909 * @param array $args An array of arguments.
    19071910 * @return array A list of parsed shortcodes or extracted srcs
    19081911 */
    1909 function get_content_media( $type, &$content, $html = true, $remove = false, $limit = 0 ) {
     1912function get_content_media( &$content, $args ) {
     1913        $defaults = array(
     1914                'type'   => null,
     1915                'html'   => true,
     1916                'remove' => false,
     1917                'limit'  => 0,
     1918        );
     1919
     1920        $args = wp_parse_args( $args, $defaults );
     1921
     1922        if ( empty( $args['type'] ) )
     1923                return;
     1924
    19101925        $items = array();
    19111926
    19121927        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
    19131928                foreach ( $matches as $shortcode ) {
    1914                         if ( $type === $shortcode[2] ) {
     1929                        if ( $args['type'] === $shortcode[2] ) {
    19151930                                $count = 1;
    1916                                 if ( $remove )
    1917                                         $content =& str_replace( $shortcode[0], '', $content, $count );
     1931                                if ( $args['remove'] )
     1932                                        $content = str_replace( $shortcode[0], '', $content, $count );
    19181933
    19191934                                $items[] = do_shortcode_tag( $shortcode );
    1920                                 if ( $limit > 0 && count( $items ) >= $limit )
     1935                                if ( $args['limit'] > 0 && count( $items ) >= $args['limit'] )
    19211936                                        break;
    19221937                        }
    19231938                }
    19241939        }
    19251940
    1926         if ( $html )
     1941        if ( $args['html'] )
    19271942                return $items;
    19281943
    19291944        $data = array();
     
    19461961 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order
    19471962 * If no HTML tag is found, check the first line of the post for a URL
    19481963 *
     1964 * $args contents:
     1965 * - type - Type of media: audio or video.
     1966 * - remove - Whether to remove the found URL from the passed content.
     1967 * - limit - The number of medias to return.
     1968 *
    19491969 * @since 3.6.0
    19501970 *
    1951  * @param string $type Type of media: audio or video
    19521971 * @param string $content A string which might contain media data.
    1953  * @param boolean $remove Whether to remove the found URL from the passed content.
    1954  * @param int $limit Optional. The number of galleries to return
     1972 * @param array $args An array of arguments.
    19551973 * @return array A list of found HTML media embeds and possibly a URL by itself
    19561974 */
    1957 function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) {
     1975function get_embedded_media( &$content, $args ) {
     1976        $defaults = array(
     1977                'type'   => null,
     1978                'remove' => false,
     1979                'limit'  => 0,
     1980        );
     1981
     1982        $args = wp_parse_args( $args, $defaults );
     1983
     1984        if ( empty( $args['type'] ) )
     1985                return;
     1986
    19581987        $html = array();
    19591988
    1960         foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) {
     1989        foreach ( array( $args['type'], 'object', 'embed', 'iframe' ) as $tag ) {
    19611990                if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
    19621991                        $html[] = $matches[0];
    1963                         if ( $remove )
     1992                        if ( $args['remove'] )
    19641993                                $content = str_replace( $matches[0], '', $content );
    19651994
    1966                         if ( $limit > 0 && count( $html ) >= $limit )
     1995                        if ( $args['limit'] > 0 && count( $html ) >= $args['limit'] )
    19671996                                break;
    19681997                }
    19691998        }
    19701999
    1971         if ( ! empty( $html ) && count( $html ) >= $limit )
     2000        if ( ! empty( $html ) && count( $html ) >= $args['limit'] )
    19722001                return $html;
    19732002
    19742003        $lines = explode( "\n", trim( $content ) );
    19752004        $line = trim( array_shift( $lines  ) );
    19762005        if ( 0 === stripos( $line, 'http' ) ) {
    1977                 if ( $remove )
     2006                if ( $args['remove'] )
    19782007                        $content = join( "\n", $lines );
    19792008
    19802009                $html[] = $line;
     
    19872016 *
    19882017 * @since 3.6.0
    19892018 *
     2019 * @uses get_content_media()
     2020 *
    19902021 * @param string $content A string which might contain audio data.
    1991  * @param boolean $html Whether to return HTML or URLs
    1992  * @param boolean $remove Whether to remove the found URL from the passed content.
     2022 * @param array $args (optional) An array of arguments.
    19932023 * @return array A list of lists. Each item has a list of HTML or srcs corresponding
    19942024 *              to an [audio]'s HTML or primary src and specified fallbacks
    19952025 */
    1996 function get_content_audio( &$content, $html = true, $remove = false ) {
    1997         return get_content_media( 'audio', $content, $html, $remove );
     2026function get_content_audio( &$content, $args = array() ) {
     2027        return get_content_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) );
    19982028}
    19992029
    20002030/**
     
    20032033 *
    20042034 * @since 3.6.0
    20052035 *
     2036 * @uses get_embedded_media()
     2037 *
    20062038 * @param string $content A string which might contain audio data.
    2007  * @param boolean $remove Whether to remove the found URL from the passed content.
     2039 * @param array $args (optional) An array of arguments.
    20082040 * @return array A list of found HTML audio embeds and possibly a URL by itself
    20092041 */
    2010 function get_embedded_audio( &$content, $remove = false ) {
    2011         return get_embedded_media( 'audio', $content, $remove );
     2042function get_embedded_audio( &$content, $args = array() ) {
     2043        return get_embedded_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) );
    20122044}
    20132045
    20142046/**
     
    20162048 *
    20172049 * @since 3.6.0
    20182050 *
     2051 * @uses get_content_media()
     2052 *
    20192053 * @param string $content A string which might contain video data.
    2020  * @param boolean $html Whether to return HTML or URLs
    2021  * @param boolean $remove Whether to remove the found URL from the passed content.
     2054 * @param array $args (optional) An array of arguments.
    20222055 * @return array A list of lists. Each item has a list of HTML or srcs corresponding
    20232056 *              to a [video]'s HTML or primary src and specified fallbacks
    20242057 */
    2025 function get_content_video( &$content, $html = true, $remove = false ) {
    2026         return get_content_media( 'video', $content, $html, $remove );
     2058function get_content_video( &$content, $args = array() ) {
     2059        return get_content_media( $content, array_merge( $args, array( 'type' => 'video' ) ) );
    20272060}
    20282061
    20292062/**
     
    20322065 *
    20332066 * @since 3.6.0
    20342067 *
     2068 * @uses get_embedded_media()
     2069 *
    20352070 * @param string $content A string which might contain video data.
    2036  * @param boolean $remove Whether to remove the found URL from the passed content.
     2071 * @param array $args (optional) An array of arguments.
    20372072 * @return array A list of found HTML video embeds and possibly a URL by itself
    20382073 */
    2039 function get_embedded_video( &$content, $remove = false ) {
    2040         return get_embedded_media( 'video', $content, $remove );
     2074function get_embedded_video( &$content, $args = array() ) {
     2075        return get_embedded_media( $content, array_merge( $args, array( 'type' => 'video' ) ) );
    20412076}
    20422077
    20432078/**
     
    20462081 *
    20472082 * @since 3.6.0
    20482083 *
     2084 * @uses get_content_media()
     2085 * @uses get_embedded_media()
     2086 *
    20492087 * @param string $type Required. 'audio' or 'video'
    20502088 * @param WP_Post $post Optional. Used instead of global $post when passed.
    20512089 * @param int $limit Optional. The number of medias to remove if content is scanned.
     
    21022140        // these functions expect a reference, so we should make a copy of post content to avoid changing it
    21032141        $content = $post->post_content;
    21042142
    2105         $htmls = get_content_media( $type, $content, true, true, $limit );
     2143        $htmls = get_content_media( $content, array(
     2144                'type'   => $type,
     2145                'html'   => true,
     2146                'remove' => true,
     2147                'limit'  => $limit,
     2148        ) );
     2149
    21062150        if ( ! empty( $htmls ) ) {
    21072151                $html = reset( $htmls );
    21082152                $post->split_content = $content;
     
    21102154                return $post->format_content[ $cache_key ];
    21112155        }
    21122156
    2113         $embeds = get_embedded_media( $type, $content, true, 1 );
     2157        $embeds = get_embedded_media( $content, array(
     2158                'type'   => $type,
     2159                'remove' => true,
     2160                'limit'  => 1,
     2161        ) );
     2162
    21142163        if ( ! empty( $embeds ) ) {
    21152164                $embed = reset( $embeds );
    21162165                $post->split_content = $content;
     
    21942243/**
    21952244 * Check the content blob for images or image srcs
    21962245 *
     2246 * $args contents:
     2247 * - html - Whether to return HTML or URLs.
     2248 * - remove - Whether to remove the found URL from the passed content.
     2249 * - limit - The number of medias to return.
     2250 *
    21972251 * @since 3.6.0
    21982252 *
    21992253 * @param string $content A string which might contain image data.
    2200  * @param boolean $html Whether to return HTML or URLs
    2201  * @param boolean $remove Whether to remove the found data from the passed content.
    2202  * @param int $limit Optional. The number of image srcs to return
     2254 * @param array $args (optional) An array of arguments.
    22032255 * @return array The found images or srcs
    22042256 */
    2205 function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) {
     2257function get_content_images( &$content, $args = array() ) {
     2258        $defaults = array(
     2259                'html'   => true,
     2260                'remove' => false,
     2261                'limit'  => 0,
     2262        );
     2263
     2264        $args = wp_parse_args( $args, $defaults );
     2265
    22062266        $tags = array();
    22072267        $captions = array();
    22082268
     
    22102270                foreach ( $matches as $shortcode ) {
    22112271                        if ( 'caption' === $shortcode[2] ) {
    22122272                                $captions[] = $shortcode[0];
    2213                                 if ( $html )
     2273                                if ( $args['html'] )
    22142274                                        $tags[] = do_shortcode( $shortcode[0] );
    22152275                        }
    22162276
    2217                         if ( $limit > 0 && count( $tags ) >= $limit )
     2277                        if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] )
    22182278                                break;
    22192279                }
    22202280        }
     
    22312291                                foreach ( $captions as $caption ) {
    22322292                                        if ( strstr( $caption, $node[0] ) ) {
    22332293                                                $found = true;
    2234                                                 if ( $remove )
     2294                                                if ( $args['remove'] )
    22352295                                                        $content = str_replace( $caption, '', $content, $count );
    22362296                                        }
    22372297                                }
    22382298
    2239                                 if ( $remove )
     2299                                if ( $args['remove'] )
    22402300                                        $content = str_replace( $node[0], '', $content, $count );
    22412301
    22422302                                if ( ! $found )
    22432303                                        $tags[] = $node[0];
    22442304
    2245                                 if ( $limit > 0 && count( $tags ) >= $limit )
     2305                                if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] )
    22462306                                        break 2;
    22472307                        }
    22482308                }
    22492309        }
    22502310
    2251         if ( $html )
     2311        if ( $args['html'] )
    22522312                return $tags;
    22532313
    22542314        $srcs = array();
     
    22572317                preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src );
    22582318                if ( ! empty( $src[1] ) ) {
    22592319                        $srcs[] = $src[1];
    2260                         if ( $limit > 0 && count( $srcs ) >= $limit )
     2320                        if ( $args['limit'] > 0 && count( $srcs ) >= $args['limit'] )
    22612321                                break;
    22622322                }
    22632323        }
     
    22682328/**
    22692329 * Check the content blob for images or srcs and return the first
    22702330 *
     2331 * $args contents:
     2332 * - html - Whether to return HTML or URLs.
     2333 * - remove - Whether to remove the found URL from the passed content.
     2334 *
    22712335 * @since 3.6.0
    22722336 *
     2337 * @uses get_content_images()
     2338 *
    22732339 * @param string $content A string which might contain image data.
    2274  * @param boolean $html Whether to return HTML or URLs
    2275  * @param boolean $remove Whether to remove the found data from the passed content.
     2340 * @param array $args (optional) An array of arguments.
    22762341 * @return string The found data
    22772342 */
    2278 function get_content_image( &$content, $html = true, $remove = false ) {
    2279         $srcs = get_content_images( $content, $html, $remove, 1 );
     2343function get_content_image( &$content, $args = array() ) {
     2344        $srcs = get_content_images( array_merge( $args, array( 'limit' => 1 ) ) );
    22802345        if ( empty( $srcs ) )
    22812346                return '';
    22822347
     
    22862351/**
    22872352 * Check the content blob for galleries and return their image srcs
    22882353 *
     2354 * $args contents:
     2355 * - html - Whether to return HTML or URLs.
     2356 * - remove - Whether to remove the found URL from the passed content.
     2357 * - limit - The number of galleries to return.
     2358 *
    22892359 * @since 3.6.0
    22902360 *
    2291  * @param string $content A string which might contain image data.
    2292  * @param boolean $html Whether to return HTML or data
    2293  * @param boolean $remove Optional. Whether to remove the found data from the passed content.
    2294  * @param int $limit Optional. The number of galleries to return
     2361 * @param array $args (optional) An array of arguments.
    22952362 * @return array A list of galleries, which in turn are a list of their srcs in order
    22962363 */
    2297 function get_content_galleries( &$content, $html = true, $remove = false, $limit = 0 ) {
     2364function get_content_galleries( &$content, $args = array() ) {
     2365        $defaults = array(
     2366                'html'   => true,
     2367                'remove' => false,
     2368                'limit'  => 0,
     2369        );
     2370
     2371        $args = wp_parse_args( $args, $defaults );
     2372
    22982373        $galleries = array();
    22992374
    23002375        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     
    23022377                        if ( 'gallery' === $shortcode[2] ) {
    23032378                                $srcs = array();
    23042379                                $count = 1;
    2305                                 if ( $remove )
     2380                                if ( $args['remove'] )
    23062381                                        $content = str_replace( $shortcode[0], '', $content, $count );
    23072382
    23082383                                $data = shortcode_parse_atts( $shortcode[3] );
    23092384                                $gallery = do_shortcode_tag( $shortcode );
    2310                                 if ( $html ) {
     2385                                if ( $args['html'] ) {
    23112386                                        $galleries[] = $gallery;
    23122387                                } else {
    23132388                                        preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER );
     
    23202395                                        $galleries[] = $data;
    23212396                                }
    23222397
    2323                                 if ( $limit > 0 && count( $galleries ) >= $limit )
     2398                                if ( $args['limit'] > 0 && count( $galleries ) >= $args['limit'] )
    23242399                                        break;
    23252400                        }
    23262401                }
     
    23322407/**
    23332408 * Retrieve galleries from the passed post's content
    23342409 *
     2410 * $args contents:
     2411 * - post_id - The post id.
     2412 * - html - Whether to return HTML or data.
     2413 *
    23352414 * @since 3.6.0
    23362415 *
    2337  * @param int $post_id Optional. Post ID.
    2338  * @param boolean $html Whether to return HTML or data
     2416 * @uses get_content_galleries()
     2417 *
     2418 * @param array $args (optional) An array of arguments.
    23392419 * @return array A list of arrays, each containing gallery data and srcs parsed
    23402420 *              from the expanded shortcode
    23412421 */
    2342 function get_post_galleries( $post_id = 0, $html = true ) {
    2343         $post = empty( $post_id ) ? clone get_post() : get_post( $post_id );
     2422function get_post_galleries( $args = array() ) {
     2423        $defaults = array(
     2424                'post_id' => 0,
     2425                'html'    => true,
     2426        );
     2427
     2428        $args = wp_parse_args( $args, $defaults );
     2429
     2430        $post = 0 == $args['post_id'] ? clone get_post() : get_post( $args['post_id'] );
    23442431        if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' )  )
    23452432                return array();
    23462433
    2347         return get_content_galleries( $post->post_content, $html );
     2434        $galleries = get_content_galleries( $post->post_content, array(
     2435                'html' => $args['html'],
     2436        ) );
     2437
     2438        return $galleries;
    23482439}
    23492440
    23502441/**
     
    23522443 *
    23532444 * @since 3.6.0
    23542445 *
    2355  * @param int $post_id Optional. Post ID.
     2446 * @uses get_content_galleries()
     2447 *
     2448 * @param int $post_id (optional) The post id.
    23562449 * @return array A list of lists, each containing image srcs parsed
    23572450 *              from an expanded shortcode
    23582451 */
     
    23612454        if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' )  )
    23622455                return array();
    23632456
    2364         $data = get_content_galleries( $post->post_content, false );
     2457        $data = get_content_galleries( $post->post_content, array(
     2458                'html' => false,
     2459        ) );
     2460
    23652461        return wp_list_pluck( $data, 'src' );
    23662462}
    23672463
    23682464/**
    23692465 * Check a specified post's content for gallery and, if present, return the first
    23702466 *
     2467 * $args contents:
     2468 * - post_id - The post id.
     2469 * - html - Whether to return HTML or URLs.
     2470 *
    23712471 * @since 3.6.0
    23722472 *
    2373  * @param int $post_id Optional. Post ID.
    2374  * @param boolean $html Whether to return HTML or data
     2473 * @uses get_content_galleries()
     2474 *
     2475 * @param array $args (optional) An array of arguments.
    23752476 * @return array Gallery data and srcs parsed from the expanded shortcode
    23762477 */
    2377 function get_post_gallery( $post_id = 0, $html = true ) {
    2378         $post = empty( $post_id ) ? clone get_post() : get_post( $post_id );
     2478function get_post_gallery( $args = array() ) {
     2479        $defaults = array(
     2480                'post_id' => 0,
     2481                'html'    => true,
     2482        );
     2483
     2484        $args = wp_parse_args( $args, $defaults );
     2485
     2486        $post = 0 == $args['post_id'] ? clone get_post() : get_post( $args['post_id'] );
    23792487        if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) )
    23802488                return array();
    23812489
    2382         $data = get_content_galleries( $post->post_content, $html, false, 1 );
     2490        $data = get_content_galleries( $post->post_content, array(
     2491                'html'  => $args['html'],
     2492                'limit' => 1,
     2493        ) );
     2494
    23832495        return reset( $data );
    23842496}
    23852497
     
    24012513 * @return array A list of a gallery's image srcs in order
    24022514 */
    24032515function get_post_gallery_images( $post_id = 0 ) {
    2404         $gallery = get_post_gallery( $post_id, false );
     2516        $gallery = get_post_gallery( array(
     2517                'post_id' => $post_id,
     2518                'html'    => false,
     2519        ) );
     2520
    24052521        if ( empty( $gallery['src'] ) )
    24062522                return array();
    24072523
     
    24132529 *
    24142530 * @since 3.6.0
    24152531 *
     2532 * @uses get_content_images()
     2533 *
    24162534 * @param string $attached_size If an attached image is found, the size to display it.
    24172535 * @param WP_Post $post Optional. Used instead of global $post when passed.
    24182536 */
     
    25292647        }
    25302648
    25312649        $content = $post->post_content;
    2532         $htmls = get_content_images( $content, true, true, 1 );
     2650        $htmls = get_content_images( $content, array(
     2651                'html'   => true,
     2652                'remove' => true,
     2653                'limit'  => 1,
     2654        ) );
     2655
    25332656        if ( ! empty( $htmls ) ) {
    25342657                $html = reset( $htmls );
    25352658                $post->split_content = $content;