Make WordPress Core

Ticket #20299: 20299.patch

File 20299.patch, 2.0 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        $versioned_meta = apply_filters( 'versioned_meta', $versioned_meta );
     495        if ( ! in_array( $meta_key, $versioned_meta ) )
     496                return $value;
     497
     498        $meta_cache = wp_cache_get( $post_preview_id, 'post_meta' );
     499        if ( ! $meta_cache ) {
     500                $meta_cache = update_meta_cache( 'post', array( $object_id ) );
     501                $meta_cache = $meta_cache[$post_preview_id];
     502        }
     503        if ( isset( $meta_cache[ $meta_key ] ) )
     504                return array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] );
     505
     506        return $value;
     507}
     508
    467509function _wp_get_post_revision_version( $post ) {
    468510        if ( is_array( $post ) ) {
    469511                if ( ! isset( $post['post_name'] ) ) {