Ticket #12922: 12922.7.diff
File 12922.7.diff, 6.4 KB (added by , 8 years ago) |
---|
-
src/wp-admin/admin-ajax.php
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', 'delete-plugin', 66 66 'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 67 'install-theme', 'test_url', 67 'install-theme', 'test_url', 'get-post-thumbnail-html', 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 backward 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'] = ( intval( $_POST['_thumbnail_id'] ) <= 0 ) ? '-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
657 657 658 658 settings.post.featuredImageId = id; 659 659 660 wp.media.post( 'set-post-thumbnail', { 661 json: true, 660 wp.media.post( 'get-post-thumbnail-html', { 662 661 post_id: settings.post.id, 663 662 thumbnail_id: settings.post.featuredImageId, 664 663 _wpnonce: settings.post.nonce 665 664 }).done( function( html ) { 665 if ( html == '0' ) { 666 window.alert( window.setPostThumbnailL10n.error ); 667 return; 668 } 666 669 $( '.inside', '#postimagediv' ).html( html ); 667 670 }); 668 671 }, 669 672 /** 673 * Remove the featured image id, save the post thumbnail data and 674 * set the HTML in the post meta box to no featured image. 675 */ 676 remove: function() { 677 wp.media.featuredImage.set( -1 ); 678 }, 679 /** 670 680 * The Featured Image workflow 671 681 * 672 682 * @global wp.media.controller.FeaturedImage … … 743 753 744 754 wp.media.featuredImage.frame().open(); 745 755 }).on( 'click', '#remove-post-thumbnail', function() { 746 wp.media.view.settings.post.featuredImageId = -1; 756 wp.media.featuredImage.remove(); 757 return false; 747 758 }); 748 759 } 749 760 }; -
src/wp-includes/post.php
3260 3260 } 3261 3261 } 3262 3262 3263 // Set or remove featured image. 3264 if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) { 3265 $thumbnail_id = intval( $postarr['_thumbnail_id'] ); 3266 if ( -1 === $thumbnail_id ) { 3267 delete_post_thumbnail( $post_ID ); 3268 } else { 3269 set_post_thumbnail( $post_ID, $thumbnail_id ); 3270 } 3271 } 3272 3263 3273 if ( ! empty( $postarr['meta_input'] ) ) { 3264 3274 foreach ( $postarr['meta_input'] as $field => $value ) { 3265 3275 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, 3 ); 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 * @return null|array The default return value or the post thumbnail meta array. 591 */ 592 function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) { 593 if ( ! $post = get_post() ) { 594 return $value; 595 } 596 597 if ( empty( $_REQUEST['_thumbnail_id'] ) || $post->ID != $post_id || '_thumbnail_id' != $meta_key || 'revision' == $post->post_type ) { 598 return $value; 599 } 600 601 $thumbnail_id = intval( $_REQUEST['_thumbnail_id'] ); 602 if ( $thumbnail_id <= 0 ) { 603 return ''; 604 } 605 606 return strval( $thumbnail_id ); 607 } 608 609 /** 581 610 * Gets the post revision version. 582 611 * 583 612 * @since 3.6.0