Ticket #12922: 12922.6.diff
File 12922.6.diff, 6.9 KB (added by , 8 years ago) |
---|
-
src/wp-admin/admin-ajax.php
62 62 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', 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 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin',66 ' search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme',67 ' install-theme', 'test_url',65 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 66 'get-post-thumbnail-html', 'delete-plugin', 'search-plugins', 'search-install-plugins', 'activate-plugin', 67 'update-theme', 'delete-theme', 'install-theme', 'test_url', 68 68 ); 69 69 70 70 // Deprecated -
src/wp-admin/includes/ajax-actions.php
2164 2164 } 2165 2165 2166 2166 /** 2167 * Ajax handler for retrieving HTML for the featured image. 2168 * 2169 * @since 4.6.0 2170 */ 2171 function wp_ajax_get_post_thumbnail_html() { 2172 $post_ID = intval( $_POST['post_id'] ); 2173 2174 check_ajax_referer( "update-post_$post_ID" ); 2175 2176 if ( ! current_user_can( 'edit_post', $post_ID ) ) { 2177 wp_die( -1 ); 2178 } 2179 2180 $thumbnail_id = intval( $_POST['thumbnail_id'] ); 2181 2182 // For backwards compatibility, -1 refers to no featured image. 2183 if ( -1 === $thumbnail_id ) { 2184 $thumbnail_id = null; 2185 } 2186 2187 $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); 2188 wp_send_json_success( $return ); 2189 } 2190 2191 /** 2167 2192 * Ajax handler for setting the featured image for an attachment. 2168 2193 * 2169 2194 * @since 4.0.0 -
src/wp-admin/includes/post.php
1428 1428 $thumbnail_html 1429 1429 ); 1430 1430 $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>';1431 $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 1432 } 1433 1433 } 1434 1434 1435 $content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />'; 1436 1435 1437 /** 1436 1438 * Filters the admin post thumbnail HTML markup to return. 1437 1439 * … … 1753 1755 $query_args['preview_id'] = $post->ID; 1754 1756 $query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID ); 1755 1757 1756 if ( isset( $_POST['post_format'] ) ) 1758 if ( isset( $_POST['post_format'] ) ) { 1757 1759 $query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] ); 1760 } 1761 1762 if ( isset( $_POST['_thumbnail_id'] ) ) { 1763 $query_args['_thumbnail_id'] = ( 0 >= intval( $_POST['_thumbnail_id'] ) ) ? '-1' : intval( $_POST['_thumbnail_id'] ); 1764 } 1758 1765 } 1759 1766 1760 1767 return get_preview_post_link( $post, $query_args ); -
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 }; -
src/wp-includes/post.php
3260 3260 } 3261 3261 } 3262 3262 3263 if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) { 3264 $thumbnail_id = intval( $postarr['_thumbnail_id'] ); 3265 if ( -1 === $thumbnail_id ) { 3266 delete_post_thumbnail( $post_ID ); 3267 } else { 3268 set_post_thumbnail( $post_ID, $thumbnail_id ); 3269 } 3270 } 3271 3263 3272 if ( ! empty( $postarr['meta_input'] ) ) { 3264 3273 foreach ( $postarr['meta_input'] as $field => $value ) { 3265 3274 update_post_meta( $post_ID, $field, $value ); -
src/wp-includes/revision.php
530 530 $post->post_excerpt = $preview->post_excerpt; 531 531 532 532 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 533 add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 4 ); 533 534 534 535 return $post; 535 536 } … … 578 579 } 579 580 580 581 /** 582 * Filters post thumbnail lookup to set the post thumbnail. 583 * 584 * @since 4.6.0 585 * @access private 586 * 587 * @param null|array|string $value The value to return - a single metadata value, or an array of values. 588 * @param int $post_id Post ID. 589 * @param string $meta_key Meta key. 590 * @param bool $single Whether to return only the first value of the specified $meta_key. 591 * @return null|array The default return value or the post thumbnail meta array. 592 */ 593 function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key, $single ) { 594 if ( ! $post = get_post() ) { 595 return $value; 596 } 597 598 if ( empty( $_REQUEST['_thumbnail_id'] ) || $post->ID != $post_id || '_thumbnail_id' != $meta_key || 'revision' == $post->post_type ) { 599 return $value; 600 } 601 602 $thumbnail_id = intval( $_REQUEST['_thumbnail_id'] ); 603 if ( 0 >= $thumbnail_id ) { 604 return ''; 605 } 606 607 return strval( $thumbnail_id ); 608 } 609 610 /** 581 611 * Gets the post revision version. 582 612 * 583 613 * @since 3.6.0