Ticket #12922: 12922.diff
File 12922.diff, 4.4 KB (added by , 9 years ago) |
---|
-
src/wp-admin/admin-ajax.php
63 63 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', 64 64 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', 65 65 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 66 'get-post-thumbnail-html', 66 67 ); 67 68 68 69 // Deprecated -
src/wp-admin/includes/ajax-actions.php
2146 2146 } 2147 2147 2148 2148 /** 2149 * Ajax handler for retrieving HTML for the featured image. 2150 * 2151 * @since 4.6.0 2152 */ 2153 function wp_ajax_get_post_thumbnail_html() { 2154 $post_ID = intval( $_POST['post_id'] ); 2155 if ( ! current_user_can( 'edit_post', $post_ID ) ) 2156 wp_die( -1 ); 2157 2158 $thumbnail_id = intval( $_POST['thumbnail_id'] ); 2159 2160 check_ajax_referer( "update-post_$post_ID" ); 2161 2162 if ( -1 === $thumbnail_id ) { 2163 $thumbnail_id = null; 2164 } 2165 2166 $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); 2167 wp_send_json_success( $return ); 2168 } 2169 2170 /** 2149 2171 * AJAX handler for setting the featured image for an attachment. 2150 2172 * 2151 2173 * @since 4.0.0 -
src/wp-admin/includes/post.php
217 217 _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) ); 218 218 } 219 219 220 if ( isset( $post_data['_thumbnail_id'] ) && post_type_supports( $ptype->name, 'thumbnail' ) ) { 221 $thumbnail_id = intval( $post_data['_thumbnail_id'] ); 222 if ( -1 === $thumbnail_id ) { 223 delete_post_thumbnail( $post_ID ); 224 } else { 225 set_post_thumbnail( $post_ID, $thumbnail_id ); 226 } 227 } 228 220 229 if ( isset($post_data['visibility']) ) { 221 230 switch ( $post_data['visibility'] ) { 222 231 case 'public' : … … 1421 1430 $thumbnail_html 1422 1431 ); 1423 1432 $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>'; 1424 $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';1433 $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>'; 1425 1434 } 1426 1435 } 1427 1436 1437 $content .= '<input type="hidden" name="_thumbnail_id" value="' . ( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />'; 1438 1428 1439 /** 1429 1440 * Filter the admin post thumbnail HTML markup to return. 1430 1441 * -
src/wp-includes/js/media-editor.js
649 649 650 650 settings.post.featuredImageId = id; 651 651 652 wp.media.post( ' set-post-thumbnail', {652 wp.media.post( 'get-post-thumbnail-html', { 653 653 json: true, 654 654 post_id: settings.post.id, 655 655 thumbnail_id: settings.post.featuredImageId, … … 659 659 }); 660 660 }, 661 661 /** 662 * Remove the featured image id, save the post thumbnail data and 663 * set the HTML in the post meta box to no featured image. 664 * 665 * @global wp.media.view.settings 666 * @global wp.media.post 667 */ 668 remove: function() { 669 var settings = wp.media.view.settings; 670 671 settings.post.featuredImageId = -1; 672 673 wp.media.post( 'get-post-thumbnail-html', { 674 json: true, 675 post_id: settings.post.id, 676 thumbnail_id: -1, 677 _wpnonce: settings.post.nonce 678 }).done( function( html ) { 679 if ( html == '0' ) { 680 window.alert( window.setPostThumbnailL10n.error ); 681 } 682 $( '.inside', '#postimagediv' ).html( html ); 683 }); 684 }, 685 /** 662 686 * The Featured Image workflow 663 687 * 664 688 * @global wp.media.controller.FeaturedImage … … 735 759 736 760 wp.media.featuredImage.frame().open(); 737 761 }).on( 'click', '#remove-post-thumbnail', function() { 738 wp.media.view.settings.post.featuredImageId = -1; 762 wp.media.featuredImage.remove(); 763 return false; 739 764 }); 740 765 } 741 766 };