Make WordPress Core


Ignore:
Timestamp:
07/20/2016 04:23:36 PM (7 years ago)
Author:
joemcgill
Message:

Post Thumbnails: Only update featured images when saving a post.

Previously, changing the post thumbnail of a published post in the edit screen
would immediately apply the change, rather than waiting for the post to be
saved before applying the update. This could lead to someone unintentionally
editing the post thumbnail on a published post, and made it impossible to
preview changes to post thumbnails on published posts before saving the change.

This introduces a new Ajax handler, wp_ajax_get_post_thumbnail_html() to
retrieve the HTML for the post thumbnail meta box without updating the post
meta value for _thumbnail_id. It also allows post thumbnail changes to be
previewed by passing the _thumbnail_id as a query variable to the preview
screen and adding a new filter, _wp_preview_post_thumbnail_filter(), which
gets applied to get_post_metadata during the post preview process.

Props flixos90.
Fixes #12922.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r38076 r38118  
    32613261    }
    32623262
     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
    32633273    if ( ! empty( $postarr['meta_input'] ) ) {
    32643274        foreach ( $postarr['meta_input'] as $field => $value ) {
Note: See TracChangeset for help on using the changeset viewer.