Ticket #12922: 12922.4.diff
File 12922.4.diff, 4.2 KB (added by , 8 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
2152 2152 } 2153 2153 2154 2154 /** 2155 * Ajax handler for retrieving HTML for the featured image. 2156 * 2157 * @since 4.6.0 2158 */ 2159 function wp_ajax_get_post_thumbnail_html() { 2160 $post_ID = intval( $_POST['post_id'] ); 2161 2162 check_ajax_referer( "update-post_$post_ID" ); 2163 2164 if ( ! current_user_can( 'edit_post', $post_ID ) ) { 2165 wp_die( -1 ); 2166 } 2167 2168 $thumbnail_id = intval( $_POST['thumbnail_id'] ); 2169 2170 // For backwards compatibility, -1 refers to no featured image. 2171 if ( -1 === $thumbnail_id ) { 2172 $thumbnail_id = null; 2173 } 2174 2175 $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); 2176 wp_send_json_success( $return ); 2177 } 2178 2179 /** 2155 2180 * AJAX handler for setting the featured image for an attachment. 2156 2181 * 2157 2182 * @since 4.0.0 -
src/wp-admin/includes/post.php
224 224 _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) ); 225 225 } 226 226 227 if ( isset( $post_data['_thumbnail_id'] ) && post_type_supports( $ptype->name, 'thumbnail' ) ) { 228 $thumbnail_id = intval( $post_data['_thumbnail_id'] ); 229 if ( -1 === $thumbnail_id ) { 230 delete_post_thumbnail( $post_ID ); 231 } else { 232 set_post_thumbnail( $post_ID, $thumbnail_id ); 233 } 234 } 235 227 236 if ( isset($post_data['visibility']) ) { 228 237 switch ( $post_data['visibility'] ) { 229 238 case 'public' : … … 1428 1437 $thumbnail_html 1429 1438 ); 1430 1439 $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>'; 1431 $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>';1440 $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>'; 1432 1441 } 1433 1442 } 1434 1443 1444 $content .= '<input type="hidden" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />'; 1445 1435 1446 /** 1436 1447 * Filters the admin post thumbnail HTML markup to return. 1437 1448 * -
src/wp-includes/js/media-editor.js
649 649 650 650 settings.post.featuredImageId = id; 651 651 652 wp.media.post( 'set-post-thumbnail', { 653 json: true, 652 wp.media.post( 'get-post-thumbnail-html', { 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 };