Allow registering post image support per post type. fixes #11364

git-svn-id: http://svn.automattic.com/wordpress/trunk@12350 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-12-09 15:39:20 +00:00
parent cf60d7c87a
commit 1c90385918
4 changed files with 36 additions and 5 deletions

View File

@ -98,7 +98,7 @@ foreach ( get_object_taxonomies('post') as $tax_name ) {
}
add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'side', 'core');
if ( current_theme_supports( 'post-images' ) )
if ( current_theme_supports( 'post-images', 'post' ) )
add_meta_box('postimagediv', __('Post Image'), 'post_image_meta_box', 'post', 'side', 'low');
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');

View File

@ -80,7 +80,7 @@ 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('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'page', 'normal', 'core');
add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', 'page', 'normal', 'core');
if ( current_theme_supports( 'post-images' ) )
if ( current_theme_supports( 'post-images', 'page' ) )
add_meta_box('postimagediv', __('Page Image'), 'post_image_meta_box', 'page', 'side', 'low');
$authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM

View File

@ -1239,7 +1239,7 @@ function get_media_item( $attachment_id, $args = null ) {
}
$thumbnail = '';
if ( 'image' == $type && current_theme_supports( 'post-images' ) && get_post_image_id($_GET['post_id']) != $attachment_id )
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 )
$thumbnail = "<a class='wp-post-thumbnail' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\");return false;'>" . esc_html__( "Use as post image" ) . "</a>";
if ( ( $send || $thumbnail || $delete ) && !isset($form_fields['buttons']) )

View File

@ -1320,9 +1320,14 @@ function add_custom_image_header($header_callback, $admin_header_callback) {
*/
function add_theme_support( $feature ) {
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';
$_wp_theme_features[$feature] = true;
if ( func_num_args() == 1 )
$_wp_theme_features[$feature] = true;
else
$_wp_theme_features[$feature] = array_slice( func_get_args(), 1 );
}
/**
@ -1336,7 +1341,33 @@ function add_theme_support( $feature ) {
function current_theme_supports( $feature ) {
global $_wp_theme_features;
return ( isset( $_wp_theme_features[$feature] ) && $_wp_theme_features[$feature] );
if ( !isset( $_wp_theme_features[$feature] ) )
return false;
// If no args passed then no extra checks need be performed
if ( func_num_args() <= 1 )
return true;
$args = array_slice( func_get_args(), 1 );
// @todo Allow pluggable arg checking
switch ( $feature ) {
case 'post-images':
// 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
// any type is accepted
if ( true === $_wp_theme_features[$feature] ) // Registered for all types
return true;
$content_type = $args[0];
if ( in_array($content_type, $_wp_theme_features[$feature][0]) )
return true;
else
return false;
break;
}
return true;
}
/**