Post/Page Image was too generic a name. Post/Page Thumbnail is more clear, even if you can create very large thumbnail images if you so choose.

git-svn-id: http://svn.automattic.com/wordpress/trunk@12351 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2009-12-10 06:14:36 +00:00
parent 1c90385918
commit bf264bb66d
14 changed files with 114 additions and 117 deletions

View File

@ -1410,14 +1410,14 @@ case 'set-post-thumbnail':
if ( $thumbnail_id == '-1' ) { if ( $thumbnail_id == '-1' ) {
delete_post_meta( $post_id, '_thumbnail_id' ); delete_post_meta( $post_id, '_thumbnail_id' );
die( _wp_post_image_html() ); die( _wp_post_thumbnail_html() );
} }
if ( $thumbnail_id && get_post( $thumbnail_id ) ) { if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
if ( !empty( $thumbnail_html ) ) { if ( !empty( $thumbnail_html ) ) {
update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id ); update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id );
die( _wp_post_image_html( $thumbnail_id ) ); die( _wp_post_thumbnail_html( $thumbnail_id ) );
} }
} }
die( '0' ); die( '0' );

View File

@ -98,8 +98,8 @@ foreach ( get_object_taxonomies('post') as $tax_name ) {
} }
add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'side', 'core'); add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'side', 'core');
if ( current_theme_supports( 'post-images', 'post' ) ) if ( current_theme_supports( 'post-thumbnails', 'post' ) )
add_meta_box('postimagediv', __('Post Image'), 'post_image_meta_box', 'post', 'side', 'low'); add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', 'post', 'side', 'low');
add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'normal', 'core'); add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'normal', 'core');
add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 'post', 'normal', 'core'); add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 'post', 'normal', 'core');
add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', 'normal', 'core'); add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', 'normal', 'core');

View File

@ -80,8 +80,8 @@ add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', 'pag
add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'page', 'normal', 'core'); add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'page', 'normal', 'core');
add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'page', 'normal', 'core'); add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'page', 'normal', 'core');
add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', 'page', 'normal', 'core'); add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', 'page', 'normal', 'core');
if ( current_theme_supports( 'post-images', 'page' ) ) if ( current_theme_supports( 'post-thumbnails', 'page' ) )
add_meta_box('postimagediv', __('Page Image'), 'post_image_meta_box', 'page', 'side', 'low'); add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', 'page', 'side', 'low');
$authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM $authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM
if ( $post->post_author && !in_array($post->post_author, $authors) ) if ( $post->post_author && !in_array($post->post_author, $authors) )

View File

@ -75,7 +75,7 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_
} }
/** /**
* Generate post image attachment meta data. * Generate post thumbnail attachment meta data.
* *
* @since 2.1.0 * @since 2.1.0
* *

View File

@ -1239,8 +1239,8 @@ function get_media_item( $attachment_id, $args = null ) {
} }
$thumbnail = ''; $thumbnail = '';
if ( 'image' == $type && isset($_GET['post_id']) && current_theme_supports( 'post-images', get_post_type($_GET['post_id']) ) && get_post_image_id($_GET['post_id']) != $attachment_id ) if ( 'image' == $type && isset($_GET['post_id']) && current_theme_supports( 'post-thumbnails', get_post_type($_GET['post_id']) ) && get_post_thumbnail_id($_GET['post_id']) != $attachment_id )
$thumbnail = "<a class='wp-post-thumbnail' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\");return false;'>" . esc_html__( "Use as post image" ) . "</a>"; $thumbnail = "<a class='wp-post-thumbnail' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\");return false;'>" . esc_html__( "Use as thumbnail" ) . "</a>";
if ( ( $send || $thumbnail || $delete ) && !isset($form_fields['buttons']) ) if ( ( $send || $thumbnail || $delete ) && !isset($form_fields['buttons']) )
$form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n"); $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n");

View File

@ -815,12 +815,12 @@ function link_advanced_meta_box($link) {
} }
/** /**
* Display post image meta box. * Display post thumbnail meta box.
* *
* @since 2.9.0 * @since 2.9.0
*/ */
function post_image_meta_box() { function post_thumbnail_meta_box() {
global $post; global $post;
$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
echo _wp_post_image_html( $thumbnail_id ); echo _wp_post_thumbnail_html( $thumbnail_id );
} }

View File

