Ticket #20299: 20299.2.diff
File 20299.2.diff, 4.8 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/post.php
1699 1699 // _wp_put_post_revision() expects unescaped. 1700 1700 $post_data = wp_unslash( $post_data ); 1701 1701 1702 /** 1703 * Fires before an autosave is created. 1704 * 1705 * @since 4.5.0 1706 * 1707 * @param array $new_autosave Post array - the autosave that is about to be saved. 1708 */ 1709 do_action( 'wp_before_creating_autosave', $post_data ); 1710 1702 1711 // Otherwise create the new autosave as a special post revision 1703 1712 return _wp_put_post_revision( $post_data, true ); 1704 1713 } -
src/wp-includes/js/autosave.js
37 37 excerpt: $( '#excerpt' ).val() || '' 38 38 }; 39 39 40 /** 41 * Attach revisioned meta field values to the autosave data. 42 * 43 * Iterates thru the revisioned meta fields, searhing the DOM for elements 44 * with matching IDs, then storing the value as data[ID]. Enables inclusion 45 * of the revisioned post meta data as part of the autosave. 46 */ 47 $( autosaveL10n.revisionedMetas ).each( function( index, meta ) { 48 data[meta] = $( document.getElementById( meta ) ).val() || ''; 49 } ); 50 40 51 if ( type === 'local' ) { 41 52 return data; 42 53 } -
src/wp-includes/revision.php
509 509 510 510 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 511 511 512 /** 513 * When doing a preview, use the autosaved revisioned post meta. 514 */ 515 add_filter( 'get_post_metadata', array( WP_Post_Meta_Revisioning, '_wp_preview_meta_filter' ), 10, 4 ); 516 512 517 return $post; 513 518 } 514 519 -
src/wp-includes/script-loader.php
807 807 */ 808 808 function wp_just_in_time_script_localization() { 809 809 810 /** 811 * Pass some data to the autosave JavaScript: 812 * int autosaveL10n.autosaveInterval How frequently to autosave. 813 * int autosaveL10n.blog_id The current blog ID. 814 * array autosaveL10n.revisionedMetas The revisioned meta keys. 815 */ 810 816 wp_localize_script( 'autosave', 'autosaveL10n', array( 811 817 'autosaveInterval' => AUTOSAVE_INTERVAL, 812 'blog_id' => get_current_blog_id(), 818 'blog_id' => get_current_blog_id(), 819 'revisionedMetas' => WP_Post_Meta_Revisioning::_wp_post_revision_meta_keys(), 813 820 ) ); 814 821 815 822 } -
tests/phpunit/tests/post/revisions.php
1 1 <?php 2 // Require the post-meta-revisions plugin until its included in core. 3 require( 'src/wp-content/plugins/wp-post-meta-revisions/wp-post-meta-revisions.php' ); 2 4 3 5 /** 4 6 * @group post … … 389 391 390 392 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 391 393 } 394 395 /** 396 * Preview changes on a published post makes all post meta "live" 397 * @ticket 20299 398 */ 399 function test_meta_stored_to_preview_autosave(){ 400 401 /** 402 * Set up a user for autosaves. 403 */ 404 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 405 $user = new WP_User( $editor_user_id ); 406 wp_set_current_user( $editor_user_id ); 407 408 $postd = array( 409 'post_author' => $editor_user_id, 410 'post_content' => 'the content', 411 'post_title' => 'the title', 412 'post_status' => 'publish', 413 ); 414 /** 415 * Insert a test post. 416 */ 417 $post_id = self::factory()->post->create( $postd ); 418 419 /** 420 * Add some post meta. 421 */ 422 update_post_meta( $post_id, 'publish_meta_test', 'original' ); 423 424 /** 425 * Revision the 'publish_meta_test' meta. 426 */ 427 add_filter( 'wp_post_revision_meta_keys', function( $keys ) { 428 $keys[] = 'publish_meta_test'; 429 return $keys; 430 } ); 431 432 /** 433 * Set up $_POST for autosave. 434 */ 435 $_POST['post_ID'] = $post_id; 436 $_POST['post_type'] = 'post'; 437 $_POST['post_title'] = 'new title'; 438 $_POST['publish_meta_test'] = 'new_value'; 439 440 /** 441 * Create an autosave 442 */ 443 $id = wp_create_post_autosave( $post_id ); 444 445 /** 446 * Verify the new meta value was autosaved. 447 */ 448 $revisioned_meta = get_post_meta( $id, 'publish_meta_test', true ); 449 $this->assertEquals( $revisioned_meta[0], 'new_value' ); 450 451 /** 452 * Clean up. 453 */ 454 wp_delete_post( $post_id ); 455 wp_delete_post( $id ); 456 wp_delete_post( $post_id ); 457 } 392 458 }