mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-10 23:54:33 +00:00
Media:
- Deprecate `wp_get_attachment_thumb_file()`. - Make `wp_get_attachment_thumb_url()` an alias of `wp_get_attachment_image_url()`. This fixes it to return the proper thumbnail URL and fall back to returning the URL to `image_meta['thumb']` if only that exists. Props: markhowellsmead, mukesh27, csesumonpro, SergeyBiryukov, mikeschroder, killua99, joemcgill, mashukushibiki, mfgmicha, swissspidy, romulodl, nacin, JoshuaAbenazer, wonderboymusic, lonnylot, azaozz. git-svn-id: https://develop.svn.wordpress.org/trunk@53685 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -6701,88 +6701,35 @@ function wp_get_attachment_caption( $post_id = 0 ) {
|
||||
return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves thumbnail for an attachment.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
|
||||
* @return string|false Thumbnail file path on success, false on failure.
|
||||
*/
|
||||
function wp_get_attachment_thumb_file( $post_id = 0 ) {
|
||||
$post_id = (int) $post_id;
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$imagedata = wp_get_attachment_metadata( $post->ID );
|
||||
if ( ! is_array( $imagedata ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = get_attached_file( $post->ID );
|
||||
|
||||
if ( ! empty( $imagedata['thumb'] ) ) {
|
||||
$thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
|
||||
if ( file_exists( $thumbfile ) ) {
|
||||
/**
|
||||
* Filters the attachment thumbnail file path.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $thumbfile File path to the attachment thumbnail.
|
||||
* @param int $post_id Attachment ID.
|
||||
*/
|
||||
return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves URL for an attachment thumbnail.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 6.1.0 Changed to use wp_get_attachment_image_url().
|
||||
*
|
||||
* @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
|
||||
* @return string|false Thumbnail URL on success, false on failure.
|
||||
*/
|
||||
function wp_get_attachment_thumb_url( $post_id = 0 ) {
|
||||
$post_id = (int) $post_id;
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( ! $post ) {
|
||||
// This uses image_downsize() which also looks for the (very) old format $image_meta['thumb']
|
||||
// when the newer format $image_meta['sizes']['thumbnail'] doesn't exist.
|
||||
$thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' );
|
||||
|
||||
if ( empty( $thumbnail_url ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = wp_get_attachment_url( $post->ID );
|
||||
if ( ! $url ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sized = image_downsize( $post_id, 'thumbnail' );
|
||||
if ( $sized ) {
|
||||
return $sized[0];
|
||||
}
|
||||
|
||||
$thumb = wp_get_attachment_thumb_file( $post->ID );
|
||||
if ( ! $thumb ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url );
|
||||
|
||||
/**
|
||||
* Filters the attachment thumbnail URL.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $url URL for the attachment thumbnail.
|
||||
* @param int $post_id Attachment ID.
|
||||
* @param string $thumbnail_url URL for the attachment thumbnail.
|
||||
* @param int $post_id Attachment ID.
|
||||
*/
|
||||
return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
|
||||
return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user