diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 31c865978e..0287296a08 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1278,6 +1278,18 @@ function wp_create_post_autosave( $post_id ) { $new_autosave = _wp_post_revision_fields( $_POST, true ); $new_autosave['ID'] = $old_autosave->ID; $new_autosave['post_author'] = $post_author; + + // Auto-save revisioned meta fields too. + foreach ( _wp_post_revision_meta_keys() as $meta_key ) { + if ( ! isset( $_POST[ $meta_key ] ) ) + continue; + + // Use the underlying delete_metadata and add_metadata vs delete_post_meta + // and add_post_meta to make sure we're working with the actual revision meta. + delete_metadata( 'post', $new_autosave['ID'], $meta_key ); + add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] ); + } + return wp_update_post( $new_autosave ); } diff --git a/wp-includes/revision.php b/wp-includes/revision.php index ede6a889de..6aae32bb3e 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -504,9 +504,28 @@ function _set_preview($post) { $post->post_title = $preview->post_title; $post->post_excerpt = $preview->post_excerpt; + add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 ); + return $post; } +/** + * Filters post meta retrieval to get values from the actual autosave post, + * and not its parent. Filters revisioned meta keys only. + * + * @since 3.6 + * @access private + */ +function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) { + $post = get_post(); + + if ( $post->ID != $object_id || ! in_array( $meta_key, _wp_post_revision_meta_keys() ) || 'revision' == $post->post_type ) + return $value; + + $preview = wp_get_post_autosave( $post->ID ); + return get_post_meta( $preview->ID, $meta_key, $single ); +} + function _wp_get_post_revision_version( $revision ) { if ( is_object( $revision ) ) $revision = get_object_vars( $revision );