Ticket #20299: 20299-3.patch
File 20299-3.patch, 5.8 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/post.php
1574 1574 } 1575 1575 1576 1576 /** 1577 * Fires before an autosave is stored.1577 * Fires before an autosave is updated. 1578 1578 * 1579 1579 * @since 4.1.0 1580 1580 * 1581 1581 * @param array $new_autosave Post array - the autosave that is about to be saved. 1582 1582 */ 1583 do_action( 'wp_ creating_autosave', $new_autosave );1583 do_action( 'wp_updating_autosave', $new_autosave ); 1584 1584 1585 1585 return wp_update_post( $new_autosave ); 1586 1586 } … … 1588 1588 // _wp_put_post_revision() expects unescaped. 1589 1589 $post_data = wp_unslash( $post_data ); 1590 1590 1591 /** 1592 * Fires before an autosave is created. 1593 * 1594 * @since 4.2.0 1595 * 1596 * @param array $new_autosave Post array - the autosave that is about to be saved. 1597 */ 1598 do_action( 'wp_creating_autosave', $post_data ); 1599 1591 1600 // Otherwise create the new autosave as a special post revision 1592 1601 return _wp_put_post_revision( $post_data, true ); 1593 1602 } -
src/wp-admin/post.php
84 84 85 85 if ( isset( $_POST['deletepost'] ) ) 86 86 $action = 'delete'; 87 elseif ( isset( $_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )87 elseif ( isset( $_POST['wp-preview'] ) && 'dopreview' == $_POST['wp-preview'] ) { 88 88 $action = 'preview'; 89 /** 90 * Set DOING_PREVIEW during previews. 91 */ 92 if ( ! defined( 'DOING_PREVIEW' ) ) { 93 define( 'DOING_PREVIEW', true ); 94 } 95 } 89 96 90 97 $sendback = wp_get_referer(); 91 98 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
505 505 $post->post_excerpt = $preview->post_excerpt; 506 506 507 507 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 508 /** 509 * When doing a preview, use the autosaved revisioned post meta. 510 */ 511 add_filter( 'get_post_metadata', array( WP_Post_Meta_Revisioning, '_wp_preview_meta_filter' ), 10, 4 ); 508 512 509 513 return $post; 510 514 } -
src/wp-includes/script-loader.php
702 702 */ 703 703 function wp_just_in_time_script_localization() { 704 704 705 /** 706 * Pass some data to the autosave JavaScript: 707 * int autosaveL10n.autosaveInterval How frequently to autosave. 708 * int autosaveL10n.blog_id The current blog ID. 709 * array autosaveL10n.revisionedMetas The revisioned meta keys. 710 */ 705 711 wp_localize_script( 'autosave', 'autosaveL10n', array( 706 712 'autosaveInterval' => AUTOSAVE_INTERVAL, 707 713 'blog_id' => get_current_blog_id(), 714 'revisionedMetas' => WP_Post_Meta_Revisioning::_wp_post_revision_meta_keys(), 708 715 ) ); 709 716 710 717 } -
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 }