WordPress.org

Make WordPress Core

Changeset 23862


Ignore:
Timestamp:
03/29/2013 12:08:42 PM (8 years ago)
Author:
markjaquith
Message:

Use the revisioned post format metadata when previewing.

fixes #23539. props kovshenin.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r23861 r23862  
    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    }
  • trunk/wp-includes/revision.php

    r23859 r23862  
    505505    $post->post_excerpt = $preview->post_excerpt;
    506506
     507    add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 );
     508
    507509    return $post;
     510}
     511
     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    $post = get_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 );
    508527}
    509528
Note: See TracChangeset for help on using the changeset viewer.