Ticket #12922: 12922.5.diff
File 12922.5.diff, 8.3 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 * -
src/wp-includes/js/autosave.js
34 34 post_author: $( '#post_author' ).val() || '', 35 35 post_title: $( '#title' ).val() || '', 36 36 content: $( '#content' ).val() || '', 37 excerpt: $( '#excerpt' ).val() || '' 37 excerpt: $( '#excerpt' ).val() || '', 38 _thumbnail_id: $( '#_thumbnail_id' ).val() || -1 38 39 }; 39 40 40 41 if ( type === 'local' ) { -
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
1617 1617 */ 1618 1618 function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { 1619 1619 // Make sure meta is added to the post, not a revision. 1620 if ( $the_post = wp_is_post_revision($post_id) )1620 if ( '_thumbnail_id' !== $meta_key && ( $the_post = wp_is_post_revision( $post_id ) ) ) 1621 1621 $post_id = $the_post; 1622 1622 1623 1623 return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); … … 1640 1640 */ 1641 1641 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { 1642 1642 // Make sure meta is added to the post, not a revision. 1643 if ( $the_post = wp_is_post_revision($post_id) )1643 if ( '_thumbnail_id' !== $meta_key && ( $the_post = wp_is_post_revision( $post_id ) ) ) 1644 1644 $post_id = $the_post; 1645 1645 1646 1646 return delete_metadata('post', $post_id, $meta_key, $meta_value); … … 1682 1682 */ 1683 1683 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { 1684 1684 // Make sure meta is added to the post, not a revision. 1685 if ( $the_post = wp_is_post_revision($post_id) )1685 if ( '_thumbnail_id' !== $meta_key && ( $the_post = wp_is_post_revision( $post_id ) ) ) 1686 1686 $post_id = $the_post; 1687 1687 1688 1688 return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); … … 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
34 34 'post_title' => __( 'Title' ), 35 35 'post_content' => __( 'Content' ), 36 36 'post_excerpt' => __( 'Excerpt' ), 37 '_thumbnail_id' => __( 'Featured Image' ), 37 38 ); 38 39 } 39 40 … … 530 531 $post->post_excerpt = $preview->post_excerpt; 531 532 532 533 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 534 add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 4 ); 533 535 534 536 return $post; 535 537 } … … 578 580 } 579 581 580 582 /** 583 * Filters post thumbnail lookup to set the post thumbnail. 584 * 585 * @since 4.6.0 586 * @access private 587 * 588 * @param null|array|string $value The value to return - a single metadata value, or an array of values. 589 * @param int $post_id Post ID. 590 * @param string $meta_key Meta key. 591 * @param bool $single Whether to return only the first value of the specified $meta_key. 592 * @return null|array The default return value or the post thumbnail meta array. 593 */ 594 function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key, $single ) { 595 if ( '_thumbnail_id' !== $meta_key ) { 596 return $value; 597 } 598 599 $preview = wp_get_post_autosave( $post_id ); 600 if ( ! is_object( $preview ) ) { 601 return $value; 602 } 603 604 remove_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 4 ); 605 606 $value = get_post_meta( $preview->ID, '_thumbnail_id', $single ); 607 608 add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 4 ); 609 610 return $value; 611 } 612 613 /** 581 614 * Gets the post revision version. 582 615 * 583 616 * @since 3.6.0