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. Built from https://develop.svn.wordpress.org/trunk@38118 git-svn-id: http://core.svn.wordpress.org/trunk@38059 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -3260,6 +3260,16 @@ function wp_insert_post( $postarr, $wp_error = false ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set or remove featured image.
|
||||
if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) {
|
||||
$thumbnail_id = intval( $postarr['_thumbnail_id'] );
|
||||
if ( -1 === $thumbnail_id ) {
|
||||
delete_post_thumbnail( $post_ID );
|
||||
} else {
|
||||
set_post_thumbnail( $post_ID, $thumbnail_id );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $postarr['meta_input'] ) ) {
|
||||
foreach ( $postarr['meta_input'] as $field => $value ) {
|
||||
update_post_meta( $post_ID, $field, $value );
|
||||
|
||||
Reference in New Issue
Block a user