From 4d98b99cc35e5ca46befed4d85cec83fa4285322 Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Sun, 11 Oct 2015 16:53:35 +0000 Subject: [PATCH] Media: Introduce the `admin_post_thumbnail_size` filter, which enables manipulation of the image size used to display the post thumbnail in the 'Featured Image' meta box. This filter has no effect on the image size used to display post thumbnails on the front-end. Props dboulet, DrewAPicture. Fixes #28512. git-svn-id: https://develop.svn.wordpress.org/trunk@35022 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/post.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 83756e695a..f5f6234994 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1396,10 +1396,31 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { if ( $thumbnail_id && get_post( $thumbnail_id ) ) { $old_content_width = $content_width; $content_width = 266; - if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) ) - $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) ); - else - $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' ); + + $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( $content_width, $content_width ); + + /** + * Filter the size used to display the post thumbnail image in the 'Featured Image' meta box. + * + * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' + * image size is registered, which differs from the 'thumbnail' image size + * managed via the Settings > Media screen. See the `$size` parameter description + * for more information on default values. + * + * @since 4.4.0 + * + * @param string|array $size Post thumbnail image size to display in the meta box. Accepts + * any valid image size, or an array of height and width values. + * If the 'post-thumbnail' size is set, default is 'post-thumbnail'. + * Otherwise, default is an array with `$content_width` as the + * height and width values. + * @param int $thumbnail_id Post thumbnail attachment ID. + * @param WP_Post $post The post object associated with the thumbnail. + */ + $size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post ); + + $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size ); + if ( !empty( $thumbnail_html ) ) { $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID ); $content = sprintf( $set_thumbnail_link,