Ticket #37255: 37255-1.patch
| File 37255-1.patch, 23.2 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 $post = get_post( $attachment ); 386 387 if( ! $post || 'attachment' !== $post->post_type ) { 388 return ''; 389 } 390 391 $id = $post->ID; 377 392 list( $img_src, $width, $height ) = image_downsize( $id, $size ); 378 393 $hwstring = image_hwstring( $width, $height ); 379 394 … … 391 406 * @param string $align Part of the class name for aligning the image. 392 407 * @param string|array $size Size of image. Image size or array of width and height values (in that order). 393 408 * Default 'medium'. 409 * @param WP_Post $attachment Attachment post object. 394 410 */ 395 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );411 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size); 396 412 397 413 $html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; 398 414 … … 408 424 * @param string $align Part of the class name for aligning the image. 409 425 * @param string|array $size Size of image. Image size or array of width and height values (in that order). 410 426 * Default 'medium'. 427 * @param WP_Post $attachment Attachment post object. 411 428 */ 412 return apply_filters( 'get_image_tag', $html, $ id, $alt, $title, $align, $size );429 return apply_filters( 'get_image_tag', $html, $post->ID, $alt, $title, $align, $size ); 413 430 } 414 431 415 432 /** … … 743 760 * 744 761 * @since 2.5.0 745 762 * 746 * @param int $ post_id Attachment ID.763 * @param int $attachment Attachment post or post ID. 747 764 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array 748 765 * of width and height values in pixels (in that order). 749 766 * Default 'thumbnail'. … … 758 775 * @type string $url Image's URL. 759 776 * } 760 777 */ 761 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 762 $imagedata = wp_get_attachment_metadata( $post_id ); 778 function image_get_intermediate_size( $attachment, $size = 'thumbnail' ) { 779 780 $post = get_post( $attachment ); 781 $imagedata = wp_get_attachment_metadata( $post ); 763 782 764 if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {783 if ( ! $size || ! $post || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) { 765 784 return false; 766 785 } 767 786 … … 830 849 831 850 // Include the full filesystem path of the intermediate file. 832 851 if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) { 833 $file_url = wp_get_attachment_url( $post _id);852 $file_url = wp_get_attachment_url( $post ); 834 853 $data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] ); 835 854 $data['url'] = path_join( dirname( $file_url ), $data['file'] ); 836 855 } … … 847 866 * @param int $post_id The post_id of the image attachment 848 867 * @param string|array $size Registered image size or flat array of initially-requested height and width 849 868 * dimensions (in that order). 869 * @param WP_Post $attachment Attachment post object. 850 870 */ 851 return apply_filters( 'image_get_intermediate_size', $data, $post _id, $size);871 return apply_filters( 'image_get_intermediate_size', $data, $post->ID, $size, $post ); 852 872 } 853 873 854 874 /** … … 937 957 * 938 958 * @since 2.5.0 939 959 * 940 * @param int $attachment _id Image attachment ID.960 * @param int $attachment Attachment post or post ID. Defaults to global $post. 941 961 * @param string|int[] $size Optional. Image size. Accepts any valid image size name, or an array of width 942 962 * and height values in pixels (in that order). Default 'thumbnail'. 943 963 * @param bool $icon Optional. Whether the image should fall back to a mime type icon. Default false. … … 950 970 * @type bool $3 Whether the image is a resized image. 951 971 * } 952 972 */ 953 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 954 981 // Get a thumbnail or intermediate image if there is one. 982 $attachment_id = $post->ID; 955 983 $image = image_downsize( $attachment_id, $size ); 956 984 if ( ! $image ) { 957 985 $src = false; … … 989 1017 * @param string|int[] $size Requested size of image. Image size name, or array of width 990 1018 * and height values (in that order). 991 1019 * @param bool $icon Whether the image should be treated as an icon. 1020 * @param WP_Post $attachment Attachment post object. 992 1021 */ 993 return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );1022 return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon, $post ); 994 1023 } 995 1024 996 1025 /** … … 1003 1032 * 1004 1033 * @since 2.5.0 1005 1034 * 1006 * @param int $attachment _id Image attachment ID.1035 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1007 1036 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width 1008 1037 * and height values in pixels (in that order). Default 'thumbnail'. 1009 1038 * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. … … 1020 1049 * } 1021 1050 * @return string HTML img element or empty string on failure. 1022 1051 */ 1023 function wp_get_attachment_image( $attachment _id, $size = 'thumbnail', $icon = false, $attr = '' ) {1052 function wp_get_attachment_image( $attachment, $size = 'thumbnail', $icon = false, $attr = '' ) { 1024 1053 $html = ''; 1025 $image = wp_get_attachment_image_src( $attachment _id, $size, $icon );1054 $image = wp_get_attachment_image_src( $attachment, $size, $icon ); 1026 1055 1027 1056 if ( $image ) { 1028 1057 list( $src, $width, $height ) = $image; 1029 1058 1030 $ attachment = get_post( $attachment_id);1059 $post = get_post( $attachment ); 1031 1060 $hwstring = image_hwstring( $width, $height ); 1032 1061 $size_class = $size; 1033 1062 … … 1038 1067 $default_attr = array( 1039 1068 'src' => $src, 1040 1069 'class' => "attachment-$size_class size-$size_class", 1041 'alt' => trim( strip_tags( get_post_meta( $ attachment_id, '_wp_attachment_image_alt', true ) ) ),1070 'alt' => trim( strip_tags( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ), 1042 1071 ); 1043 1072 1044 1073 // Add `loading` attribute. … … 1050 1079 1051 1080 // Generate 'srcset' and 'sizes' if not already present. 1052 1081 if ( empty( $attr['srcset'] ) ) { 1053 $image_meta = wp_get_attachment_metadata( $ attachment_id);1082 $image_meta = wp_get_attachment_metadata( $post ); 1054 1083 1055 1084 if ( is_array( $image_meta ) ) { 1056 1085 $size_array = array( absint( $width ), absint( $height ) ); 1057 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $ attachment_id);1058 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $ attachment_id);1086 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $post->ID ); 1087 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $post->ID ); 1059 1088 1060 1089 if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { 1061 1090 $attr['srcset'] = $srcset; … … 1078 1107 * @param string|array $size Requested size. Image size or array of width and height values 1079 1108 * (in that order). Default 'thumbnail'. 1080 1109 */ 1081 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $ attachment, $size );1110 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size ); 1082 1111 1083 1112 $attr = array_map( 'esc_attr', $attr ); 1084 1113 $html = rtrim( "<img $hwstring" ); … … 1098 1127 * 1099 1128 * @since 4.4.0 1100 1129 * 1101 * @param int $attachment _id Image attachment ID.1130 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1102 1131 * @param string|array $size Optional. Image size to retrieve. Accepts any valid image size, or an array 1103 1132 * of width and height values in pixels (in that order). Default 'thumbnail'. 1104 1133 * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. 1105 1134 * @return string|false Attachment URL or false if no image is available. 1106 1135 */ 1107 function wp_get_attachment_image_url( $attachment _id, $size = 'thumbnail', $icon = false ) {1108 $image = wp_get_attachment_image_src( $attachment _id, $size, $icon );1136 function wp_get_attachment_image_url( $attachment = null, $size = 'thumbnail', $icon = false ) { 1137 $image = wp_get_attachment_image_src( $attachment, $size, $icon ); 1109 1138 return isset( $image['0'] ) ? $image['0'] : false; 1110 1139 } 1111 1140 … … 1169 1198 * 1170 1199 * @see wp_calculate_image_srcset() 1171 1200 * 1172 * @param int $attachment _id Image attachment ID.1201 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1173 1202 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array of 1174 1203 * width and height values in pixels (in that order). Default 'medium'. 1175 1204 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. … … 1176 1205 * Default null. 1177 1206 * @return string|bool A 'srcset' value string or false. 1178 1207 */ 1179 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) { 1180 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1208 function wp_get_attachment_image_srcset( $attachment = null, $size = 'medium', $image_meta = null ) { 1209 1210 $post = get_post( $attachment ); 1211 1212 if ( ! $post || 'attachment' != $post->post_type ) { 1213 return false; 1214 } 1215 1216 $image = wp_get_attachment_image_src( $post, $size ); 1181 1217 1182 1218 if ( ! $image ) { 1183 1219 return false; … … 1184 1220 } 1185 1221 1186 1222 if ( ! is_array( $image_meta ) ) { 1187 $image_meta = wp_get_attachment_metadata( $ attachment_id);1223 $image_meta = wp_get_attachment_metadata( $post ); 1188 1224 } 1189 1225 1190 1226 $image_src = $image[0]; … … 1193 1229 absint( $image[2] ), 1194 1230 ); 1195 1231 1196 return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $ attachment_id);1232 return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $post->ID ); 1197 1233 } 1198 1234 1199 1235 /** … … 1410 1446 * 1411 1447 * @see wp_calculate_image_sizes() 1412 1448 * 1413 * @param int $attachment _id Image attachment ID.1449 * @param int $attachment Attachment post or post ID. Defaults to global $post. 1414 1450 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array of width 1415 1451 * and height values in pixels (in that order). Default 'medium'. 1416 1452 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. … … 1417 1453 * Default null. 1418 1454 * @return string|bool A valid source size value for use in a 'sizes' attribute or false. 1419 1455 */ 1420 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { 1421 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1456 function wp_get_attachment_image_sizes( $attachment = null, $size = 'medium', $image_meta = null ) { 1457 1458 $post = get_post( $attachment ); 1459 1460 if ( ! $post || 'attachment' != $post->post_type ) { 1461 return false; 1462 } 1463 1464 $image = wp_get_attachment_image_src( $post, $size ); 1422 1465 1423 1466 if ( ! $image ) { 1424 1467 return false; … … 1425 1468 } 1426 1469 1427 1470 if ( ! is_array( $image_meta ) ) { 1428 $image_meta = wp_get_attachment_metadata( $ attachment_id);1471 $image_meta = wp_get_attachment_metadata( $post ); 1429 1472 } 1430 1473 1431 1474 $image_src = $image[0]; … … 1434 1477 absint( $image[2] ), 1435 1478 ); 1436 1479 1437 return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $ attachment_id);1480 return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $post->ID ); 1438 1481 } 1439 1482 1440 1483 /** … … 4678 4721 add_image_size( '1536x1536', 1536, 1536 ); 4679 4722 // 2x large size. 4680 4723 add_image_size( '2048x2048', 2048, 2048 ); 4681 } 4724 } 4725 No newline at end of file -
wp-includes/post.php
5904 5904 * 5905 5905 * @since 2.1.0 5906 5906 * 5907 * @param int $attachment _id Attachmentpost ID. Defaults to global $post.5907 * @param int $attachment Attachment post or post ID. Defaults to global $post. 5908 5908 * @param bool $unfiltered Optional. If true, filters are not run. Default false. 5909 5909 * @return array|false { 5910 5910 * Attachment metadata. False on failure. … … 5917 5917 * @type array $image_meta Image metadata. 5918 5918 * } 5919 5919 */ 5920 function wp_get_attachment_metadata( $attachment _id = 0, $unfiltered = false ) {5921 $attachment_id = (int) $attachment_id;5922 5923 $post = get_post( $attachment_id );5924 if ( ! $post ) {5920 function wp_get_attachment_metadata( $attachment = null, $unfiltered = false ) { 5921 5922 $post = get_post( $attachment ); 5923 5924 if ( ! $post || 'attachment' !== $post->post_type ) { 5925 5925 return false; 5926 5926 } 5927 5927 … … 5939 5939 * @param array|bool $data Array of meta data for the given attachment, or false 5940 5940 * if the object does not exist. 5941 5941 * @param int $attachment_id Attachment post ID. 5942 * @param WP_Post $attachment Attachment WP_Post object. 5942 5943 */ 5943 return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );5944 return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID, $post ); 5944 5945 } 5945 5946 5946 5947 /** … … 5948 5949 * 5949 5950 * @since 2.1.0 5950 5951 * 5951 * @param int $attachment _id Attachmentpost ID.5952 * @param int $attachment Attachment post or post ID. 5952 5953 * @param array $data Attachment meta data. 5953 5954 * @return int|bool False if $post is invalid. 5954 5955 */ 5955 function wp_update_attachment_metadata( $attachment_id, $data ) { 5956 $attachment_id = (int) $attachment_id; 5956 function wp_update_attachment_metadata( $attachment, $data ) { 5957 5957 5958 $post = get_post( $attachment_id ); 5959 if ( ! $post ) { 5958 $post = get_post( $attachment ); 5959 5960 if ( ! $post || 'attachment' !== $post->post_type ) { 5960 5961 return false; 5961 5962 } 5962 5963 … … 5967 5968 * 5968 5969 * @param array $data Array of updated attachment meta data. 5969 5970 * @param int $attachment_id Attachment post ID. 5971 * @param WP_Post $attachment Attachment WP_Post object. 5970 5972 */ 5971 $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );5973 $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID, $post ); 5972 5974 if ( $data ) { 5973 5975 return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 5974 5976 } else { … … 5983 5985 * 5984 5986 * @global string $pagenow 5985 5987 * 5986 * @param int $attachment _id Optional. Attachmentpost ID. Defaults to global $post.5988 * @param int $attachment Optional. Attachment post or post ID. Defaults to global $post. 5987 5989 * @return string|false Attachment URL, otherwise false. 5988 5990 */ 5989 function wp_get_attachment_url( $attachment_id = 0 ) { 5990 $attachment_id = (int) $attachment_id; 5991 function wp_get_attachment_url( $attachment = null ) { 5991 5992 5992 $post = get_post( $attachment_id ); 5993 if ( ! $post ) { 5993 $post = get_post( $attachment ); 5994 5995 if ( ! $post || 'attachment' !== $post->post_type ) { 5994 5996 return false; 5995 5997 } 5996 5998 5997 if ( 'attachment' !== $post->post_type ) {5998 return false;5999 }6000 6001 5999 $url = ''; 6002 6000 // Get attached file. 6003 6001 $file = get_post_meta( $post->ID, '_wp_attached_file', true ); … … 6039 6037 * 6040 6038 * @param string $url URL for the given attachment. 6041 6039 * @param int $attachment_id Attachment post ID. 6040 * @param WP_Post $attachment Attachment WP_Post object. 6042 6041 */ 6043 $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );6042 $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID, $post ); 6044 6043 6045 6044 if ( empty( $url ) ) { 6046 6045 return false; … … 6054 6053 * 6055 6054 * @since 4.6.0 6056 6055 * 6057 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.6056 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global $post. 6058 6057 * @return string|false False on failure. Attachment caption on success. 6059 6058 */ 6060 function wp_get_attachment_caption( $post_id = 0 ) { 6061 $post_id = (int) $post_id; 6062 $post = get_post( $post_id ); 6063 if ( ! $post ) { 6059 function wp_get_attachment_caption( $attachment = null ) { 6060 6061 $post = get_post( $attachment ); 6062 6063 if ( ! $post || 'attachment' !== $post->post_type ) { 6064 6064 return false; 6065 6065 } 6066 6066 6067 if ( 'attachment' !== $post->post_type ) {6068 return false;6069 }6070 6071 6067 $caption = $post->post_excerpt; 6072 6068 6073 6069 /** … … 6076 6072 * @since 4.6.0 6077 6073 * 6078 6074 * @param string $caption Caption for the given attachment. 6079 * @param int $post_id Attachment ID. 6075 * @param int $attachment_id Attachment ID. 6076 * @param WP_Post $attachment Attachment WP_Post object. 6080 6077 */ 6081 return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );6078 return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID, $post ); 6082 6079 } 6083 6080 6084 6081 /** … … 6086 6083 * 6087 6084 * @since 2.1.0 6088 6085 * 6089 * @param int $post_id Optional. Attachment ID. Default 0.6086 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post. 6090 6087 * @return string|false False on failure. Thumbnail file path on success. 6091 6088 */ 6092 function wp_get_attachment_thumb_file( $post_id = 0 ) { 6093 $post_id = (int) $post_id; 6094 $post = get_post( $post_id ); 6095 if ( ! $post ) { 6089 function wp_get_attachment_thumb_file( $attachment = null ) { 6090 6091 $post = get_post( $attachment ); 6092 6093 if ( ! $post || 'attachment' != $post->post_type ) { 6096 6094 return false; 6097 6095 } 6098 6096 … … 6100 6098 if ( ! is_array( $imagedata ) ) { 6101 6099 return false; 6102 6100 } 6103 6101 6104 6102 $file = get_attached_file( $post->ID ); 6105 6103 6106 6104 if ( ! empty( $imagedata['thumb'] ) ) { 6107 6105 $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ); 6108 6106 if ( file_exists( $thumbfile ) ) { … … 6111 6109 * 6112 6110 * @since 2.1.0 6113 6111 * 6114 * @param string $thumbfile File path to the attachment thumbnail. 6115 * @param int $post_id Attachment ID. 6112 * @param string $thumbfile File path to the attachment thumbnail. 6113 * @param int $attachment_id Attachment ID. 6114 * @param WP_Post $attachment Attachment post object. 6116 6115 */ 6117 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );6116 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID, $post ); 6118 6117 } 6119 6118 } 6120 6119 return false; … … 6125 6124 * 6126 6125 * @since 2.1.0 6127 6126 * 6128 * @param int $post_id Optional. Attachment ID. Default 0.6127 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post. 6129 6128 * @return string|false False on failure. Thumbnail URL on success. 6130 6129 */ 6131 function wp_get_attachment_thumb_url( $post_id = 0 ) { 6132 $post_id = (int) $post_id; 6133 $post = get_post( $post_id ); 6134 if ( ! $post ) { 6130 function wp_get_attachment_thumb_url( $attachment = null ) { 6131 6132 $post = get_post( $attachment ); 6133 6134 if ( ! $post || 'attachment' != $post->post_type ) { 6135 6135 return false; 6136 6136 } 6137 6137 … … 6140 6140 return false; 6141 6141 } 6142 6142 6143 $sized = image_downsize( $post _id, 'thumbnail' );6143 $sized = image_downsize( $post->ID, 'thumbnail' ); 6144 6144 if ( $sized ) { 6145 6145 return $sized[0]; 6146 6146 } … … 6158 6158 * @since 2.1.0 6159 6159 * 6160 6160 * @param string $url URL for the attachment thumbnail. 6161 * @param int $post_id Attachment ID. 6161 * @param int $attachment_id Attachment ID. 6162 * @param WP_Post $attachment Attachment post object. 6162 6163 */ 6163 return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );6164 return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID, $post ); 6164 6165 } 6165 6166 6166 6167 /** … … 6173 6174 * @return bool True if one of the accepted types, false otherwise. 6174 6175 */ 6175 6176 function wp_attachment_is( $type, $post = null ) { 6177 6176 6178 $post = get_post( $post ); 6177 if ( ! $post ) { 6179 6180 if ( ! $post || 'attachment' != $post->post_type ) { 6178 6181 return false; 6179 6182 } 6180 6183 … … 7415 7418 * @param int $attachment_id Attachment ID. 7416 7419 */ 7417 7420 return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id ); 7418 } 7421 } 7422 No newline at end of file