Use the revisioned post format metadata when previewing.
fixes #23539. props kovshenin. git-svn-id: https://develop.svn.wordpress.org/trunk@23862 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6813288d59
commit
07f5ffd015
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue