Changeset 53685 for trunk/src/wp-includes/post.php
- Timestamp:
- 07/07/2022 11:30:21 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r53559 r53685 6703 6703 6704 6704 /** 6705 * Retrieves thumbnail for an attachment.6705 * Retrieves URL for an attachment thumbnail. 6706 6706 * 6707 6707 * @since 2.1.0 6708 * 6709 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. 6710 * @return string|false Thumbnail file path on success, false on failure. 6711 */ 6712 function wp_get_attachment_thumb_file( $post_id = 0 ) { 6713 $post_id = (int) $post_id; 6714 $post = get_post( $post_id ); 6715 6716 if ( ! $post ) { 6717 return false; 6718 } 6719 6720 $imagedata = wp_get_attachment_metadata( $post->ID ); 6721 if ( ! is_array( $imagedata ) ) { 6722 return false; 6723 } 6724 6725 $file = get_attached_file( $post->ID ); 6726 6727 if ( ! empty( $imagedata['thumb'] ) ) { 6728 $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ); 6729 if ( file_exists( $thumbfile ) ) { 6730 /** 6731 * Filters the attachment thumbnail file path. 6732 * 6733 * @since 2.1.0 6734 * 6735 * @param string $thumbfile File path to the attachment thumbnail. 6736 * @param int $post_id Attachment ID. 6737 */ 6738 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); 6739 } 6740 } 6741 return false; 6742 } 6743 6744 /** 6745 * Retrieves URL for an attachment thumbnail. 6746 * 6747 * @since 2.1.0 6708 * @since 6.1.0 Changed to use wp_get_attachment_image_url(). 6748 6709 * 6749 6710 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. … … 6752 6713 function wp_get_attachment_thumb_url( $post_id = 0 ) { 6753 6714 $post_id = (int) $post_id; 6754 $post = get_post( $post_id ); 6755 6756 if ( ! $post ) { 6715 6716 // This uses image_downsize() which also looks for the (very) old format $image_meta['thumb'] 6717 // when the newer format $image_meta['sizes']['thumbnail'] doesn't exist. 6718 $thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' ); 6719 6720 if ( empty( $thumbnail_url ) ) { 6757 6721 return false; 6758 6722 } 6759 6760 $url = wp_get_attachment_url( $post->ID );6761 if ( ! $url ) {6762 return false;6763 }6764 6765 $sized = image_downsize( $post_id, 'thumbnail' );6766 if ( $sized ) {6767 return $sized[0];6768 }6769 6770 $thumb = wp_get_attachment_thumb_file( $post->ID );6771 if ( ! $thumb ) {6772 return false;6773 }6774 6775 $url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url );6776 6723 6777 6724 /** … … 6780 6727 * @since 2.1.0 6781 6728 * 6782 * @param string $ urlURL for the attachment thumbnail.6783 * @param int $post_id Attachment ID.6729 * @param string $thumbnail_url URL for the attachment thumbnail. 6730 * @param int $post_id Attachment ID. 6784 6731 */ 6785 return apply_filters( 'wp_get_attachment_thumb_url', $ url, $post->ID);6732 return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id ); 6786 6733 } 6787 6734
Note: See TracChangeset
for help on using the changeset viewer.