Post thumbnail removal functionality (only allowed for replacement before). props scribu. see #10928
git-svn-id: https://develop.svn.wordpress.org/trunk@12036 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
45b4ea5807
commit
0818d29d6e
|
@ -1395,6 +1395,12 @@ case 'set-post-thumbnail':
|
|||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
die( '-1' );
|
||||
$thumbnail_id = intval( $_POST['thumbnail_id'] );
|
||||
|
||||
if ( $thumbnail_id == '-1' ) {
|
||||
delete_post_meta( $post_id, '_thumbnail_id' );
|
||||
die( _wp_post_thumbnail_html() );
|
||||
}
|
||||
|
||||
if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
|
||||
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
|
||||
if ( !empty( $thumbnail_html ) ) {
|
||||
|
|
|
@ -115,12 +115,17 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal
|
|||
}
|
||||
|
||||
function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
|
||||
$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 ) ) {
|
||||
$thumbnail_html = wp_get_attachment_image($thumbnail_id, array( 266, 266 ) );
|
||||
if ( !empty( $thumbnail_html ) )
|
||||
return apply_filters( 'admin_post_thumbnail_html', '<a href="#" id="cws-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>' );
|
||||
if ( !empty( $thumbnail_html ) ) {
|
||||
$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 thumbnail' ) . '</a></p>';
|
||||
}
|
||||
return apply_filters( 'admin_post_thumbnail_html', '<a href="#" id="cws-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a>' );
|
||||
}
|
||||
|
||||
return apply_filters( 'admin_post_thumbnail_html', $content );
|
||||
}
|
||||
|
||||
function post_thumbnail_meta_box() {
|
||||
|
|
|
@ -1,8 +1,22 @@
|
|||
function WPSetThumbnailHTML(html){
|
||||
jQuery('#postthumbnaildiv .inside').html(html);
|
||||
}
|
||||
|
||||
function WPSetThumbnailID(id){
|
||||
if ( jQuery('input[value=_thumbnail_id]').size() > 0 ) {
|
||||
jQuery('#meta\\[' + jQuery('input[value=_thumbnail_id]').attr('id').match(/[0-9]+/) + '\\]\\[value\\]' ).text(id);
|
||||
}
|
||||
}
|
||||
|
||||
function WPRemoveThumbnail(){
|
||||
jQuery.post(ajaxurl, {
|
||||
action:"set-post-thumbnail", post_id: jQuery('#post_ID').val(), thumbnail_id: -1, cookie: encodeURIComponent(document.cookie)
|
||||
}, function(str){
|
||||
if ( str == '0' ) {
|
||||
alert( setPostThumbnailL10n.error );
|
||||
} else {
|
||||
WPSetThumbnailHTML(str);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
function WPSetThumbnailHTML(html){jQuery("#postthumbnaildiv .inside").html(html)}function WPSetThumbnailID(id){if(jQuery("input[value=_thumbnail_id]").size()>0){jQuery("#meta\\["+jQuery("input[value=_thumbnail_id]").attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(id)}};
|
||||
function WPSetThumbnailHTML(html){jQuery("#postthumbnaildiv .inside").html(html)}function WPSetThumbnailID(id){if(jQuery("input[value=_thumbnail_id]").size()>0){jQuery("#meta\\["+jQuery("input[value=_thumbnail_id]").attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(id)}}function WPRemoveThumbnail(){jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:jQuery("#post_ID").val(),thumbnail_id:-1,cookie:encodeURIComponent(document.cookie)},function(str){if(str=="0"){alert(setPostThumbnailL10n.error)}else{WPSetThumbnailHTML(str)}})};
|
|
@ -17,6 +17,9 @@ get_header(); ?>
|
|||
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
|
||||
|
||||
<div class="entry">
|
||||
<?php if ( has_post_image() ) : ?>
|
||||
<p class="post-thumbnail"><?php the_post_image( array( '150', '150') ) ?></p>
|
||||
<?php endif; ?>
|
||||
<?php the_content('Read the rest of this entry »'); ?>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -712,6 +712,10 @@ div.aligncenter {
|
|||
}
|
||||
/* End captions */
|
||||
|
||||
p.post-thumbnail {
|
||||
float: left;
|
||||
margin: 0 10px 10px 0;
|
||||
}
|
||||
|
||||
/* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you.
|
||||
It won't be a stylish marriage, I can't afford a carriage.
|
||||
|
|
|
@ -383,7 +383,7 @@ function wp_default_scripts( &$scripts ) {
|
|||
'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' )
|
||||
) );
|
||||
|
||||
$scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091014' );
|
||||
$scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091015' );
|
||||
$scripts->add_data( 'set-post-thumbnail-handler', 'group', 1 );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue