WordPress.org

Make WordPress Core

Ticket #23539: 23539.diff

File 23539.diff, 1.9 KB (added by kovshenin, 8 years ago)
  • wp-includes/revision.php

     
    504504        $post->post_title = $preview->post_title;
    505505        $post->post_excerpt = $preview->post_excerpt;
    506506
     507        add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 );
     508
    507509        return $post;
    508510}
    509511
     512/**
     513 * Filters post meta retrieval to get values from the actual autosave post,
     514 * and not its parent. Filters revisioned meta keys only.
     515 *
     516 * @since 3.6
     517 * @access private
     518 */
     519function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) {
     520        global $post;
     521
     522        if ( $post->ID != $object_id || ! in_array( $meta_key, _wp_post_revision_meta_keys() ) || 'revision' == $post->post_type )
     523                return $value;
     524
     525        $preview = wp_get_post_autosave( $post->ID );
     526        return get_post_meta( $preview->ID, $meta_key, $single );
     527}
     528
    510529function _wp_get_post_revision_version( $revision ) {
    511530        if ( is_object( $revision ) )
    512531                $revision = get_object_vars( $revision );
  • wp-admin/includes/post.php

     
    12781278                $new_autosave = _wp_post_revision_fields( $_POST, true );
    12791279                $new_autosave['ID'] = $old_autosave->ID;
    12801280                $new_autosave['post_author'] = $post_author;
     1281
     1282                // Auto-save revisioned meta fields too.
     1283                foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
     1284                        if ( ! isset( $_POST[ $meta_key ] ) )
     1285                                continue;
     1286
     1287                        // Use the underlying delete_metadata and add_metadata vs delete_post_meta
     1288                        // and add_post_meta to make sure we're working with the actual revision meta.
     1289                        delete_metadata( 'post', $new_autosave['ID'], $meta_key );
     1290                        add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] );
     1291                }
     1292
    12811293                return wp_update_post( $new_autosave );
    12821294        }
    12831295