@ -1062,32 +1062,32 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
} }
/** /**
* Output HTML for the post image meta-box. * Output HTML for the post thumbnail meta-box.
* *
* @since 2.9.0 * @since 2.9.0
* *
* @param int $thumbnail_id ID of the attachment used for thumbnail * @param int $thumbnail_id ID of the attachment used for thumbnail
* @return string html * @return string html
*/ */
function _wp_post_image_html( $thumbnail_id = NULL ) { function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
global $content_width, $_wp_additional_image_sizes; global $content_width, $_wp_additional_image_sizes;
$content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set image' ) . '</a></p>'; $content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a></p>';
if ( $thumbnail_id && get_post( $thumbnail_id ) ) { if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
$old_content_width = $content_width; $old_content_width = $content_width;
$content_width = 266; $content_width = 266;
if ( !isset( $_wp_additional_image_sizes['post-image'] ) ) if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) )
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) ); $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) );
else else
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-image' ); $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
if ( !empty( $thumbnail_html ) ) { if ( !empty( $thumbnail_html ) ) {
$content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>'; $content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove image' ) . '</a></p>'; $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>';
} }
$content_width = $old_content_width; $content_width = $old_content_width;
} }
return apply_filters( 'admin_post_image_html', $content ); return apply_filters( 'admin_post_thumbnail_html', $content );
} }
/** /**

View File

@ -213,9 +213,9 @@ add_action( 'transition_post_status', '_transition_post_status', 5, 3 );
add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' );
add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
// Post Image CSS class filtering // Post Thumbnail CSS class filtering
add_action( 'begin_fetch_post_image_html', '_wp_post_image_class_filter_add' ); add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add' );
add_action( 'end_fetch_post_image_html', '_wp_post_image_class_filter_remove' ); add_action( 'end_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_remove' );
// Redirect Old Slugs // Redirect Old Slugs
add_action( 'template_redirect', 'wp_old_slug_redirect' ); add_action( 'template_redirect', 'wp_old_slug_redirect' );

View File

@ -183,10 +183,10 @@ function add_image_size( $name, $width = 0, $height = 0, $crop = FALSE ) {
} }
/** /**
* Registers an image size for the post image * Registers an image size for the post thumbnail
*/ */
function set_post_image_size( $width = 0, $height = 0, $crop = FALSE ) { function set_post_thumbnail_size( $width = 0, $height = 0, $crop = FALSE ) {
add_image_size( 'post-image', $width, $height, $crop ); add_image_size( 'post-thumbnail', $width, $height, $crop );
} }
/** /**
@ -578,38 +578,38 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
} }
/** /**
* Adds a 'wp-post-image' class to post image thumbnails * Adds a 'wp-post-image' class to post thumbnail thumbnails
* Uses the begin_fetch_post_image_html and end_fetch_post_image_html action hooks to * Uses the begin_fetch_post_thumbnail_html and end_fetch_post_thumbnail_html action hooks to
* dynamically add/remove itself so as to only filter post image thumbnails * dynamically add/remove itself so as to only filter post thumbnail thumbnails
* *
* @author Mark Jaquith * @author Mark Jaquith
* @since 2.9.0 * @since 2.9.0
* @param array $attr Attributes including src, class, alt, title * @param array $attr Attributes including src, class, alt, title
* @return array * @return array
*/ */
function _wp_post_image_class_filter( $attr ) { function _wp_post_thumbnail_class_filter( $attr ) {
$attr['class'] .= ' wp-post-image'; $attr['class'] .= ' wp-post-image';
return $attr; return $attr;
} }
/** /**
* Adds _wp_post_image_class_filter to the wp_get_attachment_image_attributes filter * Adds _wp_post_thumbnail_class_filter to the wp_get_attachment_image_attributes filter
* *
* @author Mark Jaquith * @author Mark Jaquith
* @since 2.9.0 * @since 2.9.0
*/ */
function _wp_post_image_class_filter_add( $attr ) { function _wp_post_thumbnail_class_filter_add( $attr ) {
add_filter( 'wp_get_attachment_image_attributes', '_wp_post_image_class_filter' ); add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
} }
/** /**
* Removes _wp_post_image_class_filter from the wp_get_attachment_image_attributes filter * Removes _wp_post_thumbnail_class_filter from the wp_get_attachment_image_attributes filter
* *
* @author Mark Jaquith * @author Mark Jaquith
* @since 2.9.0 * @since 2.9.0
*/ */
function _wp_post_image_class_filter_remove( $attr ) { function _wp_post_thumbnail_class_filter_remove( $attr ) {
remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_image_class_filter' ); remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
} }
add_shortcode('wp_caption', 'img_caption_shortcode'); add_shortcode('wp_caption', 'img_caption_shortcode');

View File

