Ticket #20299: 20299.5.patch
File 20299.5.patch, 5.4 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/post.php
1669 1669 // _wp_put_post_revision() expects unescaped. 1670 1670 $post_data = wp_unslash( $post_data ); 1671 1671 1672 /** 1673 * Fires before an autosave is created. 1674 * 1675 * @since 4.4.0 1676 * 1677 * @param array $new_autosave Post array - the autosave that is about to be saved. 1678 */ 1679 do_action( 'wp_before_creating_autosave', $post_data ); 1680 1672 1681 // Otherwise create the new autosave as a special post revision 1673 1682 return _wp_put_post_revision( $post_data, true ); 1674 1683 } -
src/wp-admin/post.php
89 89 90 90 if ( isset( $_POST['deletepost'] ) ) 91 91 $action = 'delete'; 92 elseif ( isset( $_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )92 elseif ( isset( $_POST['wp-preview'] ) && 'dopreview' == $_POST['wp-preview'] ) { 93 93 $action = 'preview'; 94 /** 95 * Set DOING_PREVIEW during previews. 96 */ 97 if ( ! defined( 'DOING_PREVIEW' ) ) { 98 define( 'DOING_PREVIEW', true ); 99 } 100 } 94 101 95 102 $sendback = wp_get_referer(); 96 103 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
786 786 */ 787 787 function wp_just_in_time_script_localization() { 788 788 789 /** 790 * Pass some data to the autosave JavaScript: 791 * int autosaveL10n.autosaveInterval How frequently to autosave. 792 * int autosaveL10n.blog_id The current blog ID. 793 * array autosaveL10n.revisionedMetas The revisioned meta keys. 794 */ 789 795 wp_localize_script( 'autosave', 'autosaveL10n', array( 790 796 'autosaveInterval' => AUTOSAVE_INTERVAL, 791 'blog_id' => get_current_blog_id(), 797 'blog_id' => get_current_blog_id(), 798 'revisionedMetas' => WP_Post_Meta_Revisioning::_wp_post_revision_meta_keys(), 792 799 ) ); 793 800 794 801 } -
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 … … 399 400 400 401 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 401 402 } 403 404 /** 405 * Preview changes on a published post makes all post meta "live" 406 * @ticket 20299 407 */ 408 function test_meta_stored_to_preview_autosave(){ 409 410 /** 411 * Set up a user for autosaves. 412 */ 413 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 414 $user = new WP_User( $editor_user_id ); 415 wp_set_current_user( $editor_user_id ); 416 $postd = array( 417 'post_author' => $editor_user_id, 418 'post_content' => 'the content', 419 'post_title' => 'the title', 420 'post_status' => 'publish', 421 ); 422 /** 423 * Insert a test post. 424 */ 425 $post_id = wp_insert_post( $postd ); 426 427 /** 428 * Add some post meta. 429 */ 430 update_post_meta( $post_id, 'publish_meta_test', 'original' ); 431 432 /** 433 * Revision the 'publish_meta_test' meta. 434 */ 435 add_filter( 'wp_post_revision_meta_keys', function( $keys ) { 436 $keys[] = 'publish_meta_test'; 437 return $keys; 438 } ); 439 440 /** 441 * Set up $_POST for autosave. 442 */ 443 $_POST['post_ID'] = $post_id; 444 $_POST['post_type'] = 'post'; 445 $_POST['post_title'] = 'new title'; 446 $_POST['publish_meta_test'] = 'new_value'; 447 448 /** 449 * Create an autosave 450 */ 451 $id = wp_create_post_autosave( $post_id ); 452 453 /** 454 * Verify the new meta value was autosaved. 455 */ 456 $revisioned_meta = get_post_meta( $id, 'publish_meta_test', true ); 457 $this->assertEquals( $revisioned_meta[0], 'new_value' ); 458 459 /** 460 * Clean up. 461 */ 462 wp_delete_post( $post_id ); 463 wp_delete_post( $id ); 464 wp_delete_post( $post_id ); 465 } 466 467 402 468 }