Ticket #20564: 20564.7.diff
File 20564.7.diff, 4.0 KB (added by , 11 years ago) |
---|
-
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, $meta_value ); 291 294 } 292 295 296 // Save the post format 297 add_metadata( 'post', $revision_id, '_revision_post_format', get_post_format( $post_id ) ); 298 293 299 return $revision_id; 294 300 } 295 301 … … 367 373 // Restore revisioned meta fields. 368 374 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 369 375 delete_post_meta( $update['ID'], $meta_key ); 370 $meta_value s = get_post_meta( $revision['ID'], $meta_key);371 if ( false === $meta_values)376 $meta_value = get_post_meta( $revision['ID'], $meta_key, true ); 377 if ( empty( $meta_value ) ) 372 378 continue; 373 379 374 foreach ( $meta_values as $meta_value ) 375 add_post_meta( $update['ID'], $meta_key, $meta_value ); 380 add_post_meta( $update['ID'], $meta_key, $meta_value ); 376 381 } 377 382 383 // Restore post format 384 $post_format = get_post_meta( $revision['ID'], '_revision_post_format', true ); 385 set_post_format( $update['ID'], $post_format ); 386 378 387 $post_id = wp_update_post( $update ); 379 388 if ( is_wp_error( $post_id ) ) 380 389 return $post_id; … … 505 514 $post->post_excerpt = $preview->post_excerpt; 506 515 507 516 add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 ); 517 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 508 518 509 519 return $post; 510 520 } … … 541 551 return get_post_meta( $preview->ID, $meta_key, $single ); 542 552 } 543 553 554 /** 555 * Filters terms lookup to get the post format saved with the preview revision. 556 * 557 * @since 2.6 558 * @access private 559 */ 560 function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { 561 $post = get_post(); 562 563 if ( $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) 564 return $terms; 565 566 $preview = wp_get_post_autosave( $post->ID ); 567 if ( ! is_object( $preview ) ) 568 return $terms; 569 570 $post_format = get_post_meta( $preview->ID, '_revision_post_format', true ); 571 $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $post_format ), 'post_format' ); 572 if ( $term ) 573 $terms = array( $term ); 574 575 return $terms; 576 } 577 544 578 function _wp_get_post_revision_version( $revision ) { 545 579 if ( is_object( $revision ) ) 546 580 $revision = get_object_vars( $revision ); -
wp-admin/includes/post.php
1290 1290 add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] ); 1291 1291 } 1292 1292 1293 // Save the post format 1294 if ( isset( $_POST['post_format'] ) ) 1295 update_metadata( 'post', $new_autosave['ID'], '_revision_post_format', $_POST['post_format'] ); 1296 1293 1297 return wp_update_post( $new_autosave ); 1294 1298 } 1295 1299