| | 4910 | * Retrieve thumbnail file path for an attachment. |
| | 4911 | * |
| | 4912 | * @since 4.4.0 |
| | 4913 | * |
| | 4914 | * @param int|null|WP_Post $attachment ID or WP_Post object. Default null. |
| | 4915 | * @param string $size Optional. Attachment size. Default thumbnail. |
| | 4916 | * |
| | 4917 | * @return false|string False on failure. Thumbnail file path on success. |
| | 4918 | */ |
| | 4919 | function wp_get_attachment_file( $attachment = null, $size = 'thumbnail' ) { |
| | 4920 | $attachment = get_post( $attachment ); |
| | 4921 | if ( ! $attachment ) { |
| | 4922 | return false; |
| | 4923 | } |
| | 4924 | |
| | 4925 | if ( 'thumb' === $size ) { |
| | 4926 | return wp_get_attachment_thumb_file( $attachment->ID ); |
| | 4927 | } |
| | 4928 | |
| | 4929 | $image_data = wp_get_attachment_metadata( $attachment->ID ); |
| | 4930 | if ( ! is_array( $image_data ) ) { |
| | 4931 | return false; |
| | 4932 | } |
| | 4933 | |
| | 4934 | $file = get_attached_file( $attachment->ID ); |
| | 4935 | |
| | 4936 | if ( ! $file || ! isset( $image_data['sizes'][ $size ] ) || empty( $image_data['sizes'][ $size ] ) ) { |
| | 4937 | return false; |
| | 4938 | } |
| | 4939 | |
| | 4940 | $thumbnail_file = str_replace( basename( $file ), $image_data['sizes'][ $size ]['file'], $file ); |
| | 4941 | |
| | 4942 | if ( empty( $thumbnail_file ) || ! file_exists( $thumbnail_file ) ) { |
| | 4943 | return false; |
| | 4944 | } |
| | 4945 | |
| | 4946 | /** |
| | 4947 | * Filter the attachment thumbnail file path. |
| | 4948 | * |
| | 4949 | * @since 4.4.0 |
| | 4950 | * |
| | 4951 | * @param string $thumbnail_file File path to the attachment thumbnail. |
| | 4952 | * @param WP_Post $post Attachment object. |
| | 4953 | * @param string $size Attachment size. |
| | 4954 | */ |
| | 4955 | return apply_filters( 'wp_get_attachment_thumbnail_file', $thumbnail_file, $attachment, $size ); |
| | 4956 | } |
| | 4957 | |
| | 4958 | /** |