Ticket #20564: 20564-9.patch
File 20564-9.patch, 7.0 KB (added by , 11 years ago) |
---|
-
wp-includes/js/autosave.js
322 322 (function($){ 323 323 // Returns the data for saving in both localStorage and autosaves to the server 324 324 wp.autosave.getPostData = function() { 325 var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, cats = [],325 var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, post_format, cats = [], 326 326 data = { 327 327 action: 'autosave', 328 328 autosave: true, … … 381 381 if ( $('#auto_draft').val() == '1' ) 382 382 data['auto_draft'] = '1'; 383 383 384 post_format = $('#post_format').val() || ''; 385 data['post_format'] = post_format == 'standard' ? '' : post_format; 386 387 // Add the post format selected on the edit screen. 388 $('#post-formats-select').find('input[name="post_format"]').each( function(i, field) { 389 data[ field.name ] = $(field).is(':checked') || ''; 390 }); 391 384 392 return data; 385 393 }; 386 394 -
wp-includes/revision.php
59 59 } 60 60 61 61 /** 62 * Determines which post meta fields are revisioned. 63 * 64 * @since 3.6 65 * @access private 66 * @return array An array of meta keys that should be revisioned. 67 */ 68 function _wp_post_revision_meta_keys() { 69 $keys = array( 70 '_wp_format_url', 71 '_wp_format_quote', 72 '_wp_format_quote_source', 73 '_wp_format_image', 74 '_wp_format_gallery', 75 '_wp_format_audio', 76 '_wp_format_video', 77 ); 78 return $keys; 79 } 80 81 /** 62 82 * Saves an already existing post as a post revision. 63 83 * 64 84 * Typically used immediately after post updates. … … 102 122 if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $last_revision, $post ) ) { 103 123 $post_has_changed = false; 104 124 125 // Check whether revisioned fields have been changed 105 126 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 106 127 if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) { 107 128 $post_has_changed = true; 108 129 break; 109 130 } 110 131 } 111 //don't save revision if post unchanged 132 133 // Check whether revisioned meta fields have changed 134 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 135 if ( get_post_meta( $post->ID, $meta_key ) != get_post_meta( $last_revision->ID, $meta_key ) ) { 136 $post_has_changed = true; 137 break; 138 } 139 } 140 141 // Check whether the post format has changed 142 if ( get_post_format( $post->ID ) != get_post_meta( $last_revision->ID, '_revision_post_format', true ) ) 143 $post_has_changed = true; 144 145 // Don't save revision if post unchanged 112 146 if( ! $post_has_changed ) 113 147 return; 114 148 } … … 240 274 if ( $revision_id ) 241 275 do_action( '_wp_put_post_revision', $revision_id ); 242 276 243 return $revision_id; 244 } 277 // Save revisioned meta fields. 278 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 279 $meta_value = get_post_meta( $post_id, $meta_key, true ); 280 if ( empty( $meta_value ) ) 281 continue; 282 // Use the underlying add_metadata vs add_post_meta to make sure 283 // metadata is added to the revision post and not its parent. 284 add_metadata( 'post', $revision_id, $meta_key, wp_slash( $meta_value ) ); 285 } 286 // Save the post format 287 if ( $post_format = get_post_format( $post_id ) ) 288 add_metadata( 'post', $revision_id, '_revision_post_format', $post_format ); 245 289 290 return $revision_id; 291 } 292 246 293 /** 247 294 * Gets a post revision. 248 295 * … … 308 355 309 356 $update['ID'] = $revision['post_parent']; 310 357 358 // Restore revisioned meta fields. 359 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 360 $meta_value = get_post_meta( $revision['ID'], $meta_key, true ); 361 if ( empty( $meta_value ) ) 362 $meta_value = ''; 363 // Add slashes to data pulled from the db 364 update_post_meta( $update['ID'], $meta_key, wp_slash( $meta_value ) ); 365 } 366 311 367 $update = wp_slash( $update ); //since data is from db 368 // Restore post format 369 set_post_format( $update['ID'], get_post_meta( $revision['ID'], '_revision_post_format', true ) ); 312 370 371 // Restore revisioned meta fields. 372 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 373 delete_post_meta( $update['ID'], $meta_key ); 374 $meta_values = get_post_meta( $revision['ID'], $meta_key ); 375 if ( false === $meta_values ) 376 continue; 377 378 foreach ( $meta_values as $meta_value ) 379 add_post_meta( $update['ID'], $meta_key, $meta_value ); 380 } 381 313 382 $post_id = wp_update_post( $update ); 314 383 if ( ! $post_id || is_wp_error( $post_id ) ) 315 384 return $post_id; … … 449 518 $post->post_excerpt = $preview->post_excerpt; 450 519 451 520 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 521 add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 ); 452 522 453 523 return $post; 454 524 } … … 472 542 } 473 543 474 544 /** 545 * Filters post meta retrieval to get values from the actual autosave post, 546 * and not its parent. Filters revisioned meta keys only. 547 * 548 * @since 3.6.0 549 * @access private 550 */ 551 function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) { 552 $post = get_post(); 553 if ( empty( $post ) || $post->ID != $object_id || ! in_array( $meta_key, _wp_post_revision_meta_keys() ) || 'revision' == $post->post_type ) 554 return $value; 555 $preview = wp_get_post_autosave( $post->ID ); 556 if ( ! is_object( $preview ) ) 557 return $value; 558 return get_post_meta( $preview->ID, $meta_key, $single ); 559 } 560 561 /** 475 562 * Filters terms lookup to set the post format. 476 563 * 477 564 * @since 3.6.0 -
wp-admin/includes/post.php
1327 1327 $new_autosave['ID'] = $old_autosave->ID; 1328 1328 $new_autosave['post_author'] = $post_author; 1329 1329 1330 // Auto-save revisioned meta fields. 1331 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 1332 if ( isset( $_POST[ $meta_key ] ) && get_post_meta( $new_autosave['ID'], $meta_key, true ) != $_POST[ $meta_key ] ) { 1333 // Use the underlying delete_metadata and add_metadata vs delete_post_meta 1334 // and add_post_meta to make sure we're working with the actual revision meta. 1335 delete_metadata( 'post', $new_autosave['ID'], $meta_key ); 1336 if ( ! empty( $_POST[ $meta_key ] ) ) 1337 add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] ); 1338 } 1339 } 1340 1341 // Save the post format as part of the autosave if different. 1342 if ( isset( $_POST['post_format'] ) && get_post_meta( $new_autosave['ID'], '_revision_post_format', true ) != $_POST['post_format'] ) { 1343 delete_metadata( 'post', $new_autosave['ID'], '_revision_post_format' ); 1344 if ( ! empty( $_POST['post_format'] ) ) 1345 update_metadata( 'post', $new_autosave['ID'], '_revision_post_format', $_POST['post_format'] ); 1346 } 1347 1330 1348 // If the new autosave is the same content as the post, delete the old autosave. 1331 1349 $post = get_post( $post_id ); 1332 1350 $autosave_is_different = false;