@ -1,76 +0,0 @@
<?php
/**
* WordPress Post Image Template Functions.
*
* Support for post images
* Themes function.php must call add_theme_support( 'post-images' ) to use these.
*
* @package WordPress
* @subpackage Template
*/
/**
* Check if post has an image attached.
*
* @since 2.9.0
*
* @param int $post_id Optional. Post ID.
* @return bool Whether post has an image attached (true) or not (false).
*/
function has_post_image( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return !! get_post_image_id( $post_id );
}
/**
* Retrieve Post Image ID.
*
* @since 2.9.0
*
* @param int $post_id Optional. Post ID.
* @return int
*/
function get_post_image_id( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
/**
* Display Post Image.
*
* @since 2.9.0
*
* @param int $size Optional. Image size. Defaults to 'post-image', which theme sets using set_post_image_size( $width, $height, $crop_flag );.
* @param string|array $attr Optional. Query string or array of attributes.
*/
function the_post_image( $size = 'post-image', $attr = '' ) {
echo get_the_post_image( NULL, $size, $attr );
}
/**
* Retrieve Post Image.
*
* @since 2.9.0
*
* @param int $post_id Optional. Post ID.
* @param string $size Optional. Image size. Defaults to 'thumbnail'.
* @param string|array $attr Optional. Query string or array of attributes.
*/
function get_the_post_image( $post_id = NULL, $size = 'post-image', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_image_id = get_post_image_id( $post_id );
$size = apply_filters( 'post_image_size', $size );
if ( $post_image_id ) {
do_action( 'begin_fetch_post_image_html', $post_id, $post_image_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
$html = wp_get_attachment_image( $post_image_id, $size, false, $attr );
do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size );
} else {
$html = '';
}
return apply_filters( 'post_image_html', $html, $post_id, $post_image_id, $size, $attr );
}
?>

View File

@ -0,0 +1,76 @@
<?php
/**
* WordPress Post Thumbnail Template Functions.
*
* Support for post thumbnails
* Themes function.php must call add_theme_support( 'post-thumbnails' ) to use these.
*
* @package WordPress
* @subpackage Template
*/
/**
* Check if post has an image attached.
*
* @since 2.9.0
*
* @param int $post_id Optional. Post ID.
* @return bool Whether post has an image attached (true) or not (false).
*/
function has_post_thumbnail( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $popost-thumbnailst_id;
return !! get_post_thumbnail_id( $post_id );
}
/**
* Retrieve Post Thumbnail ID.
*
* @since 2.9.0
*
* @param int $post_id Optional. Post ID.
* @return int
*/
function get_post_thumbnail_id( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
/**
* Display Post Thumbnail.
*
* @since 2.9.0
*
* @param int $size Optional. Image size. Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );.
* @param string|array $attr Optional. Query string or array of attributes.
*/
function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) {
echo get_the_post_thumbnail( NULL, $size, $attr );
}
/**
* Retrieve Post Thumbnail.
*
* @since 2.9.0
*
* @param int $post_id Optional. Post ID.
* @param string $size Optional. Image size. Defaults to 'thumbnail'.
* @param string|array $attr Optional. Query string or array of attributes.
*/
function get_the_post_thumbnail( $post_id = NULL, $size = 'post-thumbnail', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$size = apply_filters( 'post_thumbnail_size', $size );
if ( $post_thumbnail_id ) {
do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
} else {
$html = '';
}
return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
}
?>

View File

@ -385,7 +385,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), '20091021' ); $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), '20091021' );
$scripts->add_data( 'set-post-thumbnail', 'group', 1 ); $scripts->add_data( 'set-post-thumbnail', 'group', 1 );
$scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array( $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
'setThumbnail' => __( 'Use as post image' ), 'setThumbnail' => __( 'Use as thumbnail' ),
'saving' => __( 'Saving...' ), 'saving' => __( 'Saving...' ),
'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ) 'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' )
) ); ) );

View File

@ -1321,9 +1321,6 @@ function add_custom_image_header($header_callback, $admin_header_callback) {
function add_theme_support( $feature ) { function add_theme_support( $feature ) {
global $_wp_theme_features; global $_wp_theme_features;
if ( 'post-thumbnails' == $feature ) // This was changed during 2.9 beta. I'll be nice and not break things.
$feature = 'post-images';
if ( func_num_args() == 1 ) if ( func_num_args() == 1 )
$_wp_theme_features[$feature] = true; $_wp_theme_features[$feature] = true;
else else
@ -1353,7 +1350,7 @@ function current_theme_supports( $feature ) {
// @todo Allow pluggable arg checking // @todo Allow pluggable arg checking
switch ( $feature ) { switch ( $feature ) {
case 'post-images': case 'post-thumbnails':
// post-thumbnails can be registered for only certain content/post types by passing // post-thumbnails can be registered for only certain content/post types by passing
// an array of types to add_theme_support(). If no array was passed, then // an array of types to add_theme_support(). If no array was passed, then
// any type is accepted // any type is accepted

View File

@ -692,7 +692,7 @@ if ( file_exists(TEMPLATEPATH . '/functions.php') )
include(TEMPLATEPATH . '/functions.php'); include(TEMPLATEPATH . '/functions.php');
// Load in support for template functions which the theme supports // Load in support for template functions which the theme supports
require_if_theme_supports( 'post-images', ABSPATH . WPINC . '/post-image-template.php' ); require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-thumbnail-template.php' );
/** /**
* Runs just before PHP shuts down execution. * Runs just before PHP shuts down execution.