Changeset 24093 for trunk/wp-includes/media.php
- Timestamp:
- 04/25/2013 07:42:59 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r24091 r24093 2295 2295 * 2296 2296 * @param string $content A string which might contain image data. 2297 * @param boolean $html Whether to return HTML or data 2297 2298 * @param boolean $remove Optional. Whether to remove the found data from the passed content. 2298 2299 * @param int $limit Optional. The number of galleries to return 2299 2300 * @return array A list of galleries, which in turn are a list of their srcs in order 2300 2301 */ 2301 function get_content_galleries( &$content, $ remove = false, $limit = 0 ) {2302 function get_content_galleries( &$content, $html = true, $remove = false, $limit = 0 ) { 2302 2303 $src = ''; 2303 2304 $galleries = array(); … … 2314 2315 $data = shortcode_parse_atts( $shortcode[3] ); 2315 2316 $gallery = do_shortcode_tag( $shortcode ); 2316 preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER ); 2317 if ( ! empty( $src ) ) { 2318 foreach ( $src as $s ) 2319 $srcs[] = $s[1]; 2317 if ( $html ) { 2318 $galleries[] = $gallery; 2319 } else { 2320 preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER ); 2321 if ( ! empty( $src ) ) { 2322 foreach ( $src as $s ) 2323 $srcs[] = $s[1]; 2324 } 2325 2326 $data['src'] = array_values( array_unique( $srcs ) ); 2327 $galleries[] = $data; 2320 2328 } 2321 2329 2322 $data['src'] = array_values( array_unique( $srcs ) );2323 $galleries[] = $data;2324 2330 if ( $limit > 0 && count( $galleries ) >= $limit ) 2325 2331 break; … … 2337 2343 * 2338 2344 * @param int $post_id Optional. Post ID. 2345 * @param boolean $html Whether to return HTML or data 2339 2346 * @return array A list of arrays, each containing gallery data and srcs parsed 2340 2347 * from the expanded shortcode 2341 2348 */ 2342 function get_post_galleries( $post_id = 0 ) {2349 function get_post_galleries( $post_id = 0, $html = true ) { 2343 2350 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 2344 2351 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2345 2352 return array(); 2346 2353 2347 return get_content_galleries( $post->post_content );2354 return get_content_galleries( $post->post_content, $html ); 2348 2355 } 2349 2356 … … 2362 2369 return array(); 2363 2370 2364 $data = get_content_galleries( $post->post_content );2371 $data = get_content_galleries( $post->post_content, false ); 2365 2372 return wp_list_pluck( $data, 'src' ); 2366 2373 } … … 2372 2379 * 2373 2380 * @param int $post_id Optional. Post ID. 2381 * @param boolean $html Whether to return HTML or data 2374 2382 * @return array Gallery data and srcs parsed from the expanded shortcode 2375 2383 */ 2376 function get_post_gallery( $post_id = 0 ) {2384 function get_post_gallery( $post_id = 0, $html = true ) { 2377 2385 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 2378 2386 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2379 2387 return array(); 2380 2388 2381 $data = get_content_galleries( $post->post_content, false, 1 );2389 $data = get_content_galleries( $post->post_content, $html, false, 1 ); 2382 2390 return reset( $data ); 2391 } 2392 2393 /** 2394 * Output the first gallery in the current (@global) $post 2395 * 2396 * @since 3.6.0 2397 */ 2398 function the_post_format_gallery() { 2399 echo get_post_gallery(); 2383 2400 } 2384 2401 … … 2392 2409 */ 2393 2410 function get_post_gallery_images( $post_id = 0 ) { 2394 $gallery = get_post_gallery( $post_id );2411 $gallery = get_post_gallery( $post_id, false ); 2395 2412 if ( empty( $gallery['src'] ) ) 2396 2413 return array();
Note: See TracChangeset
for help on using the changeset viewer.