Changeset 45538 for trunk/src/wp-includes/media.php
- Timestamp:
- 06/15/2019 01:01:48 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r45270 r45538 18 18 function wp_get_additional_image_sizes() { 19 19 global $_wp_additional_image_sizes; 20 20 21 if ( ! $_wp_additional_image_sizes ) { 21 22 $_wp_additional_image_sizes = array(); 22 23 } 24 23 25 return $_wp_additional_image_sizes; 24 26 } … … 67 69 $max_width = $size[0]; 68 70 $max_height = $size[1]; 69 } elseif ( $size == 'thumb' || $size== 'thumbnail' ) {71 } elseif ( $size === 'thumb' || $size === 'thumbnail' ) { 70 72 $max_width = intval( get_option( 'thumbnail_size_w' ) ); 71 73 $max_height = intval( get_option( 'thumbnail_size_h' ) ); … … 75 77 $max_height = 96; 76 78 } 77 } elseif ( $size == 'medium' ) {79 } elseif ( $size === 'medium' ) { 78 80 $max_width = intval( get_option( 'medium_size_w' ) ); 79 81 $max_height = intval( get_option( 'medium_size_h' ) ); 80 82 81 } elseif ( $size == 'medium_large' ) {83 } elseif ( $size === 'medium_large' ) { 82 84 $max_width = intval( get_option( 'medium_large_size_w' ) ); 83 85 $max_height = intval( get_option( 'medium_large_size_h' ) ); … … 86 88 $max_width = min( intval( $content_width ), $max_width ); 87 89 } 88 } elseif ( $size == 'large' ) {90 } elseif ( $size === 'large' ) { 89 91 /* 90 92 * We're inserting a large size image into the editor. If it's a really … … 95 97 $max_width = intval( get_option( 'large_size_w' ) ); 96 98 $max_height = intval( get_option( 'large_size_h' ) ); 99 97 100 if ( intval( $content_width ) > 0 ) { 98 101 $max_width = min( intval( $content_width ), $max_width ); 99 102 } 100 } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {103 } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ), true ) ) { 101 104 $max_width = intval( $_wp_additional_image_sizes[ $size ]['width'] ); 102 105 $max_height = intval( $_wp_additional_image_sizes[ $size ]['height'] ); … … 196 199 * Default 'medium'. 197 200 */ 198 if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { 201 $out = apply_filters( 'image_downsize', false, $id, $size ); 202 203 if ( $out ) { 199 204 return $out; 200 205 } … … 202 207 $img_url = wp_get_attachment_url( $id ); 203 208 $meta = wp_get_attachment_metadata( $id ); 204 $width = $height = 0; 209 $width = 0; 210 $height = 0; 205 211 $is_intermediate = false; 206 212 $img_url_basename = wp_basename( $img_url ); … … 220 226 221 227 // try for a new style intermediate size 222 if ( $intermediate = image_get_intermediate_size( $id, $size ) ) { 228 $intermediate = image_get_intermediate_size( $id, $size ); 229 230 if ( $intermediate ) { 223 231 $img_url = str_replace( $img_url_basename, $intermediate['file'], $img_url ); 224 232 $width = $intermediate['width']; 225 233 $height = $intermediate['height']; 226 234 $is_intermediate = true; 227 } elseif ( $size == 'thumbnail' ) {235 } elseif ( $size === 'thumbnail' ) { 228 236 // fall back to the old thumbnail 229 if ( ( $thumb_file = wp_get_attachment_thumb_file( $id ) ) && $info = getimagesize( $thumb_file ) ) { 237 $thumb_file = wp_get_attachment_thumb_file( $id ); 238 $info = getimagesize( $thumb_file ); 239 240 if ( $thumb_file && $info ) { 230 241 $img_url = str_replace( $img_url_basename, wp_basename( $thumb_file ), $img_url ); 231 242 $width = $info[0]; … … 234 245 } 235 246 } 247 236 248 if ( ! $width && ! $height && isset( $meta['width'], $meta['height'] ) ) { 237 249 // any other type: use the real image … … 246 258 return array( $img_url, $width, $height, $is_intermediate ); 247 259 } 260 248 261 return false; 249 250 262 } 251 263 … … 413 425 } 414 426 415 $width_ratio = $height_ratio = 1.0; 416 $did_width = $did_height = false; 427 $width_ratio = 1.0; 428 $height_ratio = 1.0; 429 $did_width = false; 430 $did_height = false; 417 431 418 432 if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) { … … 447 461 448 462 // Note: $did_width means it is possible $smaller_ratio == $width_ratio. 449 if ( $did_width && $w == $max_width - 1 ) {463 if ( $did_width && $w === $max_width - 1 ) { 450 464 $w = $max_width; // Round it up 451 465 } 452 466 453 467 // Note: $did_height means it is possible $smaller_ratio == $height_ratio. 454 if ( $did_height && $h == $max_height - 1 ) {468 if ( $did_height && $h === $max_height - 1 ) { 455 469 $h = $max_height; // Round it up 456 470 } … … 521 535 */ 522 536 $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); 537 523 538 if ( null !== $output ) { 524 539 return $output; … … 577 592 578 593 // if the resulting image would be the same size or larger we don't want to resize it 579 if ( $new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) {594 if ( $new_w >= $orig_w && $new_h >= $orig_h && intval( $dest_w ) !== intval( $orig_w ) && intval( $dest_h ) !== intval( $orig_h ) ) { 580 595 return false; 581 596 } … … 688 703 */ 689 704 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 690 if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) { 705 $imagedata = wp_get_attachment_metadata( $post_id ); 706 707 if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) { 691 708 return false; 692 709 } … … 705 722 foreach ( $imagedata['sizes'] as $_size => $data ) { 706 723 // If there's an exact match to an existing image size, short circuit. 707 if ( $data['width'] == $size[0] && $data['height'] == $size[1]) {724 if ( intval( $data['width'] ) === intval( $size[0] ) && intval( $data['height'] ) === intval( $size[1] ) ) { 708 725 $candidates[ $data['width'] * $data['height'] ] = $data; 709 726 break; … … 786 803 */ 787 804 function get_intermediate_image_sizes() { 788 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 789 $image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); // Standard sizes 790 if ( ! empty( $_wp_additional_image_sizes ) ) { 791 $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); 805 $default_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); 806 $additional_sizes = wp_get_additional_image_sizes(); 807 808 if ( ! empty( $additional_sizes ) ) { 809 $default_sizes = array_merge( $default_sizes, array_keys( $additional_sizes ) ); 792 810 } 793 811 … … 797 815 * @since 2.5.0 798 816 * 799 * @param array $image_sizes An array of intermediate image sizes. Defaults 800 * are 'thumbnail', 'medium', 'medium_large', 'large'. 801 */ 802 return apply_filters( 'intermediate_image_sizes', $image_sizes ); 817 * @param array $default_sizes An array of intermediate image sizes. Defaults 818 * are 'thumbnail', 'medium', 'medium_large', 'large'. 819 */ 820 return apply_filters( 'intermediate_image_sizes', $default_sizes ); 821 } 822 823 /** 824 * Returns a normalized list of all currently registered image sub-sizes. 825 * 826 * @since 5.3.0 827 * @uses wp_get_additional_image_sizes() 828 * @uses get_intermediate_image_sizes() 829 * 830 * @return array Associative array of the registered image sub-sizes. 831 */ 832 function wp_get_registered_image_subsizes() { 833 $additional_sizes = wp_get_additional_image_sizes(); 834 $all_sizes = array(); 835 836 foreach ( get_intermediate_image_sizes() as $size_name ) { 837 $size_data = array( 838 'width' => 0, 839 'height' => 0, 840 'crop' => false, 841 ); 842 843 if ( isset( $additional_sizes[ $size_name ]['width'] ) ) { 844 // For sizes added by plugins and themes. 845 $size_data['width'] = intval( $additional_sizes[ $size_name ]['width'] ); 846 } else { 847 // For default sizes set in options. 848 $size_data['width'] = intval( get_option( "{$size_name}_size_w" ) ); 849 } 850 851 if ( isset( $additional_sizes[ $size_name ]['height'] ) ) { 852 $size_data['height'] = intval( $additional_sizes[ $size_name ]['height'] ); 853 } else { 854 $size_data['height'] = intval( get_option( "{$size_name}_size_h" ) ); 855 } 856 857 if ( empty( $size_data['width'] ) && empty( $size_data['height'] ) ) { 858 // This size isn't set. 859 continue; 860 } 861 862 if ( isset( $additional_sizes[ $size_name ]['crop'] ) ) { 863 $size_data['crop'] = (bool) $additional_sizes[ $size_name ]['crop']; 864 } else { 865 $size_data['crop'] = (bool) get_option( "{$size_name}_crop" ); 866 } 867 868 $all_sizes[ $size_name ] = $size_data; 869 } 870 871 return $all_sizes; 803 872 } 804 873 … … 827 896 $src = false; 828 897 829 if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) { 830 /** This filter is documented in wp-includes/post.php */ 831 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); 832 833 $src_file = $icon_dir . '/' . wp_basename( $src ); 834 @list( $width, $height ) = getimagesize( $src_file ); 898 if ( $icon ) { 899 $src = wp_mime_type_icon( $attachment_id ); 900 901 if ( $src ) { 902 /** This filter is documented in wp-includes/post.php */ 903 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); 904 905 $src_file = $icon_dir . '/' . wp_basename( $src ); 906 @list( $width, $height ) = getimagesize( $src_file ); 907 } 835 908 } 836 909 … … 1015 1088 */ 1016 1089 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) { 1017 if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { 1090 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1091 1092 if ( ! $image ) { 1018 1093 return false; 1019 1094 } … … 1147 1222 // If the file name is part of the `src`, we've confirmed a match. 1148 1223 if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) { 1149 $src_matched = $is_src = true; 1224 $src_matched = true; 1225 $is_src = true; 1150 1226 } 1151 1227 … … 1233 1309 */ 1234 1310 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { 1235 if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { 1311 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1312 1313 if ( ! $image ) { 1236 1314 return false; 1237 1315 } … … 1319 1397 } 1320 1398 1321 $selected_images = $attachment_ids = array(); 1399 $selected_images = array(); 1400 $attachment_ids = array(); 1322 1401 1323 1402 foreach ( $matches[0] as $image ) { 1324 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && 1325 ( $attachment_id = absint( $class_id[1] ) ) ) { 1326 1327 /* 1328 * If exactly the same image tag is used more than once, overwrite it. 1329 * All identical tags will be replaced later with 'str_replace()'. 1330 */ 1331 $selected_images[ $image ] = $attachment_id; 1332 // Overwrite the ID when the same image is included more than once. 1333 $attachment_ids[ $attachment_id ] = true; 1403 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) ) { 1404 $attachment_id = absint( $class_id[1] ); 1405 1406 if ( $attachment_id ) { 1407 /* 1408 * If exactly the same image tag is used more than once, overwrite it. 1409 * All identical tags will be replaced later with 'str_replace()'. 1410 */ 1411 $selected_images[ $image ] = $attachment_id; 1412 // Overwrite the ID when the same image is included more than once. 1413 $attachment_ids[ $attachment_id ] = true; 1414 } 1334 1415 } 1335 1416 } … … 1540 1621 */ 1541 1622 $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); 1542 if ( $output != '' ) { 1623 1624 if ( ! empty( $output ) ) { 1543 1625 return $output; 1544 1626 } … … 1558 1640 1559 1641 $atts['width'] = (int) $atts['width']; 1642 1560 1643 if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) { 1561 1644 return $content; 1562 1645 } 1563 1646 1564 $id = $caption_id = $describedby = ''; 1647 $id = ''; 1648 $caption_id = ''; 1649 $describedby = ''; 1565 1650 1566 1651 if ( $atts['id'] ) { … … 1604 1689 1605 1690 $style = ''; 1691 1606 1692 if ( $caption_width ) { 1607 1693 $style = 'style="width: ' . (int) $caption_width . 'px" '; … … 1706 1792 */ 1707 1793 $output = apply_filters( 'post_gallery', '', $attr, $instance ); 1708 if ( $output != '' ) { 1794 1795 if ( ! empty( $output ) ) { 1709 1796 return $output; 1710 1797 } … … 1851 1938 1852 1939 $i = 0; 1940 1853 1941 foreach ( $attachments as $id => $attachment ) { 1854 1942 1855 1943 $attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : ''; 1944 1856 1945 if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) { 1857 1946 $image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr ); … … 1861 1950 $image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr ); 1862 1951 } 1952 1863 1953 $image_meta = wp_get_attachment_metadata( $id ); 1864 1954 1865 1955 $orientation = ''; 1956 1866 1957 if ( isset( $image_meta['height'], $image_meta['width'] ) ) { 1867 1958 $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape'; 1868 1959 } 1960 1869 1961 $output .= "<{$itemtag} class='gallery-item'>"; 1870 1962 $output .= " … … 1872 1964 $image_output 1873 1965 </{$icontag}>"; 1966 1874 1967 if ( $captiontag && trim( $attachment->post_excerpt ) ) { 1875 1968 $output .= " … … 1878 1971 </{$captiontag}>"; 1879 1972 } 1973 1880 1974 $output .= "</{$itemtag}>"; 1881 if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) { 1975 1976 if ( ! $html5 && $columns > 0 && ++$i % $columns === 0 ) { 1882 1977 $output .= '<br style="clear: both" />'; 1883 1978 } … … 2026 2121 */ 2027 2122 $output = apply_filters( 'post_playlist', '', $attr, $instance ); 2028 if ( $output != '' ) { 2123 2124 if ( ! empty( $output ) ) { 2029 2125 return $output; 2030 2126 } … … 2336 2432 */ 2337 2433 $override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance ); 2434 2338 2435 if ( '' !== $override ) { 2339 2436 return $override; … … 2360 2457 if ( ! empty( $atts['src'] ) ) { 2361 2458 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); 2362 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { 2459 2460 if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) { 2363 2461 return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); 2364 2462 } 2463 2365 2464 $primary = true; 2366 2465 array_unshift( $default_types, 'src' ); … … 2369 2468 if ( ! empty( $atts[ $ext ] ) ) { 2370 2469 $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); 2470 2371 2471 if ( strtolower( $type['ext'] ) === $ext ) { 2372 2472 $primary = true; … … 2378 2478 if ( ! $primary ) { 2379 2479 $audios = get_attached_media( 'audio', $post_id ); 2480 2380 2481 if ( empty( $audios ) ) { 2381 2482 return; … … 2384 2485 $audio = reset( $audios ); 2385 2486 $atts['src'] = wp_get_attachment_url( $audio->ID ); 2487 2386 2488 if ( empty( $atts['src'] ) ) { 2387 2489 return; … … 2399 2501 */ 2400 2502 $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); 2503 2401 2504 if ( 'mediaelement' === $library && did_action( 'init' ) ) { 2402 2505 wp_enqueue_style( 'wp-mediaelement' ); … … 2432 2535 2433 2536 $attr_strings = array(); 2537 2434 2538 foreach ( $html_atts as $k => $v ) { 2435 2539 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; … … 2437 2541 2438 2542 $html = ''; 2543 2439 2544 if ( 'mediaelement' === $library && 1 === $instance ) { 2440 2545 $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n"; 2441 2546 } 2547 2442 2548 $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) ); 2443 2549 2444 2550 $fileurl = ''; 2445 2551 $source = '<source type="%s" src="%s" />'; 2552 2446 2553 foreach ( $default_types as $fallback ) { 2447 2554 if ( ! empty( $atts[ $fallback ] ) ) { … … 2449 2556 $fileurl = $atts[ $fallback ]; 2450 2557 } 2558 2451 2559 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 2452 2560 $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); … … 2458 2566 $html .= wp_mediaelement_fallback( $fileurl ); 2459 2567 } 2568 2460 2569 $html .= '</audio>'; 2461 2570 … … 2545 2654 */ 2546 2655 $override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance ); 2656 2547 2657 if ( '' !== $override ) { 2548 2658 return $override; … … 2583 2693 } 2584 2694 2585 $is_vimeo = $is_youtube = false; 2695 $is_vimeo = false; 2696 $is_youtube = false; 2586 2697 $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; 2587 2698 $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; … … 2591 2702 $is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) ); 2592 2703 $is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) ); 2704 2593 2705 if ( ! $is_youtube && ! $is_vimeo ) { 2594 2706 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); 2595 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { 2707 2708 if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) { 2596 2709 return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); 2597 2710 } … … 2814 2927 2815 2928 foreach ( $attachments as $k => $attachment ) { 2816 if ( $attachment->ID == $post->ID) {2929 if ( intval( $attachment->ID ) === intval( $post->ID ) ) { 2817 2930 break; 2818 2931 } … … 2867 2980 $attachment = (object) $attachment; 2868 2981 } 2982 2869 2983 if ( ! is_object( $attachment ) ) { 2870 2984 return array(); … … 2879 2993 $objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 ); 2880 2994 } 2995 2881 2996 if ( ! empty( $attachment->post_mime_type ) ) { 2882 2997 $objects[] = 'attachment:' . $attachment->post_mime_type; 2998 2883 2999 if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { 2884 3000 foreach ( explode( '/', $attachment->post_mime_type ) as $token ) { … … 2891 3007 2892 3008 $taxonomies = array(); 3009 2893 3010 foreach ( $objects as $object ) { 2894 if ( $taxes = get_object_taxonomies( $object, $output ) ) { 3011 $taxes = get_object_taxonomies( $object, $output ); 3012 3013 if ( $taxes ) { 2895 3014 $taxonomies = array_merge( $taxonomies, $taxes ); 2896 3015 } … … 2918 3037 function get_taxonomies_for_attachments( $output = 'names' ) { 2919 3038 $taxonomies = array(); 3039 2920 3040 foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { 2921 3041 foreach ( $taxonomy->object_type as $object_type ) { 2922 if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {2923 if ( 'names' == $output ) {3042 if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { 3043 if ( 'names' === $output ) { 2924 3044 $taxonomies[] = $taxonomy->name; 2925 3045 } else { … … 3194 3314 */ 3195 3315 function wp_prepare_attachment_for_js( $attachment ) { 3196 if ( ! $attachment = get_post( $attachment ) ) { 3316 $attachment = get_post( $attachment ); 3317 3318 if ( ! $attachment ) { 3197 3319 return; 3198 3320 } 3199 3321 3200 if ( 'attachment' != $attachment->post_type ) {3322 if ( 'attachment' !== $attachment->post_type ) { 3201 3323 return; 3202 3324 } … … 3317 3439 3318 3440 /** This filter is documented in wp-includes/media.php */ 3319 if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { 3441 $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ); 3442 3443 if ( $downsize ) { 3320 3444 if ( empty( $downsize[3] ) ) { 3321 3445 continue; … … 3817 3941 */ 3818 3942 function get_attached_media( $type, $post = 0 ) { 3819 if ( ! $post = get_post( $post ) ) { 3943 $post = get_post( $post ); 3944 3945 if ( ! $post ) { 3820 3946 return array(); 3821 3947 } … … 3907 4033 */ 3908 4034 function get_post_galleries( $post, $html = true ) { 3909 if ( ! $post = get_post( $post ) ) { 4035 $post = get_post( $post ); 4036 4037 if ( ! $post ) { 3910 4038 return array(); 3911 4039 } … … 4028 4156 */ 4029 4157 function wp_maybe_generate_attachment_metadata( $attachment ) { 4030 if ( empty( $attachment ) || ( empty( $attachment->ID ) || ! $attachment_id = (int)$attachment->ID ) ) {4158 if ( empty( $attachment ) || empty( $attachment->ID ) ) { 4031 4159 return; 4032 4160 } 4033 4161 4034 $file = get_attached_file( $attachment_id ); 4035 $meta = wp_get_attachment_metadata( $attachment_id ); 4162 $attachment_id = (int) $attachment->ID; 4163 $file = get_attached_file( $attachment_id ); 4164 $meta = wp_get_attachment_metadata( $attachment_id ); 4165 4036 4166 if ( empty( $meta ) && file_exists( $file ) ) { 4037 $_meta = get_post_meta( $attachment_id ); 4038 $regeneration_lock = 'wp_generating_att_' . $attachment_id; 4039 if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $regeneration_lock ) ) { 4040 set_transient( $regeneration_lock, $file ); 4167 $_meta = get_post_meta( $attachment_id ); 4168 $_lock = 'wp_generating_att_' . $attachment_id; 4169 4170 if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $_lock ) ) { 4171 set_transient( $_lock, $file ); 4041 4172 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); 4042 delete_transient( $ regeneration_lock );4173 delete_transient( $_lock ); 4043 4174 } 4044 4175 } … … 4073 4204 } 4074 4205 4075 $sql 4206 $sql = $wpdb->prepare( 4076 4207 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 4077 4208 $path 4078 4209 ); 4210 4079 4211 $post_id = $wpdb->get_var( $sql ); 4080 4212
Note: See TracChangeset
for help on using the changeset viewer.