Ticket #20564: 20564-8.patch
File 20564-8.patch, 6.3 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/post.php
1279 1279 $new_autosave['ID'] = $old_autosave->ID; 1280 1280 $new_autosave['post_author'] = $post_author; 1281 1281 1282 // Auto-save revisioned meta fields too.1282 // Auto-save revisioned meta fields. 1283 1283 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 1284 if ( ! isset( $_POST[ $meta_key ] ) ) 1285 continue; 1284 if ( isset( $_POST[ $meta_key ] ) && get_post_meta( $new_autosave['ID'], $meta_key, true ) != $_POST[ $meta_key ] ) { 1285 // Use the underlying delete_metadata and add_metadata vs delete_post_meta 1286 // and add_post_meta to make sure we're working with the actual revision meta. 1287 delete_metadata( 'post', $new_autosave['ID'], $meta_key ); 1286 1288 1287 // Use the underlying delete_metadata and add_metadata vs delete_post_meta 1288 // and add_post_meta to make sure we're working with the actual revision meta. 1289 delete_metadata( 'post', $new_autosave['ID'], $meta_key ); 1290 add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] ); 1289 if ( ! empty( $_POST[ $meta_key ] ) ) 1290 add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] ); 1291 } 1291 1292 } 1292 1293 1294 // Save the post format if different 1295 if ( isset( $_POST['post_format'] ) && get_post_meta( $new_autosave['ID'], '_revision_post_format', true ) != $_POST['post_format'] ) { 1296 delete_metadata( 'post', $new_autosave['ID'], '_revision_post_format' ); 1297 1298 if ( ! empty( $_POST['post_format'] ) ) 1299 update_metadata( 'post', $new_autosave['ID'], '_revision_post_format', $_POST['post_format'] ); 1300 } 1301 1293 1302 return wp_update_post( $new_autosave ); 1294 1303 } 1295 1304 -
wp-includes/js/autosave.js
305 305 (function($){ 306 306 // Returns the data for saving in both localStorage and autosaves to the server 307 307 wp.autosave.getPostData = function() { 308 var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, cats = [],308 var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, post_format, cats = [], 309 309 data = { 310 310 action: 'autosave', 311 311 autosave: true, … … 364 364 if ( $('#auto_draft').val() == '1' ) 365 365 data['auto_draft'] = '1'; 366 366 367 post_format = $('#post_format').val() || ''; 368 data['post_format'] = post_format == 'standard' ? '' : post_format; 369 370 $('.post-formats-fields').find('input[name^="_wp_format_"], textarea[name^="_wp_format_"]').each( function(i, field) { 371 data[ field.name ] = field.value || ''; 372 }); 373 367 374 return data; 368 375 } 369 376 -
wp-includes/revision.php
134 134 135 135 // Check whether revisioned meta fields have changed. 136 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) ) {137 if ( get_post_meta( $post->ID, $meta_key, true ) != get_post_meta( $last_revision->ID, $meta_key, true ) ) { 138 138 $post_has_changed = true; 139 139 break; 140 140 } 141 141 } 142 142 143 // Check whether the post format has changed 144 if ( get_post_format( $post->ID ) != get_post_meta( $last_revision->ID, '_revision_post_format', true ) ) 145 $post_has_changed = true; 146 143 147 //don't save revision if post unchanged 144 148 if( ! $post_has_changed ) 145 149 return; … … 280 284 281 285 // Save revisioned meta fields. 282 286 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 283 $meta_value s = get_post_meta( $post_id, $meta_key);284 if ( false === $meta_values)287 $meta_value = get_post_meta( $post_id, $meta_key, true ); 288 if ( empty( $meta_value ) ) 285 289 continue; 286 290 287 291 // Use the underlying add_metadata vs add_post_meta to make sure 288 292 // 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 ); 293 add_metadata( 'post', $revision_id, $meta_key, wp_slash( $meta_value ) ); 291 294 } 292 295 296 // Save the post format 297 if ( $post_format = get_post_format( $post_id ) ) 298 add_metadata( 'post', $revision_id, '_revision_post_format', $post_format ); 299 293 300 return $revision_id; 294 301 } 295 302 … … 366 373 367 374 // Restore revisioned meta fields. 368 375 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 $meta_value = get_post_meta( $revision['ID'], $meta_key, true ); 377 if ( empty( $meta_value ) ) 378 $meta_value = ''; 379 // Add slashes to data pulled from the db 380 update_post_meta( $update['ID'], $meta_key, wp_slash( $meta_value ) ); 376 381 } 377 382 383 // Restore post format 384 set_post_format( $update['ID'], get_post_meta( $revision['ID'], '_revision_post_format', true ) ); 385 378 386 $post_id = wp_update_post( $update ); 379 387 if ( is_wp_error( $post_id ) ) 380 388 return $post_id; … … 505 513 $post->post_excerpt = $preview->post_excerpt; 506 514 507 515 add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 ); 516 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 508 517 509 518 return $post; 510 519 } … … 541 550 return get_post_meta( $preview->ID, $meta_key, $single ); 542 551 } 543 552 553 /** 554 * Filters terms lookup to get the post format saved with the preview revision. 555 * 556 * @since 2.6 557 * @access private 558 */ 559 function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { 560 $post = get_post(); 561 562 if ( $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) 563 return $terms; 564 565 if ( ! $preview = wp_get_post_autosave( $post->ID ) ) 566 return $terms; 567 568 $post_format = get_post_meta( $preview->ID, '_revision_post_format', true ); 569 $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $post_format ), 'post_format' ); 570 if ( $term ) 571 $terms = array( $term ); 572 573 return $terms; 574 } 575 544 576 function _wp_get_post_revision_version( $revision ) { 545 577 if ( is_object( $revision ) ) 546 578 $revision = get_object_vars( $revision );