Ticket #12922: 12922.2.diff
File 12922.2.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="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />'; 1438 1428 1439 /** 1429 1440 * Filters the admin post thumbnail HTML markup to return. 1430 1441 * -
src/wp-includes/js/media-editor.js
640 640 * set the HTML in the post meta box to the new featured image. 641 641 * 642 642 * @global wp.media.view.settings 643 * @global wp.media.post644 643 * 645 644 * @param {number} id The post ID of the featured image, or -1 to unset it. 646 645 */ … … 649 648 650 649 settings.post.featuredImageId = id; 651 650 652 wp.media.post( ' set-post-thumbnail', {651 wp.media.post( 'get-post-thumbnail-html', { 653 652 json: true, 654 653 post_id: settings.post.id, 655 654 thumbnail_id: settings.post.featuredImageId, 656 655 _wpnonce: settings.post.nonce 657 656 }).done( function( html ) { 657 if ( html == '0' ) { 658 window.alert( window.setPostThumbnailL10n.error ); 659 return; 660 } 658 661 $( '.inside', '#postimagediv' ).html( html ); 659 662 }); 660 663 }, 661 664 /** 665 * Remove the featured image id, save the post thumbnail data and 666 * set the HTML in the post meta box to no featured image. 667 */ 668 remove: function() { 669 wp.media.featuredImage.set( -1 ); 670 }, 671 /** 662 672 * The Featured Image workflow 663 673 * 664 674 * @global wp.media.controller.FeaturedImage … … 735 745 736 746 wp.media.featuredImage.frame().open(); 737 747 }).on( 'click', '#remove-post-thumbnail', function() { 738 wp.media.view.settings.post.featuredImageId = -1; 748 wp.media.featuredImage.remove(); 749 return false; 739 750 }); 740 751 } 741 752 };