diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 2351958b85..df75c17140 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1473,8 +1473,10 @@ case 'set-post-thumbnail': check_ajax_referer( "set_post_thumbnail-$post_ID" ); if ( $thumbnail_id == '-1' ) { - delete_post_meta( $post_ID, '_thumbnail_id' ); - die( _wp_post_thumbnail_html() ); + if ( delete_post_thumbnail( $post_ID ) ) + die( _wp_post_thumbnail_html() ); + else + die( '0' ); } if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) diff --git a/wp-includes/post.php b/wp-includes/post.php index 93bdb0a36b..091ebaccbd 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -5190,6 +5190,21 @@ function set_post_thumbnail( $post, $thumbnail_id ) { return false; } +/** + * Removes a post thumbnail. + * + * @since 3.3.0 + * + * @param int|object $post Post ID or object where thumbnail should be removed from. + * @return bool True on success, false on failure. + */ +function delete_post_thumbnail( $post ) { + $post = get_post( $post ); + if ( $post ) + return delete_post_meta( $post->ID, '_thumbnail_id' ); + return false; +} + /** * Returns a link to a post format index. *