Ticket #20564: 20564.4.diff
File 20564.4.diff, 4.2 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
1667 1667 * @return bool False for failure. True for success. 1668 1668 */ 1669 1669 function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) { 1670 // make sure meta is added to the post, not a revision 1671 if ( $the_post = wp_is_post_revision( $post_id) )1670 // make sure meta is added to the post, not a revision, unless the key is revisioned 1671 if ( $the_post = wp_is_post_revision( $post_id ) && ! in_array( $meta_key, _wp_post_revision_meta_keys() ) ) 1672 1672 $post_id = $the_post; 1673 1673 1674 1674 return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); … … 1691 1691 * @return bool False for failure. True for success. 1692 1692 */ 1693 1693 function delete_post_meta($post_id, $meta_key, $meta_value = '') { 1694 // make sure meta is added to the post, not a revision1695 if ( $the_post = wp_is_post_revision( $post_id) )1694 // make sure meta is deleted from the post, not the revision, unless the key is revisioned 1695 if ( $the_post = wp_is_post_revision( $post_id ) && ! in_array( $meta_key, _wp_post_revision_meta_keys() ) ) 1696 1696 $post_id = $the_post; 1697 1697 1698 1698 return delete_metadata('post', $post_id, $meta_key, $meta_value); … … 1734 1734 * @return bool False on failure, true if success. 1735 1735 */ 1736 1736 function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { 1737 // make sure meta is added to the post, not a revision1738 if ( $the_post = wp_is_post_revision( $post_id) )1737 // make sure meta is updated on the post, not a revision, unless the key is revisioned 1738 if ( $the_post = wp_is_post_revision( $post_id ) && ! in_array( $meta_key, _wp_post_revision_meta_keys() ) ) 1739 1739 $post_id = $the_post; 1740 1740 1741 1741 return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); -
wp-includes/revision.php
61 61 } 62 62 63 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 */ 70 function _wp_post_revision_meta_keys() { 71 $keys = 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 ); 80 return $keys; 81 } 82 83 /** 64 84 * Saves an already existing post as a post revision. 65 85 * 66 86 * Typically used immediately after post updates. … … 113 133 } 114 134 } 115 135 136 // Check whether revisioned meta fields have changed. 137 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 138 if ( get_post_meta( $post->ID, $meta_key ) != get_post_meta( $last_revision->ID, $meta_key ) ) { 139 $post_has_changed = true; 140 break; 141 } 142 } 143 116 144 //don't save revision if post unchanged 117 145 if( ! $post_has_changed ) 118 146 return; … … 240 268 if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) 241 269 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 242 270 271 $post_id = $post['ID']; 243 272 $post = _wp_post_revision_fields( $post, $autosave ); 244 273 $post = wp_slash($post); //since data is from db 245 274 … … 250 279 if ( $revision_id ) 251 280 do_action( '_wp_put_post_revision', $revision_id ); 252 281 282 // Save revisioned meta fields. 283 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 284 $meta_values = get_post_meta( $post_id, $meta_key ); 285 if ( false === $meta_values ) 286 continue; 287 288 foreach ( $meta_values as $meta_value ) 289 add_post_meta( $revision_id, $meta_key, $meta_value ); 290 } 291 253 292 return $revision_id; 254 293 } 255 294 … … 324 363 325 364 $update = wp_slash( $update ); //since data is from db 326 365 366 // Restore revisioned meta fields. 367 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 368 delete_post_meta( $update['ID'], $meta_key ); 369 $meta_values = get_post_meta( $revision['ID'], $meta_key ); 370 if ( false === $meta_values ) 371 continue; 372 373 foreach ( $meta_values as $meta_value ) 374 add_post_meta( $update['ID'], $meta_key, $meta_value ); 375 } 376 327 377 $post_id = wp_update_post( $update ); 328 378 if ( is_wp_error( $post_id ) ) 329 379 return $post_id;