Ticket #20564: 20564.5.diff
File 20564.5.diff, 2.5 KB (added by , 12 years ago) |
---|
-
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 // Use the underlying add_metadata vs add_post_meta to make sure 289 // metadata is added to the revision post and not its parent. 290 foreach ( $meta_values as $meta_value ) 291 add_metadata( 'post', $revision_id, $meta_key, $meta_value ); 292 } 293 253 294 return $revision_id; 254 295 } 255 296 … … 324 365 325 366 $update = wp_slash( $update ); //since data is from db 326 367 368 // Restore revisioned meta fields. 369 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 370 delete_post_meta( $update['ID'], $meta_key ); 371 $meta_values = get_post_meta( $revision['ID'], $meta_key ); 372 if ( false === $meta_values ) 373 continue; 374 375 foreach ( $meta_values as $meta_value ) 376 add_post_meta( $update['ID'], $meta_key, $meta_value ); 377 } 378 327 379 $post_id = wp_update_post( $update ); 328 380 if ( is_wp_error( $post_id ) ) 329 381 return $post_id;