Ticket #20299: 20299.diff
File 20299.diff, 5.5 KB (added by , 8 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.4.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 } … … 1844 1853 */ 1845 1854 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); 1846 1855 exit; 1847 } 1848 No newline at end of file 1856 } -
src/wp-admin/post.php
40 40 41 41 if ( isset( $_POST['deletepost'] ) ) 42 42 $action = 'delete'; 43 elseif ( isset( $_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )43 elseif ( isset( $_POST['wp-preview'] ) && 'dopreview' == $_POST['wp-preview'] ) { 44 44 $action = 'preview'; 45 /** 46 * Set DOING_PREVIEW during previews. 47 */ 48 if ( ! defined( 'DOING_PREVIEW' ) ) { 49 define( 'DOING_PREVIEW', true ); 50 } 51 } 45 52 46 53 $sendback = wp_get_referer(); 47 54 if ( ! $sendback || -
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 ID, 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 2 3 require( 'src/wp-content/plugins/wp-post-meta-revisions/wp-post-meta-revisions.php' ); 3 4 /** 4 5 * @group post 5 6 * @group revision … … 389 390 390 391 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 391 392 } 393 394 /** 395 * Preview changes on a published post makes all post meta "live" 396 * @ticket 20299 397 */ 398 function test_meta_stored_to_preview_autosave(){ 399 400 /** 401 * Set up a user for autosaves. 402 */ 403 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 404 $user = new WP_User( $editor_user_id ); 405 wp_set_current_user( $editor_user_id ); 406 407 $postd = array( 408 'post_author' => $editor_user_id, 409 'post_content' => 'the content', 410 'post_title' => 'the title', 411 'post_status' => 'publish', 412 ); 413 /** 414 * Insert a test post. 415 */ 416 $post_id = self::factory()->post->create( $postd ); 417 418 /** 419 * Add some post meta. 420 */ 421 update_post_meta( $post_id, 'publish_meta_test', 'original' ); 422 423 /** 424 * Revision the 'publish_meta_test' meta. 425 */ 426 add_filter( 'wp_post_revision_meta_keys', function( $keys ) { 427 $keys[] = 'publish_meta_test'; 428 return $keys; 429 } ); 430 431 /** 432 * Set up $_POST for autosave. 433 */ 434 $_POST['post_ID'] = $post_id; 435 $_POST['post_type'] = 'post'; 436 $_POST['post_title'] = 'new title'; 437 $_POST['publish_meta_test'] = 'new_value'; 438 439 /** 440 * Create an autosave 441 */ 442 $id = wp_create_post_autosave( $post_id ); 443 444 /** 445 * Verify the new meta value was autosaved. 446 */ 447 $revisioned_meta = get_post_meta( $id, 'publish_meta_test', true ); 448 $this->assertEquals( $revisioned_meta[0], 'new_value' ); 449 450 /** 451 * Clean up. 452 */ 453 wp_delete_post( $post_id ); 454 wp_delete_post( $id ); 455 wp_delete_post( $post_id ); 456 } 457 458 392 459 }