Make WordPress Core

Changeset 23859


Ignore:
Timestamp:
03/29/2013 10:37:44 AM (12 years ago)
Author:
markjaquith
Message:

Revision our post format postmeta.

props kovshenin, WraithKenny. see #20564.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/revision.php

    r23849 r23859  
    5959
    6060    return $return;
     61}
     62
     63/**
     64 * Determines which post meta fields are revisioned.
     65 *
     66 * @since 3.6
     67 * @access private
     68 * @return array An array of meta keys that should be revisioned.
     69 */
     70function _wp_post_revision_meta_keys() {
     71    return array(
     72        '_wp_format_url',
     73        '_wp_format_quote',
     74        '_wp_format_quote_source',
     75        '_wp_format_image',
     76        '_wp_format_gallery',
     77        '_wp_format_audio',
     78        '_wp_format_video',
     79    );
    6180}
    6281
     
    114133            }
    115134
     135            // Check whether revisioned meta fields have changed.
     136            foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
     137                if ( get_post_meta( $post->ID, $meta_key ) != get_post_meta( $last_revision->ID, $meta_key ) ) {
     138                    $post_has_changed = true;
     139                    break;
     140                }
     141            }
     142
    116143            //don't save revision if post unchanged
    117144            if( ! $post_has_changed )
     
    241268        return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
    242269
     270    $post_id = $post['ID'];
    243271    $post = _wp_post_revision_fields( $post, $autosave );
    244272    $post = wp_slash($post); //since data is from db
     
    250278    if ( $revision_id )
    251279        do_action( '_wp_put_post_revision', $revision_id );
     280
     281    // Save revisioned meta fields.
     282    foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
     283        $meta_values = get_post_meta( $post_id, $meta_key );
     284        if ( false === $meta_values )
     285            continue;
     286
     287        // Use the underlying add_metadata vs add_post_meta to make sure
     288        // metadata is added to the revision post and not its parent.
     289        foreach ( $meta_values as $meta_value )
     290            add_metadata( 'post', $revision_id, $meta_key, $meta_value );
     291    }
    252292
    253293    return $revision_id;
     
    324364
    325365    $update = wp_slash( $update ); //since data is from db
     366
     367    // Restore revisioned meta fields.
     368    foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
     369        delete_post_meta( $update['ID'], $meta_key );
     370        $meta_values = get_post_meta( $revision['ID'], $meta_key );
     371        if ( false === $meta_values )
     372            continue;
     373
     374        foreach ( $meta_values as $meta_value )
     375            add_post_meta( $update['ID'], $meta_key, $meta_value );
     376    }
    326377
    327378    $post_id = wp_update_post( $update );
Note: See TracChangeset for help on using the changeset viewer.