WordPress.org

Make WordPress Core

Changeset 12036


Ignore:
Timestamp:
10/15/09 12:57:16 (5 years ago)
Author:
markjaquith
Message:

Post thumbnail removal functionality (only allowed for replacement before). props scribu. see #10928

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r12023 r12036  
    13961396        die( '-1' ); 
    13971397    $thumbnail_id = intval( $_POST['thumbnail_id'] ); 
     1398 
     1399    if ( $thumbnail_id == '-1' ) { 
     1400        delete_post_meta( $post_id, '_thumbnail_id' ); 
     1401        die( _wp_post_thumbnail_html() ); 
     1402    } 
     1403 
    13981404    if ( $thumbnail_id && get_post( $thumbnail_id ) ) { 
    13991405        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); 
  • trunk/wp-admin/includes/media.php

    r12018 r12036  
    116116 
    117117function _wp_post_thumbnail_html( $thumbnail_id = NULL ) { 
     118    $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>'; 
     119 
    118120    if ( $thumbnail_id && get_post( $thumbnail_id ) ) { 
    119121        $thumbnail_html = wp_get_attachment_image($thumbnail_id, array( 266, 266 ) ); 
    120         if ( !empty( $thumbnail_html ) ) 
    121             return apply_filters( 'admin_post_thumbnail_html', '<a href="#" id="cws-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>' ); 
    122     } 
    123     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>' ); 
     122        if ( !empty( $thumbnail_html ) ) { 
     123            $content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>'; 
     124            $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>'; 
     125        } 
     126    } 
     127 
     128    return apply_filters( 'admin_post_thumbnail_html', $content ); 
    124129} 
    125130 
  • trunk/wp-admin/js/set-post-thumbnail-handler.dev.js

    r12031 r12036  
    22    jQuery('#postthumbnaildiv .inside').html(html); 
    33} 
     4 
    45function WPSetThumbnailID(id){ 
    56    if ( jQuery('input[value=_thumbnail_id]').size() > 0 ) { 
     
    78    } 
    89} 
     10 
     11function WPRemoveThumbnail(){ 
     12    jQuery.post(ajaxurl, { 
     13        action:"set-post-thumbnail", post_id: jQuery('#post_ID').val(), thumbnail_id: -1, cookie: encodeURIComponent(document.cookie) 
     14    }, function(str){ 
     15        if ( str == '0' ) { 
     16            alert( setPostThumbnailL10n.error ); 
     17        } else { 
     18            WPSetThumbnailHTML(str); 
     19        } 
     20    } 
     21    ); 
     22} 
  • trunk/wp-admin/js/set-post-thumbnail-handler.js

    r12031 r12036  
    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)}}; 
     1function 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)}})}; 
  • trunk/wp-content/themes/default/index.php

    r10945 r12036  
    1818 
    1919                <div class="entry"> 
     20                    <?php if ( has_post_image() ) : ?> 
     21                        <p class="post-thumbnail"><?php the_post_image( array( '150', '150') ) ?></p> 
     22                    <?php endif; ?> 
    2023                    <?php the_content('Read the rest of this entry &raquo;'); ?> 
    2124                </div> 
  • trunk/wp-content/themes/default/style.css

    r11413 r12036  
    713713/* End captions */ 
    714714 
     715p.post-thumbnail { 
     716    float: left; 
     717    margin: 0 10px 10px 0; 
     718} 
    715719 
    716720/* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you. 
  • trunk/wp-includes/script-loader.php

    r12031 r12036  
    384384        ) ); 
    385385 
    386         $scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091014' ); 
     386        $scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091015' ); 
    387387        $scripts->add_data( 'set-post-thumbnail-handler', 'group', 1 ); 
    388388     
Note: See TracChangeset for help on using the changeset viewer.