Ticket #24202: 24202.4.diff
File 24202.4.diff, 22.9 KB (added by , 11 years ago) |
---|
-
wp-includes/post-formats.php
352 352 if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) { 353 353 $url = $meta['link_url']; 354 354 } else { 355 $url = get_content_url( $content, true);355 $url = get_content_url( $content, array( 'remove' => true ) ); 356 356 } 357 357 } else { 358 358 $content_before = $content; 359 $url = get_content_url( $content, true);359 $url = get_content_url( $content, array( 'remove' => true ) ); 360 360 if ( $content_before == $content ) 361 361 $url = ''; 362 362 } … … 417 417 $quote = get_the_post_format_quote( $post ); 418 418 419 419 // Replace the existing quote in-place. 420 if ( ! empty( $quote ) ) 421 get_content_quote( $content, true, $quote ); 420 if ( ! empty( $quote ) ) { 421 get_content_quote( $content, array( 422 'remove' => true, 423 'replace' => $quote, 424 ) ); 425 } 422 426 break; 423 427 424 428 case 'video': … … 522 526 * ) 523 527 * ) 524 528 * 529 * $args contents: 530 * - remove - Whether to remove the found data from the passed content. 531 * 525 532 * @since 3.6.0 526 533 * 527 534 * @param string $content A string which might contain chat data, passed by reference. 528 * @param boolean $remove Whether to remove the found data from the passed content.535 * @param array $args (optional) arguments. 529 536 * @return array A chat log as structured data 530 537 */ 531 function get_content_chat( &$content, $ remove = false) {538 function get_content_chat( &$content, $args = array() ) { 532 539 global $_wp_chat_parsers; 533 540 541 $defaults = array( 542 'remove' => false, 543 ); 544 545 $args = wp_parse_args( $args, $defaults ); 546 534 547 $trimmed = strip_tags( trim( $content ) ); 535 548 if ( empty( $trimmed ) ) 536 549 return array(); … … 619 632 if ( ! empty( $stanza ) ) 620 633 $stanzas[] = $stanza; 621 634 622 if ( $ remove) {635 if ( $args['remove'] ) { 623 636 if ( 0 === $found_index ) { 624 637 $removed = array_slice( $lines, $last_index ); 625 638 } else { … … 638 651 * 639 652 * @since 3.6.0 640 653 * 654 * @uses get_content_chat() 655 * 641 656 * @param int $post_id (optional) The post ID. 642 657 * @return array The chat content. 643 658 */ … … 695 710 * If $content does not have a blockquote, assume the whole string 696 711 * is the quote. 697 712 * 713 * $args contents: 714 * - remove - Whether to remove the quote from the content. 715 * - replace - Content to replace the quote content with. 716 * 698 717 * @since 3.6.0 699 718 * 700 719 * @param string $content A string which might contain chat data, passed by reference. 701 * @param bool $remove (optional) Whether to remove the quote from the content. 702 * @param string $replace (optional) Content to replace the quote content with. 720 * @param array $args An optional array of arguments. 703 721 * @return string The quote content. 704 722 */ 705 function get_content_quote( &$content, $remove = false, $replace = '' ) { 723 function get_content_quote( &$content, $args = array() ) { 724 $defaults = array( 725 'remove' => false, 726 'replace' => '', 727 ); 728 729 $args = wp_parse_args( $args, $defaults ); 730 706 731 if ( empty( $content ) ) 707 732 return ''; 708 733 709 734 if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $content, $matches ) ) { 710 735 $quote = $content; 711 if ( $ remove || ! empty( $replace) )712 $content = $ replace;736 if ( $args['remove'] || ! empty( $args['replace'] ) ) 737 $content = $args['replace']; 713 738 return $quote; 714 739 } 715 740 716 if ( $ remove || ! empty( $replace) )717 $content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $ replace, '\\$' ), $content, 1 );741 if ( $args['remove'] || ! empty( $args['replace'] ) ) 742 $content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $args['replace'], '\\$' ), $content, 1 ); 718 743 719 744 return $matches[1]; 720 745 } … … 738 763 return ''; 739 764 740 765 $content = $post->post_content; 741 $quote = get_content_quote( $content, true ); 766 $quote = get_content_quote( $content, array( 767 'remove' => true, 768 ) ); 769 742 770 $post->split_content = $content; 743 771 744 772 if ( ! empty( $quote ) ) … … 771 799 * Extract a URL from passed content, if possible 772 800 * Checks for a URL on the first line of the content or the first encountered href attribute. 773 801 * 802 * $args contents: 803 * - remove - Whether to remove the found URL from the passed content. 804 * 774 805 * @since 3.6.0 775 806 * 776 807 * @param string $content A string which might contain a URL, passed by reference. 777 * @param boolean $remove Whether to remove the found URL from the passed content.808 * @param array $args An optional array of arguments. 778 809 * @return string The found URL. 779 810 */ 780 function get_content_url( &$content, $remove = false ) { 811 function get_content_url( &$content, $args = array() ) { 812 $defaults = array( 813 'remove' => false, 814 ); 815 816 $args = wp_parse_args( $args, $defaults ); 817 781 818 if ( empty( $content ) ) 782 819 return ''; 783 820 784 821 // the content is a URL 785 822 $trimmed = trim( $content ); 786 823 if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) { 787 if ( $ remove)824 if ( $args['content'] ) 788 825 $content = ''; 789 826 790 827 return $trimmed; … … 798 835 799 836 // the content is a URL followed by content 800 837 if ( 0 === stripos( $line, 'http' ) ) { 801 if ( $ remove)838 if ( $args['remove'] ) 802 839 $content = trim( join( "\n", $lines ) ); 803 840 804 841 return esc_url_raw( $line ); -
wp-includes/media.php
1896 1896 /** 1897 1897 * Extract and parse {media type} shortcodes or srcs from the passed content 1898 1898 * 1899 * $args contents: 1900 * - type - Type of media: audio or video. 1901 * - return - Whether to return HTML or URLs. 1902 * - remove - Whether to remove the found URL from the passed content. 1903 * - limit - The number of medias to return. 1904 * 1899 1905 * @since 3.6.0 1900 1906 * 1901 * @param string $type Type of media: audio or video1902 1907 * @param string $content A string which might contain media data. 1903 * @param boolean $html Whether to return HTML or URLs 1904 * @param boolean $remove Whether to remove the found URL from the passed content. 1905 * @param int $limit Optional. The number of medias to return 1908 * @param array $args An array of arguments. 1906 1909 * @return array A list of parsed shortcodes or extracted srcs 1907 1910 */ 1908 function get_content_media( $type, &$content, $html = true, $remove = false, $limit = 0 ) { 1911 function get_content_media( &$content, $args ) { 1912 $defaults = array( 1913 'type' => null, 1914 'html' => true, 1915 'remove' => false, 1916 'limit' => 0, 1917 ); 1918 1919 $args = wp_parse_args( $args, $defaults ); 1920 1921 if ( empty( $args['type'] ) ) 1922 return; 1923 1909 1924 $items = array(); 1910 1925 1911 1926 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 1912 1927 foreach ( $matches as $shortcode ) { 1913 if ( $ type=== $shortcode[2] ) {1928 if ( $args['type'] === $shortcode[2] ) { 1914 1929 $count = 1; 1915 if ( $ remove)1916 $content = &str_replace( $shortcode[0], '', $content, $count );1930 if ( $args['remove'] ) 1931 $content = str_replace( $shortcode[0], '', $content, $count ); 1917 1932 1918 1933 $items[] = do_shortcode_tag( $shortcode ); 1919 if ( $ limit > 0 && count( $items ) >= $limit)1934 if ( $args['limit'] > 0 && count( $items ) >= $args['limit'] ) 1920 1935 break; 1921 1936 } 1922 1937 } 1923 1938 } 1924 1939 1925 if ( $ html)1940 if ( $args['html'] ) 1926 1941 return $items; 1927 1942 1928 1943 $data = array(); … … 1945 1960 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order 1946 1961 * If no HTML tag is found, check the first line of the post for a URL 1947 1962 * 1963 * $args contents: 1964 * - type - Type of media: audio or video. 1965 * - remove - Whether to remove the found URL from the passed content. 1966 * - limit - The number of medias to return. 1967 * 1948 1968 * @since 3.6.0 1949 1969 * 1950 * @param string $type Type of media: audio or video1951 1970 * @param string $content A string which might contain media data. 1952 * @param boolean $remove Whether to remove the found URL from the passed content. 1953 * @param int $limit Optional. The number of galleries to return 1971 * @param array $args An array of arguments. 1954 1972 * @return array A list of found HTML media embeds and possibly a URL by itself 1955 1973 */ 1956 function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) { 1974 function get_embedded_media( &$content, $args ) { 1975 $defaults = array( 1976 'type' => null, 1977 'remove' => false, 1978 'limit' => 0, 1979 ); 1980 1981 $args = wp_parse_args( $args, $defaults ); 1982 1983 if ( empty( $args['type'] ) ) 1984 return; 1985 1957 1986 $html = array(); 1958 1987 1959 foreach ( array( $ type, 'object', 'embed', 'iframe' ) as $tag ) {1988 foreach ( array( $args['type'], 'object', 'embed', 'iframe' ) as $tag ) { 1960 1989 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) { 1961 1990 $html[] = $matches[0]; 1962 if ( $ remove)1991 if ( $args['remove'] ) 1963 1992 $content = str_replace( $matches[0], '', $content ); 1964 1993 1965 if ( $ limit > 0 && count( $html ) >= $limit)1994 if ( $args['limit'] > 0 && count( $html ) >= $args['limit'] ) 1966 1995 break; 1967 1996 } 1968 1997 } 1969 1998 1970 if ( ! empty( $html ) && count( $html ) >= $ limit)1999 if ( ! empty( $html ) && count( $html ) >= $args['limit'] ) 1971 2000 return $html; 1972 2001 1973 2002 $lines = explode( "\n", trim( $content ) ); 1974 2003 $line = trim( array_shift( $lines ) ); 1975 2004 if ( 0 === stripos( $line, 'http' ) ) { 1976 if ( $ remove)2005 if ( $args['remove'] ) 1977 2006 $content = join( "\n", $lines ); 1978 2007 1979 2008 $html[] = $line; … … 1986 2015 * 1987 2016 * @since 3.6.0 1988 2017 * 2018 * @uses get_content_media() 2019 * 1989 2020 * @param string $content A string which might contain audio data. 1990 * @param boolean $html Whether to return HTML or URLs 1991 * @param boolean $remove Whether to remove the found URL from the passed content. 2021 * @param array $args (optional) An array of arguments. 1992 2022 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 1993 2023 * to an [audio]'s HTML or primary src and specified fallbacks 1994 2024 */ 1995 function get_content_audio( &$content, $ html = true, $remove = false) {1996 return get_content_media( 'audio', $content, $html, $remove);2025 function get_content_audio( &$content, $args = array() ) { 2026 return get_content_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) ); 1997 2027 } 1998 2028 1999 2029 /** … … 2002 2032 * 2003 2033 * @since 3.6.0 2004 2034 * 2035 * @uses get_embedded_media() 2036 * 2005 2037 * @param string $content A string which might contain audio data. 2006 * @param boolean $remove Whether to remove the found URL from the passed content.2038 * @param array $args (optional) An array of arguments. 2007 2039 * @return array A list of found HTML audio embeds and possibly a URL by itself 2008 2040 */ 2009 function get_embedded_audio( &$content, $ remove = false) {2010 return get_embedded_media( 'audio', $content, $remove);2041 function get_embedded_audio( &$content, $args = array() ) { 2042 return get_embedded_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) ); 2011 2043 } 2012 2044 2013 2045 /** … … 2015 2047 * 2016 2048 * @since 3.6.0 2017 2049 * 2050 * @uses get_content_media() 2051 * 2018 2052 * @param string $content A string which might contain video data. 2019 * @param boolean $html Whether to return HTML or URLs 2020 * @param boolean $remove Whether to remove the found URL from the passed content. 2053 * @param array $args (optional) An array of arguments. 2021 2054 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 2022 2055 * to a [video]'s HTML or primary src and specified fallbacks 2023 2056 */ 2024 function get_content_video( &$content, $ html = true, $remove = false) {2025 return get_content_media( 'video', $content, $html, $remove);2057 function get_content_video( &$content, $args = array() ) { 2058 return get_content_media( $content, array_merge( $args, array( 'type' => 'video' ) ) ); 2026 2059 } 2027 2060 2028 2061 /** … … 2031 2064 * 2032 2065 * @since 3.6.0 2033 2066 * 2067 * @uses get_embedded_media() 2068 * 2034 2069 * @param string $content A string which might contain video data. 2035 * @param boolean $remove Whether to remove the found URL from the passed content.2070 * @param array $args (optional) An array of arguments. 2036 2071 * @return array A list of found HTML video embeds and possibly a URL by itself 2037 2072 */ 2038 function get_embedded_video( &$content, $ remove = false) {2039 return get_embedded_media( 'video', $content, $remove);2073 function get_embedded_video( &$content, $args = array() ) { 2074 return get_embedded_media( $content, array_merge( $args, array( 'type' => 'video' ) ) ); 2040 2075 } 2041 2076 2042 2077 /** … … 2045 2080 * 2046 2081 * @since 3.6.0 2047 2082 * 2083 * @uses get_content_media() 2084 * @uses get_embedded_media() 2085 * 2048 2086 * @param string $type Required. 'audio' or 'video' 2049 2087 * @param WP_Post $post Optional. Used instead of global $post when passed. 2050 2088 * @param int $limit Optional. The number of medias to remove if content is scanned. … … 2101 2139 // these functions expect a reference, so we should make a copy of post content to avoid changing it 2102 2140 $content = $post->post_content; 2103 2141 2104 $htmls = get_content_media( $type, $content, true, true, $limit ); 2142 $htmls = get_content_media( $content, array( 2143 'type' => $type, 2144 'html' => true, 2145 'remove' => true, 2146 'limit' => $limit, 2147 ) ); 2148 2105 2149 if ( ! empty( $htmls ) ) { 2106 2150 $html = reset( $htmls ); 2107 2151 $post->split_content = $content; … … 2109 2153 return $post->format_content[ $cache_key ]; 2110 2154 } 2111 2155 2112 $embeds = get_embedded_media( $type, $content, true, 1 ); 2156 $embeds = get_embedded_media( $content, array( 2157 'type' => $type, 2158 'remove' => true, 2159 'limit' => 1, 2160 ) ); 2161 2113 2162 if ( ! empty( $embeds ) ) { 2114 2163 $embed = reset( $embeds ); 2115 2164 $post->split_content = $content; … … 2193 2242 /** 2194 2243 * Check the content blob for images or image srcs 2195 2244 * 2245 * $args contents: 2246 * - html - Whether to return HTML or URLs. 2247 * - remove - Whether to remove the found URL from the passed content. 2248 * - limit - The number of medias to return. 2249 * 2196 2250 * @since 3.6.0 2197 2251 * 2198 2252 * @param string $content A string which might contain image data. 2199 * @param boolean $html Whether to return HTML or URLs 2200 * @param boolean $remove Whether to remove the found data from the passed content. 2201 * @param int $limit Optional. The number of image srcs to return 2253 * @param array $args (optional) An array of arguments. 2202 2254 * @return array The found images or srcs 2203 2255 */ 2204 function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) { 2256 function get_content_images( &$content, $args = array() ) { 2257 $defaults = array( 2258 'html' => true, 2259 'remove' => false, 2260 'limit' => 0, 2261 ); 2262 2263 $args = wp_parse_args( $args, $defaults ); 2264 2205 2265 $tags = array(); 2206 2266 $captions = array(); 2207 2267 … … 2209 2269 foreach ( $matches as $shortcode ) { 2210 2270 if ( 'caption' === $shortcode[2] ) { 2211 2271 $captions[] = $shortcode[0]; 2212 if ( $ html)2272 if ( $args['html'] ) 2213 2273 $tags[] = do_shortcode( $shortcode[0] ); 2214 2274 } 2215 2275 2216 if ( $ limit > 0 && count( $tags ) >= $limit)2276 if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] ) 2217 2277 break; 2218 2278 } 2219 2279 } … … 2230 2290 foreach ( $captions as $caption ) { 2231 2291 if ( strstr( $caption, $node[0] ) ) { 2232 2292 $found = true; 2233 if ( $ remove)2293 if ( $args['remove'] ) 2234 2294 $content = str_replace( $caption, '', $content, $count ); 2235 2295 } 2236 2296 } 2237 2297 2238 if ( $ remove)2298 if ( $args['remove'] ) 2239 2299 $content = str_replace( $node[0], '', $content, $count ); 2240 2300 2241 2301 if ( ! $found ) 2242 2302 $tags[] = $node[0]; 2243 2303 2244 if ( $ limit > 0 && count( $tags ) >= $limit)2304 if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] ) 2245 2305 break 2; 2246 2306 } 2247 2307 } 2248 2308 } 2249 2309 2250 if ( $ html)2310 if ( $args['html'] ) 2251 2311 return $tags; 2252 2312 2253 2313 $srcs = array(); … … 2256 2316 preg_match( '#src=([\'"])(.+?)\1#is', $tag, $src ); 2257 2317 if ( ! empty( $src[2] ) ) { 2258 2318 $srcs[] = $src[2]; 2259 if ( $ limit > 0 && count( $srcs ) >= $limit)2319 if ( $args['limit'] > 0 && count( $srcs ) >= $args['limit'] ) 2260 2320 break; 2261 2321 } 2262 2322 } … … 2267 2327 /** 2268 2328 * Check the content blob for images or srcs and return the first 2269 2329 * 2330 * $args contents: 2331 * - html - Whether to return HTML or URLs. 2332 * - remove - Whether to remove the found URL from the passed content. 2333 * 2270 2334 * @since 3.6.0 2271 2335 * 2336 * @uses get_content_images() 2337 * 2272 2338 * @param string $content A string which might contain image data. 2273 * @param boolean $html Whether to return HTML or URLs 2274 * @param boolean $remove Whether to remove the found data from the passed content. 2339 * @param array $args (optional) An array of arguments. 2275 2340 * @return string The found data 2276 2341 */ 2277 function get_content_image( &$content, $ html = true, $remove = false) {2278 $srcs = get_content_images( $content, $html, $remove, 1);2342 function get_content_image( &$content, $args = array() ) { 2343 $srcs = get_content_images( array_merge( $args, array( 'limit' => 1 ) ) ); 2279 2344 if ( empty( $srcs ) ) 2280 2345 return ''; 2281 2346 … … 2285 2350 /** 2286 2351 * Check the content blob for galleries and return their image srcs 2287 2352 * 2353 * $args contents: 2354 * - html - Whether to return HTML or URLs. 2355 * - remove - Whether to remove the found URL from the passed content. 2356 * - limit - The number of galleries to return. 2357 * 2288 2358 * @since 3.6.0 2289 2359 * 2290 * @param string $content A string which might contain image data. 2291 * @param boolean $html Whether to return HTML or data 2292 * @param boolean $remove Optional. Whether to remove the found data from the passed content. 2293 * @param int $limit Optional. The number of galleries to return 2360 * @param array $args (optional) An array of arguments. 2294 2361 * @return array A list of galleries, which in turn are a list of their srcs in order 2295 2362 */ 2296 function get_content_galleries( &$content, $html = true, $remove = false, $limit = 0 ) { 2363 function get_content_galleries( &$content, $args = array() ) { 2364 $defaults = array( 2365 'html' => true, 2366 'remove' => false, 2367 'limit' => 0, 2368 ); 2369 2370 $args = wp_parse_args( $args, $defaults ); 2371 2297 2372 $galleries = array(); 2298 2373 2299 2374 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { … … 2301 2376 if ( 'gallery' === $shortcode[2] ) { 2302 2377 $srcs = array(); 2303 2378 $count = 1; 2304 if ( $ remove)2379 if ( $args['remove'] ) 2305 2380 $content = str_replace( $shortcode[0], '', $content, $count ); 2306 2381 2307 2382 $data = shortcode_parse_atts( $shortcode[3] ); 2308 2383 $gallery = do_shortcode_tag( $shortcode ); 2309 if ( $ html) {2384 if ( $args['html'] ) { 2310 2385 $galleries[] = $gallery; 2311 2386 } else { 2312 2387 preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER ); … … 2319 2394 $galleries[] = $data; 2320 2395 } 2321 2396 2322 if ( $ limit > 0 && count( $galleries ) >= $limit)2397 if ( $args['limit'] > 0 && count( $galleries ) >= $args['limit'] ) 2323 2398 break; 2324 2399 } 2325 2400 } … … 2331 2406 /** 2332 2407 * Retrieve galleries from the passed post's content 2333 2408 * 2409 * $args contents: 2410 * - post_id - The post id. 2411 * - html - Whether to return HTML or data. 2412 * 2334 2413 * @since 3.6.0 2335 2414 * 2336 * @param int $post_id Optional. Post ID. 2337 * @param boolean $html Whether to return HTML or data 2415 * @uses get_content_galleries() 2416 * 2417 * @param array $args (optional) An array of arguments. 2338 2418 * @return array A list of arrays, each containing gallery data and srcs parsed 2339 2419 * from the expanded shortcode 2340 2420 */ 2341 function get_post_galleries( $post_id = 0, $html = true ) { 2342 if ( ! $post = get_post( $post_id ) ) 2421 function get_post_galleries( $args = array() ) { 2422 $defaults = array( 2423 'post_id' => 0, 2424 'html' => true, 2425 ); 2426 2427 $args = wp_parse_args( $args, $defaults ); 2428 2429 if ( ! $post = get_post( $args['post_id'] ) ) 2343 2430 return array(); 2344 2431 2345 2432 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 2346 2433 return array(); 2347 2434 2348 return get_content_galleries( $post->post_content, $html);2435 return get_content_galleries( $post->post_content, array( 'html' => $args['html'] ) ); 2349 2436 } 2350 2437 2351 2438 /** … … 2353 2440 * 2354 2441 * @since 3.6.0 2355 2442 * 2356 * @param int $post_id Optional. Post ID. 2443 * @uses get_content_galleries() 2444 * 2445 * @param int $post_id (optional) The post id. 2357 2446 * @return array A list of lists, each containing image srcs parsed 2358 2447 * from an expanded shortcode 2359 2448 */ … … 2364 2453 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 2365 2454 return array(); 2366 2455 2367 $data = get_content_galleries( $post->post_content, false);2456 $data = get_content_galleries( $post->post_content, array( 'html' => false ) ); 2368 2457 return wp_list_pluck( $data, 'src' ); 2369 2458 } 2370 2459 2371 2460 /** 2372 2461 * Check a specified post's content for gallery and, if present, return the first 2373 2462 * 2463 * $args contents: 2464 * - post_id - The post id. 2465 * - html - Whether to return HTML or URLs. 2466 * 2374 2467 * @since 3.6.0 2375 2468 * 2376 * @param int $post_id Optional. Post ID. 2377 * @param boolean $html Whether to return HTML or data 2469 * @uses get_content_galleries() 2470 * 2471 * @param array $args (optional) An array of arguments. 2378 2472 * @return array Gallery data and srcs parsed from the expanded shortcode 2379 2473 */ 2380 function get_post_gallery( $post_id = 0, $html = true ) { 2381 if ( ! $post = get_post( $post_id ) ) 2474 function get_post_gallery( $args = array() ) { 2475 $defaults = array( 2476 'post_id' => 0, 2477 'html' => true, 2478 ); 2479 2480 $args = wp_parse_args( $args, $defaults ); 2481 2482 if ( ! $post = get_post( $args['post_id'] ) ) 2382 2483 return array(); 2383 2484 2384 2485 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 2385 2486 return array(); 2386 2487 2387 $data = get_content_galleries( $post->post_content, $html, false, 1 ); 2488 $data = get_content_galleries( $post->post_content, array( 2489 'html' => $args['html'], 2490 'limit' => 1, 2491 ) ); 2492 2388 2493 return reset( $data ); 2389 2494 } 2390 2495 … … 2406 2511 * @return array A list of a gallery's image srcs in order 2407 2512 */ 2408 2513 function get_post_gallery_images( $post_id = 0 ) { 2409 $gallery = get_post_gallery( $post_id, false ); 2514 $gallery = get_post_gallery( array( 2515 'post_id' => $post_id, 2516 'html' => false, 2517 ) ); 2518 2410 2519 if ( empty( $gallery['src'] ) ) 2411 2520 return array(); 2412 2521 … … 2418 2527 * 2419 2528 * @since 3.6.0 2420 2529 * 2530 * @uses get_content_images() 2531 * 2421 2532 * @param string $attached_size If an attached image is found, the size to display it. 2422 2533 * @param WP_Post $post Optional. Used instead of global $post when passed. 2423 2534 */ … … 2554 2665 } 2555 2666 2556 2667 $content = $post->post_content; 2557 $htmls = get_content_images( $content, true, true, 1 ); 2668 $htmls = get_content_images( $content, array( 2669 'html' => true, 2670 'remove' => true, 2671 'limit' => 1, 2672 ) ); 2673 2558 2674 if ( ! empty( $htmls ) ) { 2559 2675 $html = reset( $htmls ); 2560 2676 -
wp-content/themes/twentyeleven/functions.php
641 641 $images = array(); 642 642 643 643 if ( function_exists( 'get_post_galleries' ) ) { 644 $galleries = get_post_galleries( get_the_ID(), false);644 $galleries = get_post_galleries( array( 'post_id' => get_the_ID(), 'html' => false ) ); 645 645 if ( isset( $galleries[0]['ids'] ) ) 646 646 $images = explode( ',', $galleries[0]['ids'] ); 647 647 } else { -
wp-content/themes/twentyten/functions.php
529 529 $images = array(); 530 530 531 531 if ( function_exists( 'get_post_galleries' ) ) { 532 $galleries = get_post_galleries( get_the_ID(), false);532 $galleries = get_post_galleries( array( 'post_id' => get_the_ID(), 'html' => false ) ); 533 533 if ( isset( $galleries[0]['ids'] ) ) 534 534 $images = explode( ',', $galleries[0]['ids'] ); 535 535 } else {