Ticket #24202: 24202.3.diff
| File 24202.3.diff, 22.5 KB (added by , 13 years ago) |
|---|
-
wp-includes/post-formats.php
353 353 if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) { 354 354 $url = $meta['link_url']; 355 355 } else { 356 $url = get_content_url( $content, true);356 $url = get_content_url( $content, array( 'remove' => true ) ); 357 357 } 358 358 } else { 359 359 $content_before = $content; 360 $url = get_content_url( $content, true);360 $url = get_content_url( $content, array( 'remove' => true ) ); 361 361 if ( $content_before == $content ) 362 362 $url = ''; 363 363 } … … 418 418 $quote = get_the_post_format_quote( $post ); 419 419 420 420 // 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 } 423 427 break; 424 428 425 429 case 'video': … … 523 527 * ) 524 528 * ) 525 529 * 530 * $args contents: 531 * - remove - Whether to remove the found data from the passed content. 532 * 526 533 * @since 3.6.0 527 534 * 528 535 * @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. 530 537 * @return array A chat log as structured data 531 538 */ 532 function get_content_chat( &$content, $ remove = false) {539 function get_content_chat( &$content, $args = array() ) { 533 540 global $_wp_chat_parsers; 534 541 542 $defaults = array( 543 'remove' => false, 544 ); 545 546 $args = wp_parse_args( $args, $defaults ); 547 535 548 $trimmed = strip_tags( trim( $content ) ); 536 549 if ( empty( $trimmed ) ) 537 550 return array(); … … 620 633 if ( ! empty( $stanza ) ) 621 634 $stanzas[] = $stanza; 622 635 623 if ( $ remove) {636 if ( $args['remove'] ) { 624 637 if ( 0 === $found_index ) { 625 638 $removed = array_slice( $lines, $last_index ); 626 639 } else { … … 639 652 * 640 653 * @since 3.6.0 641 654 * 642 * @param int $id (optional) The post ID. 655 * @uses get_content_chat() 656 * 657 * @param int $post_id (optional) The post ID. 643 658 * @return array The chat content. 644 659 */ 645 function get_the_post_format_chat( $ id = 0 ) {646 $post = empty( $ id ) ? clone get_post() : get_post( $id );660 function get_the_post_format_chat( $post_id = 0 ) { 661 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 647 662 if ( empty( $post ) ) 648 663 return array(); 649 664 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 ); 651 667 if ( empty( $data ) ) 652 668 return array(); 653 669 … … 697 713 * If $content does not have a blockquote, assume the whole string 698 714 * is the quote. 699 715 * 716 * $args contents: 717 * - remove - Whether to remove the quote from the content. 718 * - replace - Content to replace the quote content with. 719 * 700 720 * @since 3.6.0 701 721 * 702 722 * @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. 705 724 * @return string The quote content. 706 725 */ 707 function get_content_quote( &$content, $remove = false, $replace = '' ) { 726 function get_content_quote( &$content, $args = array() ) { 727 $defaults = array( 728 'remove' => false, 729 'replace' => '', 730 ); 731 732 $args = wp_parse_args( $args, $defaults ); 733 708 734 if ( empty( $content ) ) 709 735 return ''; 710 736 711 737 if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $content, $matches ) ) { 712 738 $quote = $content; 713 if ( $ remove || ! empty( $replace) )714 $content = $ replace;739 if ( $args['remove'] || ! empty( $args['replace'] ) ) 740 $content = $args['replace']; 715 741 return $quote; 716 742 } 717 743 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 ); 720 746 721 747 return $matches[1]; 722 748 } … … 740 766 return ''; 741 767 742 768 $content = $post->post_content; 743 $quote = get_content_quote( $content, true ); 769 $quote = get_content_quote( $content, array( 770 'remove' => true, 771 ) ); 772 744 773 $post->split_content = $content; 745 774 746 775 if ( ! empty( $quote ) ) … … 773 802 * Extract a URL from passed content, if possible 774 803 * Checks for a URL on the first line of the content or the first encountered href attribute. 775 804 * 805 * $args contents: 806 * - remove - Whether to remove the found URL from the passed content. 807 * 776 808 * @since 3.6.0 777 809 * 778 810 * @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. 780 812 * @return string The found URL. 781 813 */ 782 function get_content_url( &$content, $remove = false ) { 814 function get_content_url( &$content, $args = array() ) { 815 $defaults = array( 816 'remove' => false, 817 ); 818 819 $args = wp_parse_args( $args, $defaults ); 820 783 821 if ( empty( $content ) ) 784 822 return ''; 785 823 786 824 // the content is a URL 787 825 $trimmed = trim( $content ); 788 826 if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) { 789 if ( $ remove)827 if ( $args['content'] ) 790 828 $content = ''; 791 829 792 830 return $trimmed; … … 800 838 801 839 // the content is a URL followed by content 802 840 if ( 0 === stripos( $line, 'http' ) ) { 803 if ( $ remove)841 if ( $args['remove'] ) 804 842 $content = trim( join( "\n", $lines ) ); 805 843 806 844 return esc_url_raw( $line ); -
wp-includes/media.php
1897 1897 /** 1898 1898 * Extract and parse {media type} shortcodes or srcs from the passed content 1899 1899 * 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 * 1900 1906 * @since 3.6.0 1901 1907 * 1902 * @param string $type Type of media: audio or video1903 1908 * @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. 1907 1910 * @return array A list of parsed shortcodes or extracted srcs 1908 1911 */ 1909 function get_content_media( $type, &$content, $html = true, $remove = false, $limit = 0 ) { 1912 function 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 1910 1925 $items = array(); 1911 1926 1912 1927 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 1913 1928 foreach ( $matches as $shortcode ) { 1914 if ( $ type=== $shortcode[2] ) {1929 if ( $args['type'] === $shortcode[2] ) { 1915 1930 $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 ); 1918 1933 1919 1934 $items[] = do_shortcode_tag( $shortcode ); 1920 if ( $ limit > 0 && count( $items ) >= $limit)1935 if ( $args['limit'] > 0 && count( $items ) >= $args['limit'] ) 1921 1936 break; 1922 1937 } 1923 1938 } 1924 1939 } 1925 1940 1926 if ( $ html)1941 if ( $args['html'] ) 1927 1942 return $items; 1928 1943 1929 1944 $data = array(); … … 1946 1961 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order 1947 1962 * If no HTML tag is found, check the first line of the post for a URL 1948 1963 * 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 * 1949 1969 * @since 3.6.0 1950 1970 * 1951 * @param string $type Type of media: audio or video1952 1971 * @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. 1955 1973 * @return array A list of found HTML media embeds and possibly a URL by itself 1956 1974 */ 1957 function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) { 1975 function 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 1958 1987 $html = array(); 1959 1988 1960 foreach ( array( $ type, 'object', 'embed', 'iframe' ) as $tag ) {1989 foreach ( array( $args['type'], 'object', 'embed', 'iframe' ) as $tag ) { 1961 1990 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) { 1962 1991 $html[] = $matches[0]; 1963 if ( $ remove)1992 if ( $args['remove'] ) 1964 1993 $content = str_replace( $matches[0], '', $content ); 1965 1994 1966 if ( $ limit > 0 && count( $html ) >= $limit)1995 if ( $args['limit'] > 0 && count( $html ) >= $args['limit'] ) 1967 1996 break; 1968 1997 } 1969 1998 } 1970 1999 1971 if ( ! empty( $html ) && count( $html ) >= $ limit)2000 if ( ! empty( $html ) && count( $html ) >= $args['limit'] ) 1972 2001 return $html; 1973 2002 1974 2003 $lines = explode( "\n", trim( $content ) ); 1975 2004 $line = trim( array_shift( $lines ) ); 1976 2005 if ( 0 === stripos( $line, 'http' ) ) { 1977 if ( $ remove)2006 if ( $args['remove'] ) 1978 2007 $content = join( "\n", $lines ); 1979 2008 1980 2009 $html[] = $line; … … 1987 2016 * 1988 2017 * @since 3.6.0 1989 2018 * 2019 * @uses get_content_media() 2020 * 1990 2021 * @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. 1993 2023 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 1994 2024 * to an [audio]'s HTML or primary src and specified fallbacks 1995 2025 */ 1996 function get_content_audio( &$content, $ html = true, $remove = false) {1997 return get_content_media( 'audio', $content, $html, $remove);2026 function get_content_audio( &$content, $args = array() ) { 2027 return get_content_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) ); 1998 2028 } 1999 2029 2000 2030 /** … … 2003 2033 * 2004 2034 * @since 3.6.0 2005 2035 * 2036 * @uses get_embedded_media() 2037 * 2006 2038 * @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. 2008 2040 * @return array A list of found HTML audio embeds and possibly a URL by itself 2009 2041 */ 2010 function get_embedded_audio( &$content, $ remove = false) {2011 return get_embedded_media( 'audio', $content, $remove);2042 function get_embedded_audio( &$content, $args = array() ) { 2043 return get_embedded_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) ); 2012 2044 } 2013 2045 2014 2046 /** … … 2016 2048 * 2017 2049 * @since 3.6.0 2018 2050 * 2051 * @uses get_content_media() 2052 * 2019 2053 * @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. 2022 2055 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 2023 2056 * to a [video]'s HTML or primary src and specified fallbacks 2024 2057 */ 2025 function get_content_video( &$content, $ html = true, $remove = false) {2026 return get_content_media( 'video', $content, $html, $remove);2058 function get_content_video( &$content, $args = array() ) { 2059 return get_content_media( $content, array_merge( $args, array( 'type' => 'video' ) ) ); 2027 2060 } 2028 2061 2029 2062 /** … … 2032 2065 * 2033 2066 * @since 3.6.0 2034 2067 * 2068 * @uses get_embedded_media() 2069 * 2035 2070 * @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. 2037 2072 * @return array A list of found HTML video embeds and possibly a URL by itself 2038 2073 */ 2039 function get_embedded_video( &$content, $ remove = false) {2040 return get_embedded_media( 'video', $content, $remove);2074 function get_embedded_video( &$content, $args = array() ) { 2075 return get_embedded_media( $content, array_merge( $args, array( 'type' => 'video' ) ) ); 2041 2076 } 2042 2077 2043 2078 /** … … 2046 2081 * 2047 2082 * @since 3.6.0 2048 2083 * 2084 * @uses get_content_media() 2085 * @uses get_embedded_media() 2086 * 2049 2087 * @param string $type Required. 'audio' or 'video' 2050 2088 * @param WP_Post $post Optional. Used instead of global $post when passed. 2051 2089 * @param int $limit Optional. The number of medias to remove if content is scanned. … … 2102 2140 // these functions expect a reference, so we should make a copy of post content to avoid changing it 2103 2141 $content = $post->post_content; 2104 2142 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 2106 2150 if ( ! empty( $htmls ) ) { 2107 2151 $html = reset( $htmls ); 2108 2152 $post->split_content = $content; … … 2110 2154 return $post->format_content[ $cache_key ]; 2111 2155 } 2112 2156 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 2114 2163 if ( ! empty( $embeds ) ) { 2115 2164 $embed = reset( $embeds ); 2116 2165 $post->split_content = $content; … … 2194 2243 /** 2195 2244 * Check the content blob for images or image srcs 2196 2245 * 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 * 2197 2251 * @since 3.6.0 2198 2252 * 2199 2253 * @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. 2203 2255 * @return array The found images or srcs 2204 2256 */ 2205 function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) { 2257 function 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 2206 2266 $tags = array(); 2207 2267 $captions = array(); 2208 2268 … … 2210 2270 foreach ( $matches as $shortcode ) { 2211 2271 if ( 'caption' === $shortcode[2] ) { 2212 2272 $captions[] = $shortcode[0]; 2213 if ( $ html)2273 if ( $args['html'] ) 2214 2274 $tags[] = do_shortcode( $shortcode[0] ); 2215 2275 } 2216 2276 2217 if ( $ limit > 0 && count( $tags ) >= $limit)2277 if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] ) 2218 2278 break; 2219 2279 } 2220 2280 } … … 2231 2291 foreach ( $captions as $caption ) { 2232 2292 if ( strstr( $caption, $node[0] ) ) { 2233 2293 $found = true; 2234 if ( $ remove)2294 if ( $args['remove'] ) 2235 2295 $content = str_replace( $caption, '', $content, $count ); 2236 2296 } 2237 2297 } 2238 2298 2239 if ( $ remove)2299 if ( $args['remove'] ) 2240 2300 $content = str_replace( $node[0], '', $content, $count ); 2241 2301 2242 2302 if ( ! $found ) 2243 2303 $tags[] = $node[0]; 2244 2304 2245 if ( $ limit > 0 && count( $tags ) >= $limit)2305 if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] ) 2246 2306 break 2; 2247 2307 } 2248 2308 } 2249 2309 } 2250 2310 2251 if ( $ html)2311 if ( $args['html'] ) 2252 2312 return $tags; 2253 2313 2254 2314 $srcs = array(); … … 2257 2317 preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src ); 2258 2318 if ( ! empty( $src[1] ) ) { 2259 2319 $srcs[] = $src[1]; 2260 if ( $ limit > 0 && count( $srcs ) >= $limit)2320 if ( $args['limit'] > 0 && count( $srcs ) >= $args['limit'] ) 2261 2321 break; 2262 2322 } 2263 2323 } … … 2268 2328 /** 2269 2329 * Check the content blob for images or srcs and return the first 2270 2330 * 2331 * $args contents: 2332 * - html - Whether to return HTML or URLs. 2333 * - remove - Whether to remove the found URL from the passed content. 2334 * 2271 2335 * @since 3.6.0 2272 2336 * 2337 * @uses get_content_images() 2338 * 2273 2339 * @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. 2276 2341 * @return string The found data 2277 2342 */ 2278 function get_content_image( &$content, $ html = true, $remove = false) {2279 $srcs = get_content_images( $content, $html, $remove, 1);2343 function get_content_image( &$content, $args = array() ) { 2344 $srcs = get_content_images( array_merge( $args, array( 'limit' => 1 ) ) ); 2280 2345 if ( empty( $srcs ) ) 2281 2346 return ''; 2282 2347 … … 2286 2351 /** 2287 2352 * Check the content blob for galleries and return their image srcs 2288 2353 * 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 * 2289 2359 * @since 3.6.0 2290 2360 * 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. 2295 2362 * @return array A list of galleries, which in turn are a list of their srcs in order 2296 2363 */ 2297 function get_content_galleries( &$content, $html = true, $remove = false, $limit = 0 ) { 2364 function 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 2298 2373 $galleries = array(); 2299 2374 2300 2375 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { … … 2302 2377 if ( 'gallery' === $shortcode[2] ) { 2303 2378 $srcs = array(); 2304 2379 $count = 1; 2305 if ( $ remove)2380 if ( $args['remove'] ) 2306 2381 $content = str_replace( $shortcode[0], '', $content, $count ); 2307 2382 2308 2383 $data = shortcode_parse_atts( $shortcode[3] ); 2309 2384 $gallery = do_shortcode_tag( $shortcode ); 2310 if ( $ html) {2385 if ( $args['html'] ) { 2311 2386 $galleries[] = $gallery; 2312 2387 } else { 2313 2388 preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER ); … … 2320 2395 $galleries[] = $data; 2321 2396 } 2322 2397 2323 if ( $ limit > 0 && count( $galleries ) >= $limit)2398 if ( $args['limit'] > 0 && count( $galleries ) >= $args['limit'] ) 2324 2399 break; 2325 2400 } 2326 2401 } … … 2332 2407 /** 2333 2408 * Retrieve galleries from the passed post's content 2334 2409 * 2410 * $args contents: 2411 * - post_id - The post id. 2412 * - html - Whether to return HTML or data. 2413 * 2335 2414 * @since 3.6.0 2336 2415 * 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. 2339 2419 * @return array A list of arrays, each containing gallery data and srcs parsed 2340 2420 * from the expanded shortcode 2341 2421 */ 2342 function get_post_galleries( $post_id = 0, $html = true ) { 2343 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 2422 function 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'] ); 2344 2431 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2345 2432 return array(); 2346 2433 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; 2348 2439 } 2349 2440 2350 2441 /** … … 2352 2443 * 2353 2444 * @since 3.6.0 2354 2445 * 2355 * @param int $post_id Optional. Post ID. 2446 * @uses get_content_galleries() 2447 * 2448 * @param int $post_id (optional) The post id. 2356 2449 * @return array A list of lists, each containing image srcs parsed 2357 2450 * from an expanded shortcode 2358 2451 */ … … 2361 2454 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2362 2455 return array(); 2363 2456 2364 $data = get_content_galleries( $post->post_content, false ); 2457 $data = get_content_galleries( $post->post_content, array( 2458 'html' => false, 2459 ) ); 2460 2365 2461 return wp_list_pluck( $data, 'src' ); 2366 2462 } 2367 2463 2368 2464 /** 2369 2465 * Check a specified post's content for gallery and, if present, return the first 2370 2466 * 2467 * $args contents: 2468 * - post_id - The post id. 2469 * - html - Whether to return HTML or URLs. 2470 * 2371 2471 * @since 3.6.0 2372 2472 * 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. 2375 2476 * @return array Gallery data and srcs parsed from the expanded shortcode 2376 2477 */ 2377 function get_post_gallery( $post_id = 0, $html = true ) { 2378 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 2478 function 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'] ); 2379 2487 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2380 2488 return array(); 2381 2489 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 2383 2495 return reset( $data ); 2384 2496 } 2385 2497 … … 2401 2513 * @return array A list of a gallery's image srcs in order 2402 2514 */ 2403 2515 function 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 2405 2521 if ( empty( $gallery['src'] ) ) 2406 2522 return array(); 2407 2523 … … 2413 2529 * 2414 2530 * @since 3.6.0 2415 2531 * 2532 * @uses get_content_images() 2533 * 2416 2534 * @param string $attached_size If an attached image is found, the size to display it. 2417 2535 * @param WP_Post $post Optional. Used instead of global $post when passed. 2418 2536 */ … … 2529 2647 } 2530 2648 2531 2649 $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 2533 2656 if ( ! empty( $htmls ) ) { 2534 2657 $html = reset( $htmls ); 2535 2658 $post->split_content = $content;