Make WordPress Core

Ticket #20299: 20299-2.patch

File 20299-2.patch, 1.9 KB (added by WraithKenny, 11 years ago)
  • wp-includes/revision.php

     
    446446
    447447
    448448function _set_preview($post) {
    449 
     449        global $post_preview_id;
    450450        if ( ! is_object($post) )
    451451                return $post;
    452452
     
    460460        $post->post_content = $preview->post_content;
    461461        $post->post_title = $preview->post_title;
    462462        $post->post_excerpt = $preview->post_excerpt;
     463       
     464        $post_preview_id = $preview->ID;
     465        add_filter( 'get_post_metadata', '_get_preview_meta', 10, 4 );
    463466
    464467        return $post;
    465468}
    466469
     470/**
     471 * Private filter for getting metadata for the preview.
     472 *
     473 * @package WordPress
     474 * @subpackage Post_Revisions
     475 * @since 3.6.0
     476 *
     477 * @uses get_meta_data()
     478 *
     479 * @param unknown $value null
     480 * @param int $object_id ID of the object metadata is for
     481 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
     482 *              the specified object.
     483 * @param bool $single Optional, default is false. If true, return only the first value of the
     484 *              specified meta_key. This parameter has no effect if meta_key is not specified.
     485 *
     486 * @return string|array Single metadata value, or array of values
     487 */
     488function _get_preview_meta( $value, $object_id, $meta_key, $single ) {
     489        global $post_preview_id;
     490
     491        if ( !$meta_key )
     492                return $value;
     493
     494        if ( ! in_array( $meta_key, get_versioned_meta_keys() ) )
     495                return $value;
     496
     497        $meta_cache = wp_cache_get( $post_preview_id, 'post_meta' );
     498        if ( ! $meta_cache ) {
     499                $meta_cache = update_meta_cache( 'post', array( $object_id ) );
     500                $meta_cache = $meta_cache[$post_preview_id];
     501        }
     502        if ( isset( $meta_cache[ $meta_key ] ) )
     503                return array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] );
     504
     505        return $value;
     506}
     507
    467508function _wp_get_post_revision_version( $post ) {
    468509        if ( is_array( $post ) ) {
    469510                if ( ! isset( $post['post_name'] ) ) {