Ticket #20564: 20564-6.patch
File 20564-6.patch, 8.3 KB (added by , 12 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. 1283 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 1284 if ( ! isset( $_POST[ $meta_key ] ) ) 1285 continue; 1282 // Auto-save revisioned meta fields. 1283 if ( ! empty( $_POST['post_format'] ) && in_array( $_POST['post_format'], array_keys( get_post_format_strings() ) ) ) { 1284 $post_format = $_POST['post_format']; 1286 1285 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 ] ); 1286 if ( $meta_keys = _wp_post_revision_meta_keys( $post_format ) ) { 1287 foreach ( $meta_keys as $meta_key ) { 1288 // Don't add the meta if there is no data. 1289 if ( empty( $_POST[ $meta_key ] ) ) 1290 continue; 1291 1292 // Use the underlying delete_metadata and add_metadata vs delete_post_meta 1293 // and add_post_meta to make sure we're working with the actual revision meta. 1294 delete_metadata( 'post', $new_autosave['ID'], $meta_key ); 1295 add_metadata( 'post', $new_autosave['ID'], $meta_key, $_POST[ $meta_key ] ); 1296 } 1297 } 1298 // Save the current post format as revision meta 1299 add_metadata( 'post', $new_autosave['ID'], '_revision_format', $post_format ); 1291 1300 } 1292 1301 1293 1302 return wp_update_post( $new_autosave ); -
wp-includes/js/autosave.js
292 292 (function($){ 293 293 // Returns the data for saving in both localStorage and autosaves to the server 294 294 wp.autosave.getPostData = function() { 295 var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, cats = [],295 var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, post_format, cats = [], 296 296 data = { 297 297 action: 'autosave', 298 298 autosave: true, … … 351 351 if ( $('#auto_draft').val() == '1' ) 352 352 data['auto_draft'] = '1'; 353 353 354 post_format = $('.post-format-options a.active').attr('data-wp-format'); 355 if ( post_format && post_format != 'standard' ) 356 data['post_format'] = post_format; 357 354 358 return data; 355 359 } 356 360 -
wp-includes/post-formats.php
51 51 * @since 3.1.0 52 52 * 53 53 * @param int|object $post The post for which to assign a format 54 * @param string $format A format to assign. Use an empty string or array to remove all formatsfrom the post.54 * @param string $format A format to assign. Empty or invalid value will remove the format from the post. 55 55 * @return mixed WP_Error on error. Array of affected term IDs on success. 56 56 */ 57 57 function set_post_format( $post, $format ) { -
wp-includes/revision.php
67 67 * @access private 68 68 * @return array An array of meta keys that should be revisioned. 69 69 */ 70 function _wp_post_revision_meta_keys() { 71 return 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', 70 function _wp_post_revision_meta_keys( $post_format ) { 71 $keys = array( 72 'quote' => array( '_wp_format_quote', '_wp_format_quote_source', '_wp_format_url' ), 73 'link' => array( '_wp_format_url' ), 74 'image' => array( '_wp_format_image', '_wp_format_url' ), 75 'gallery' => array( '_wp_format_gallery' ), 76 'video' => array( '_wp_format_video' ), 77 'audio' => array( '_wp_format_audio' ), 79 78 ); 79 80 return isset( $keys[ $post_format ] ) ? $keys[ $post_format ] : false; 80 81 } 81 82 82 83 /** … … 132 133 } 133 134 } 134 135 135 // Check whether revisioned meta fields have changed. 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 ) ) { 138 $post_has_changed = true; 139 break; 136 // Check whether post format meta has changed. 137 if ( ! $post_has_changed && ( $post_format = get_post_format( $post ) ) && ( $meta_keys = _wp_post_revision_meta_keys( $post_format ) ) ) { 138 foreach ( $meta_keys as $meta_key ) { 139 if ( get_post_meta( $post->ID, $meta_key, true ) != get_post_meta( $last_revision->ID, $meta_key, true ) ) { 140 $post_has_changed = true; 141 break; 142 } 140 143 } 141 144 } 142 145 … … 278 281 if ( $revision_id ) 279 282 do_action( '_wp_put_post_revision', $revision_id ); 280 283 281 // Save revisioned meta fields. 282 foreach ( _wp_post_revision_meta_keys() as $meta_key ) { 283 $meta_values = get_post_meta( $post_id, $meta_key ); 284 if ( false === $meta_values ) 285 continue; 284 // Save revisioned post formats meta. 285 if ( $post_format = get_post_format( $post_id ) ) { 286 if ( $meta_keys = _wp_post_revision_meta_keys( $post_format ) ) { 287 foreach ( $meta_keys as $meta_key ) { 288 // There can be only one meta field per $meta_key 289 $meta_value = get_post_meta( $post_id, $meta_key, true ); 286 290 287 // Use the underlying add_metadata vs add_post_meta to make sure 288 // 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 ); 291 // Don't add the meta if there is no data. 292 if ( empty( $meta_value ) ) 293 continue; 294 295 // Use the underlying add_metadata vs add_post_meta to make sure 296 // metadata is added to the revision post and not its parent. 297 add_metadata( 'post', $revision_id, $meta_key, $meta_value ); 298 } 299 } 300 // Save the current post format as revision meta 301 add_metadata( 'post', $revision_id, '_revision_format', $post_format ); 291 302 } 292 303 293 304 return $revision_id; … … 361 372 return false; 362 373 363 374 $update['ID'] = $revision['post_parent']; 364 365 375 $update = wp_slash( $update ); //since data is from db 366 376 367 // Restore revisioned meta fields.368 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 }377 378 377 $post_id = wp_update_post( $update ); 379 378 if ( is_wp_error( $post_id ) ) 380 379 return $post_id; … … 382 381 if ( $post_id ) 383 382 do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] ); 384 383 384 // Restore the post format 385 $post_format = get_post_meta( $revision['ID'], '_revision_format', true ); 386 set_post_format( $post_id, $post_format ); 387 388 // Restore revisioned post formats meta. 389 if ( $meta_keys = _wp_post_revision_meta_keys( $post_format ) ) { 390 foreach ( $meta_keys as $meta_key ) { 391 // There can be only one meta field per $meta_key 392 $meta_value = get_post_meta( $revision['ID'], $meta_key, true ); 393 394 if ( empty( $meta_value ) ) 395 continue; 396 397 update_post_meta( $post_id, $meta_key, $meta_value ); 398 } 399 } 400 385 401 $restore_details = array( 386 402 'restored_revision_id' => $revision_id, 387 403 'restored_by_user' => get_current_user_id(), 388 404 'restored_time' => time() 389 405 ); 406 390 407 update_post_meta( $post_id, '_post_restored_from', $restore_details ); 391 408 392 409 return $post_id; … … 530 547 */ 531 548 function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) { 532 549 $post = get_post(); 550 $meta_keys = array( 551 '_wp_format_url', 552 '_wp_format_quote', 553 '_wp_format_quote_source', 554 '_wp_format_image', 555 '_wp_format_gallery', 556 '_wp_format_audio', 557 '_wp_format_video' 558 ); 533 559 534 if ( $post->ID != $object_id || ! in_array( $meta_key, _wp_post_revision_meta_keys()) || 'revision' == $post->post_type )560 if ( $post->ID != $object_id || ! in_array( $meta_key, $meta_keys ) || 'revision' == $post->post_type ) 535 561 return $value; 536 562 537 563 $preview = wp_get_post_autosave( $post->ID );