<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12036] trunk: Post thumbnail removal functionality (
only allowed for replacement before).</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12036">12036</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2009-10-15 12:57:16 +0000 (Thu, 15 Oct 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Post thumbnail removal functionality (only allowed for replacement before). props scribu. see <a href="http://trac.wordpress.org/ticket/10928">#10928</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminadminajaxphp">trunk/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpadminjssetpostthumbnailhandlerdevjs">trunk/wp-admin/js/set-post-thumbnail-handler.dev.js</a></li>
<li><a href="#trunkwpadminjssetpostthumbnailhandlerjs">trunk/wp-admin/js/set-post-thumbnail-handler.js</a></li>
<li><a href="#trunkwpcontentthemesdefaultindexphp">trunk/wp-content/themes/default/index.php</a></li>
<li><a href="#trunkwpcontentthemesdefaultstylecss">trunk/wp-content/themes/default/style.css</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminadminajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/admin-ajax.php (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/admin-ajax.php        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-admin/admin-ajax.php        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -1395,6 +1395,12 @@
</span><span class="cx">         if ( !current_user_can( 'edit_post', $post_id ) )
</span><span class="cx">                 die( '-1' );
</span><span class="cx">         $thumbnail_id = intval( $_POST['thumbnail_id'] );
</span><ins>+
+        if ( $thumbnail_id == '-1' ) {
+                delete_post_meta( $post_id, '_thumbnail_id' );
+                die( _wp_post_thumbnail_html() );
+        }
+
</ins><span class="cx">         if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
</span><span class="cx">                 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
</span><span class="cx">                 if ( !empty( $thumbnail_html ) ) {
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-admin/includes/media.php        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -115,12 +115,17 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
</span><ins>+        $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>';
+
</ins><span class="cx">         if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
</span><span class="cx">                 $thumbnail_html = wp_get_attachment_image($thumbnail_id, array( 266, 266 ) );
</span><del>-                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>' );
</del><ins>+                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>';
+                }
</ins><span class="cx">         }
</span><del>-        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>' );
</del><ins>+
+        return apply_filters( 'admin_post_thumbnail_html', $content );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function post_thumbnail_meta_box() {
</span></span></pre></div>
<a id="trunkwpadminjssetpostthumbnailhandlerdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/set-post-thumbnail-handler.dev.js (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/set-post-thumbnail-handler.dev.js        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-admin/js/set-post-thumbnail-handler.dev.js        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -1,8 +1,22 @@
</span><span class="cx"> function WPSetThumbnailHTML(html){
</span><span class="cx">         jQuery('#postthumbnaildiv .inside').html(html);
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> function WPSetThumbnailID(id){
</span><span class="cx">         if ( jQuery('input[value=_thumbnail_id]').size() > 0 ) {
</span><span class="cx">                 jQuery('#meta\\[' + jQuery('input[value=_thumbnail_id]').attr('id').match(/[0-9]+/) + '\\]\\[value\\]' ).text(id);
</span><span class="cx">         }
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
+
+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);
+                }
+        }
+        );
+}
</ins></span></pre></div>
<a id="trunkwpadminjssetpostthumbnailhandlerjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/set-post-thumbnail-handler.js (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/set-post-thumbnail-handler.js        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-admin/js/set-post-thumbnail-handler.js        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -1 +1 @@
</span><del>-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)}};
</del><span class="cx">\ No newline at end of file
</span><ins>+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)}})};
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpcontentthemesdefaultindexphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/default/index.php (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/default/index.php        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-content/themes/default/index.php        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -17,6 +17,9 @@
</span><span class="cx">                                 <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
</span><span class="cx">
</span><span class="cx">                                 <div class="entry">
</span><ins>+                                        <?php if ( has_post_image() ) : ?>
+                                                <p class="post-thumbnail"><?php the_post_image( array( '150', '150') ) ?></p>
+                                        <?php endif; ?>
</ins><span class="cx">                                         <?php the_content('Read the rest of this entry &raquo;'); ?>
</span><span class="cx">                                 </div>
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpcontentthemesdefaultstylecss"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/default/style.css (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/default/style.css        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-content/themes/default/style.css        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -712,6 +712,10 @@
</span><span class="cx"> }
</span><span class="cx"> /* End captions */
</span><span class="cx">
</span><ins>+p.post-thumbnail {
+        float: left;
+        margin: 0 10px 10px 0;
+}
</ins><span class="cx">
</span><span class="cx"> /* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you.
</span><span class="cx">         It won't be a stylish marriage, I can't afford a carriage.
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (12035 => 12036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2009-10-15 12:31:48 UTC (rev 12035)
+++ trunk/wp-includes/script-loader.php        2009-10-15 12:57:16 UTC (rev 12036)
</span><span class="lines">@@ -383,7 +383,7 @@
</span><span class="cx">                         'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' )
</span><span class="cx">                 ) );
</span><span class="cx">
</span><del>-                $scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091014' );
</del><ins>+                $scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091015' );
</ins><span class="cx">                 $scripts->add_data( 'set-post-thumbnail-handler', 'group', 1 );
</span><span class="cx">         
</span><span class="cx">         }
</span></span></pre>
</div>
</div>
</body>
</html>