Ticket #37255: 37255.diff
| File 37255.diff, 23.3 KB (added by , 6 years ago) |
|---|
-
wp-includes/media.php
176 176 * 177 177 * @since 2.5.0 178 178 * 179 * @param int $ id Attachment ID for image.179 * @param int $attachment Attachment post or attachment ID for image. Defaults to global $post. 180 180 * @param string|int[] $size Optional. Image size to scale to. Accepts any valid image size name, 181 181 * or an array of width and height values in pixels (in that order). 182 182 * Default 'medium'. … … 189 189 * @type bool $3 Whether the image is a resized image. 190 190 * } 191 191 */ 192 function image_downsize( $id, $size = 'medium' ) { 193 $is_image = wp_attachment_is_image( $id ); 192 function image_downsize( $attachment = null, $size = 'medium' ) { 193 194 $post = get_post( $attachment ); 195 196 if ( ! $post || 'attachment' != $post->post_type ) { 197 return false; 198 } 199 200 $is_image = wp_attachment_is_image( $post ); 194 201 195 202 /** 196 203 * Filters whether to preempt the output of image_downsize(). … … 204 211 * @param int $id Attachment ID for image. 205 212 * @param array|string $size Requested size of image. Image size name, or array of width 206 213 * and height values (in that order). 214 * @param WP_Post $attachment Attachment post object. 207 215 */ 208 $out = apply_filters( 'image_downsize', false, $ id, $size);216 $out = apply_filters( 'image_downsize', false, $post->ID, $size, $post ); 209 217 210 218 if ( $out ) { 211 219 return $out; 212 220 } 213 221 214 $img_url = wp_get_attachment_url( $ id);215 $meta = wp_get_attachment_metadata( $ id);222 $img_url = wp_get_attachment_url( $post ); 223 $meta = wp_get_attachment_metadata( $post ); 216 224 $width = 0; 217 225 $height = 0; 218 226 $is_intermediate = false; … … 232 240 } 233 241 234 242 // Try for a new style intermediate size. 235 $intermediate = image_get_intermediate_size( $ id, $size );243 $intermediate = image_get_intermediate_size( $post, $size ); 236 244 237 245 if ( $intermediate ) { 238 246 $img_url = str_replace( $img_url_basename, $intermediate['file'], $img_url ); … … 241 249 $is_intermediate = true; 242 250 } elseif ( 'thumbnail' === $size ) { 243 251 // Fall back to the old thumbnail. 244 $thumb_file = wp_get_attachment_thumb_file( $ id);252 $thumb_file = wp_get_attachment_thumb_file( $post ); 245 253 $info = null; 246 254 247 255 if ( $thumb_file ) { … … 363 371 * 364 372 * @since 2.5.0 365 373 * 366 * @param int $ id Attachment ID.374 * @param int $attachment Attachment post or post ID. 367 375 * @param string $alt Image description for the alt attribute. 368 376 * @param string $title Image description for the title attribute. 369 377 * @param string $align Part of the class name for aligning the image. … … 372 380 * (in that order). Default 'medium'. 373 381 * @return string HTML IMG element for given image attachment 374 382 */ 375 function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { 376 383 function get_image_tag( $attachment, $alt, $title, $align, $size = 'medium' ) { 384 385 if( $attachment instanceof WP_Post && 'attachment' == $attachment->post_type ) { 386 $id = $attachment->ID; 387 } else if( is_numeric( $attachment ) ) { 388 $id = $attachment; 389 } else { 390 return ''; 391 } 392 377 393 list( $img_src, $width, $height ) = image_downsize( $id, $size ); 378 394 $hwstring = image_hwstring( $width, $height ); 379 395 … … 391 407 * @param string $align Part of the class name for aligning the image. 392 408 * @param string|array $size Size of image. Image size or array of width and height values (in that order). 393 409 * Default 'medium'. 410 * @param WP_Post $attachment Attachment post object. 394 411 */ 395 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );412 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size); 396 413 397 414 $html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; 398 415 … … 408 425 * @param string $align Part of the class name for aligning the image. 409 426 * @param string|array $size Size of image. Image size or array of width and height values (in that order). 410 427 * Default 'medium'. 428 * @param WP_Post $attachment Attachment post object. 411 429 */ 412 430 return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); 413 431 } … … 743 761 * 744 762 * @since 2.5.0 745 763 * 746 * @param int $ post_id Attachment ID.764 * @param int $attachment Attachment post or post ID. 747 765 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array 748 766 * of width and height values in pixels (in that order). 749 767 * Default 'thumbnail'. … … 758 776 * @type string $url Image's URL. 759 777 * } 760 778 */ 761 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 762 $imagedata = wp_get_attachment_metadata( $post_id ); 779 function image_get_intermediate_size( $attachment, $size = 'thumbnail' ) { 780 781 $post = get_post( $attachment ); 782 $imagedata = wp_get_attachment_metadata( $post ); 763 783 764 if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {784 if ( ! $size || ! $post || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) { 765 785 return false; 766 786 } 767 787 … … 830 850 831 851 // Include the full filesystem path of the intermediate file. 832 852 if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) { 833 $file_url = wp_get_attachment_url( $post _id);853 $file_url = wp_get_attachment_url( $post ); 834 854 $data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] ); 835 855 $data['url'] = path_join( dirname( $file_url ), $data['file'] ); 836 856 } … … 847 867 * @param int $post_id The post_id of the image attachment 848 868 * @param string|array $size Registered image size or flat array of initially-requested height and width 849 869 * dimensions (in that order). 870 * @param WP_Post $attachment Attachment post object. 850 871 */ 851 return apply_filters( 'image_get_intermediate_size', $data, $post _id, $size);872 return apply_filters( 'image_get_intermediate_size', $data, $post->ID, $size, $post ); 852 873 } 853 874 854 875 /** … … 937 958 * 938 959 * @since 2.5.0 939 960 * 940 * @param int $attachment _id Image attachment ID.961 * @param int $attachment Attachment post or post ID. Defaults to global $post. 941 962 * @param string|int[] $size Optional. Image size. Accepts any valid image size name, or an array of width 942 963 * and height values in pixels (in that order). Default 'thumbnail'. 943 964 * @param bool $icon Optional. Whether the image should fall back to a mime type icon. Default false. … … 949 970 * @type int $2 Image height in pixels. 950 971 * } 951 972 */ 952 function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { 973 function wp_get_attachment_image_src( $attachment = null, $size = 'thumbnail', $icon = false ) { 974 975 $post = get_post( $attachment ); 976 977 if ( ! $post || 'attachment' != $post->post_type ) { 978 return false; 979 } 980 953 981 // Get a thumbnail or intermediate image if there is one. 982 $attachment_id = $post->ID; 954 983 $image = image_downsize( $attachment_id, $size ); 955 984 if ( ! $image ) { 956 985 $src = false; … … 987 1016 * @param string|int[] $size Requested size of image. Image size name, or array of width 988 1017 * and height values (in that order). 989 1018 * @param bool $icon Whether the image should be treated as an icon. 1019 * @param WP_Post $attachment Attachment post object. 990 1020 */ 991 return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );1021 return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon, $post ); 992 1022 } 993 1023 994 1024 /** … … 1001 1031 * 1002 1032 * @since 2.5.0 1003 1033 * 1004 * @param int $attachment _id Image attachment ID.1034 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1005 1035 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width 1006 1036 * and height values in pixels (in that order). Default 'thumbnail'. 1007 1037 * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. … … 1018 1048 * } 1019 1049 * @return string HTML img element or empty string on failure. 1020 1050 */ 1021 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) { 1051 function wp_get_attachment_image( $attachment = null, $size = 'thumbnail', $icon = false, $attr = '' ) { 1052 1053 $post = get_post( $attachment ); 1054 1055 if ( ! $post || 'attachment' != $post->post_type ) { 1056 return ''; 1057 } 1058 1022 1059 $html = ''; 1023 $image = wp_get_attachment_image_src( $ attachment_id, $size, $icon );1060 $image = wp_get_attachment_image_src( $post, $size, $icon ); 1024 1061 if ( $image ) { 1025 1062 list( $src, $width, $height ) = $image; 1026 1063 $hwstring = image_hwstring( $width, $height ); … … 1028 1065 if ( is_array( $size_class ) ) { 1029 1066 $size_class = join( 'x', $size_class ); 1030 1067 } 1031 $attachment = get_post( $attachment_id );1032 1068 $default_attr = array( 1033 1069 'src' => $src, 1034 1070 'class' => "attachment-$size_class size-$size_class", 1035 'alt' => trim( strip_tags( get_post_meta( $ attachment_id, '_wp_attachment_image_alt', true ) ) ),1071 'alt' => trim( strip_tags( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ), 1036 1072 ); 1037 1073 1038 1074 $attr = wp_parse_args( $attr, $default_attr ); … … 1039 1075 1040 1076 // Generate 'srcset' and 'sizes' if not already present. 1041 1077 if ( empty( $attr['srcset'] ) ) { 1042 $image_meta = wp_get_attachment_metadata( $ attachment_id);1078 $image_meta = wp_get_attachment_metadata( $post ); 1043 1079 1044 1080 if ( is_array( $image_meta ) ) { 1045 1081 $size_array = array( absint( $width ), absint( $height ) ); 1046 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $ attachment_id);1047 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $ attachment_id);1082 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $post->ID ); 1083 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $post->ID ); 1048 1084 1049 1085 if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { 1050 1086 $attr['srcset'] = $srcset; … … 1067 1103 * @param string|array $size Requested size. Image size or array of width and height values 1068 1104 * (in that order). Default 'thumbnail'. 1069 1105 */ 1070 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $ attachment, $size );1106 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size ); 1071 1107 $attr = array_map( 'esc_attr', $attr ); 1072 1108 $html = rtrim( "<img $hwstring" ); 1073 1109 foreach ( $attr as $name => $value ) { … … 1084 1120 * 1085 1121 * @since 4.4.0 1086 1122 * 1087 * @param int $attachment _id Image attachment ID.1123 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1088 1124 * @param string|array $size Optional. Image size to retrieve. Accepts any valid image size, or an array 1089 1125 * of width and height values in pixels (in that order). Default 'thumbnail'. 1090 1126 * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. 1091 1127 * @return string|false Attachment URL or false if no image is available. 1092 1128 */ 1093 function wp_get_attachment_image_url( $attachment _id, $size = 'thumbnail', $icon = false ) {1094 $image = wp_get_attachment_image_src( $attachment _id, $size, $icon );1129 function wp_get_attachment_image_url( $attachment = null, $size = 'thumbnail', $icon = false ) { 1130 $image = wp_get_attachment_image_src( $attachment, $size, $icon ); 1095 1131 return isset( $image['0'] ) ? $image['0'] : false; 1096 1132 } 1097 1133 … … 1155 1191 * 1156 1192 * @see wp_calculate_image_srcset() 1157 1193 * 1158 * @param int $attachment _id Image attachment ID.1194 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1159 1195 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array of 1160 1196 * width and height values in pixels (in that order). Default 'medium'. 1161 1197 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. … … 1162 1198 * Default null. 1163 1199 * @return string|bool A 'srcset' value string or false. 1164 1200 */ 1165 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) { 1166 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1201 function wp_get_attachment_image_srcset( $attachment = null, $size = 'medium', $image_meta = null ) { 1202 1203 $post = get_post( $attachment ); 1204 1205 if ( ! $post || 'attachment' != $post->post_type ) { 1206 return false; 1207 } 1208 1209 $image = wp_get_attachment_image_src( $post, $size ); 1167 1210 1168 1211 if ( ! $image ) { 1169 1212 return false; … … 1170 1213 } 1171 1214 1172 1215 if ( ! is_array( $image_meta ) ) { 1173 $image_meta = wp_get_attachment_metadata( $ attachment_id);1216 $image_meta = wp_get_attachment_metadata( $post ); 1174 1217 } 1175 1218 1176 1219 $image_src = $image[0]; … … 1179 1222 absint( $image[2] ), 1180 1223 ); 1181 1224 1182 return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $ attachment_id);1225 return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $post->ID ); 1183 1226 } 1184 1227 1185 1228 /** … … 1396 1439 * 1397 1440 * @see wp_calculate_image_sizes() 1398 1441 * 1399 * @param int $attachment _id Image attachment ID.1442 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1400 1443 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array of width 1401 1444 * and height values in pixels (in that order). Default 'medium'. 1402 1445 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. … … 1403 1446 * Default null. 1404 1447 * @return string|bool A valid source size value for use in a 'sizes' attribute or false. 1405 1448 */ 1406 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { 1407 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1449 function wp_get_attachment_image_sizes( $attachment = null, $size = 'medium', $image_meta = null ) { 1450 1451 $post = get_post( $attachment ); 1452 1453 if ( ! $post || 'attachment' != $post->post_type ) { 1454 return false; 1455 } 1456 1457 $image = wp_get_attachment_image_src( $post, $size ); 1408 1458 1409 1459 if ( ! $image ) { 1410 1460 return false; … … 1411 1461 } 1412 1462 1413 1463 if ( ! is_array( $image_meta ) ) { 1414 $image_meta = wp_get_attachment_metadata( $ attachment_id);1464 $image_meta = wp_get_attachment_metadata( $post ); 1415 1465 } 1416 1466 1417 1467 $image_src = $image[0]; … … 1420 1470 absint( $image[2] ), 1421 1471 ); 1422 1472 1423 return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $ attachment_id);1473 return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $post->ID ); 1424 1474 } 1425 1475 1426 1476 /** … … 4473 4523 add_image_size( '1536x1536', 1536, 1536 ); 4474 4524 // 2x large size. 4475 4525 add_image_size( '2048x2048', 2048, 2048 ); 4476 } 4526 } 4527 No newline at end of file -
wp-includes/post.php
5770 5770 * 5771 5771 * @since 2.1.0 5772 5772 * 5773 * @param int $attachment_id Attachmentpost ID. Defaults to global $post.5773 * @param int|WP_Post $attachment Attachment post or post ID. Defaults to global $post. 5774 5774 * @param bool $unfiltered Optional. If true, filters are not run. Default false. 5775 5775 * @return mixed Attachment meta field. False on failure. 5776 5776 */ 5777 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { 5778 $attachment_id = (int) $attachment_id; 5779 $post = get_post( $attachment_id ); 5780 if ( ! $post ) { 5777 function wp_get_attachment_metadata( $attachment = null, $unfiltered = false ) { 5778 5779 $post = get_post( $attachment ); 5780 5781 if ( ! $post || 'attachment' != $post->post_type ) { 5781 5782 return false; 5782 5783 } 5783 5784 … … 5795 5796 * @param array|bool $data Array of meta data for the given attachment, or false 5796 5797 * if the object does not exist. 5797 5798 * @param int $attachment_id Attachment post ID. 5799 * @param WP_Post $attachment Attachment WP_Post object. 5798 5800 */ 5799 return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );5801 return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID, $post ); 5800 5802 } 5801 5803 5802 5804 /** … … 5804 5806 * 5805 5807 * @since 2.1.0 5806 5808 * 5807 * @param int $attachment_id Attachmentpost ID.5809 * @param int|WP_Post $attachment Attachment post or post ID. 5808 5810 * @param array $data Attachment meta data. 5809 5811 * @return int|bool False if $post is invalid. 5810 5812 */ 5811 function wp_update_attachment_metadata( $attachment_id, $data ) { 5812 $attachment_id = (int) $attachment_id; 5813 $post = get_post( $attachment_id ); 5814 if ( ! $post ) { 5813 function wp_update_attachment_metadata( $attachment, $data ) { 5814 5815 $post = get_post( $attachment ); 5816 5817 if ( ! $post || 'attachment' != $post->post_type ) { 5815 5818 return false; 5816 5819 } 5817 5820 … … 5822 5825 * 5823 5826 * @param array $data Array of updated attachment meta data. 5824 5827 * @param int $attachment_id Attachment post ID. 5828 * @param WP_Post $attachment Attachment WP_Post object. 5825 5829 */ 5826 $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );5830 $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID, $post ); 5827 5831 if ( $data ) { 5828 5832 return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 5829 5833 } else { … … 5838 5842 * 5839 5843 * @global string $pagenow 5840 5844 * 5841 * @param int $attachment_id Optional. Attachment post ID. Defaults toglobal $post.5845 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global $post. 5842 5846 * @return string|false Attachment URL, otherwise false. 5843 5847 */ 5844 function wp_get_attachment_url( $attachment_id = 0 ) { 5845 $attachment_id = (int) $attachment_id; 5846 $post = get_post( $attachment_id ); 5847 if ( ! $post ) { 5848 function wp_get_attachment_url( $attachment = null ) { 5849 5850 $post = get_post( $attachment ); 5851 5852 if ( ! $post || 'attachment' != $post->post_type ) { 5848 5853 return false; 5849 5854 } 5850 5855 5851 if ( 'attachment' != $post->post_type ) {5852 return false;5853 }5854 5855 5856 $url = ''; 5856 5857 // Get attached file. 5857 5858 $file = get_post_meta( $post->ID, '_wp_attached_file', true ); … … 5893 5894 * 5894 5895 * @param string $url URL for the given attachment. 5895 5896 * @param int $attachment_id Attachment post ID. 5897 * @param WP_Post $attachment Attachment WP_Post object. 5896 5898 */ 5897 $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );5899 $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID, $post ); 5898 5900 5899 5901 if ( empty( $url ) ) { 5900 5902 return false; … … 5908 5910 * 5909 5911 * @since 4.6.0 5910 5912 * 5911 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.5913 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global $post. 5912 5914 * @return string|false False on failure. Attachment caption on success. 5913 5915 */ 5914 function wp_get_attachment_caption( $post_id = 0 ) { 5915 $post_id = (int) $post_id; 5916 $post = get_post( $post_id ); 5917 if ( ! $post ) { 5916 function wp_get_attachment_caption( $attachment = null ) { 5917 5918 $post = get_post( $attachment ); 5919 5920 if ( ! $post || 'attachment' !== $post->post_type ) { 5918 5921 return false; 5919 5922 } 5920 5923 5921 if ( 'attachment' !== $post->post_type ) {5922 return false;5923 }5924 5925 5924 $caption = $post->post_excerpt; 5926 5925 5927 5926 /** … … 5930 5929 * @since 4.6.0 5931 5930 * 5932 5931 * @param string $caption Caption for the given attachment. 5933 * @param int $post_id Attachment ID. 5932 * @param int $attachment_id Attachment ID. 5933 * @param WP_Post $attachment Attachment WP_Post object. 5934 5934 */ 5935 return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );5935 return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID, $post ); 5936 5936 } 5937 5937 5938 5938 /** … … 5940 5940 * 5941 5941 * @since 2.1.0 5942 5942 * 5943 * @param int $post_id Optional. Attachment ID. Default 0.5943 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post. 5944 5944 * @return string|false False on failure. Thumbnail file path on success. 5945 5945 */ 5946 function wp_get_attachment_thumb_file( $post_id = 0 ) { 5947 $post_id = (int) $post_id; 5948 $post = get_post( $post_id ); 5949 if ( ! $post ) { 5946 function wp_get_attachment_thumb_file( $attachment = null ) { 5947 5948 $post = get_post( $attachment ); 5949 5950 if ( ! $post || 'attachment' != $post->post_type ) { 5950 5951 return false; 5951 5952 } 5952 5953 … … 5954 5955 if ( ! is_array( $imagedata ) ) { 5955 5956 return false; 5956 5957 } 5957 5958 5958 5959 $file = get_attached_file( $post->ID ); 5959 5960 5960 5961 if ( ! empty( $imagedata['thumb'] ) ) { 5961 5962 $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ); 5962 5963 if ( file_exists( $thumbfile ) ) { … … 5965 5966 * 5966 5967 * @since 2.1.0 5967 5968 * 5968 * @param string $thumbfile File path to the attachment thumbnail. 5969 * @param int $post_id Attachment ID. 5969 * @param string $thumbfile File path to the attachment thumbnail. 5970 * @param int $attachment_id Attachment ID. 5971 * @param WP_Post $attachment Attachment post object. 5970 5972 */ 5971 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );5973 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID, $post ); 5972 5974 } 5973 5975 } 5974 5976 return false; … … 5979 5981 * 5980 5982 * @since 2.1.0 5981 5983 * 5982 * @param int $post_id Optional. Attachment ID. Default 0.5984 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post. 5983 5985 * @return string|false False on failure. Thumbnail URL on success. 5984 5986 */ 5985 function wp_get_attachment_thumb_url( $post_id = 0 ) { 5986 $post_id = (int) $post_id; 5987 $post = get_post( $post_id ); 5988 if ( ! $post ) { 5987 function wp_get_attachment_thumb_url( $attachment = null ) { 5988 5989 $post = get_post( $attachment ); 5990 5991 if ( ! $post || 'attachment' != $post->post_type ) { 5989 5992 return false; 5990 5993 } 5991 5994 … … 5994 5997 return false; 5995 5998 } 5996 5999 5997 $sized = image_downsize( $post _id, 'thumbnail' );6000 $sized = image_downsize( $post->ID, 'thumbnail' ); 5998 6001 if ( $sized ) { 5999 6002 return $sized[0]; 6000 6003 } … … 6012 6015 * @since 2.1.0 6013 6016 * 6014 6017 * @param string $url URL for the attachment thumbnail. 6015 * @param int $post_id Attachment ID. 6018 * @param int $attachment_id Attachment ID. 6019 * @param WP_Post $attachment Attachment post object. 6016 6020 */ 6017 return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );6021 return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID, $post ); 6018 6022 } 6019 6023 6020 6024 /** … … 6027 6031 * @return bool True if one of the accepted types, false otherwise. 6028 6032 */ 6029 6033 function wp_attachment_is( $type, $post = null ) { 6034 6030 6035 $post = get_post( $post ); 6031 if ( ! $post ) { 6036 6037 if ( ! $post || 'attachment' != $post->post_type ) { 6032 6038 return false; 6033 6039 } 6034 6040 … … 7263 7269 * @param int $attachment_id Attachment ID. 7264 7270 */ 7265 7271 return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id ); 7266 } 7272 } 7273 No newline at end of file