| | 341 | |
| | 342 | /** |
| | 343 | * Preview changes on a published post makes all post meta "live" |
| | 344 | * @ticket 20299 |
| | 345 | */ |
| | 346 | function test_meta_stored_to_preview_autosave(){ |
| | 347 | |
| | 348 | $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); |
| | 349 | |
| | 350 | $user = new WP_User( $editor_user_id ); |
| | 351 | |
| | 352 | $postd = array( |
| | 353 | 'post_author' => $editor_user_id, |
| | 354 | 'post_content' => 'the content', |
| | 355 | 'post_title' => 'the title', |
| | 356 | 'post_status' => 'publish', |
| | 357 | ); |
| | 358 | |
| | 359 | wp_set_current_user( $editor_user_id ); |
| | 360 | $post_id = wp_insert_post( $postd ); |
| | 361 | |
| | 362 | add_filter( 'wp_post_revision_meta_keys', function( $keys ) { |
| | 363 | $keys[] = 'publish_meta_test'; |
| | 364 | return $keys; |
| | 365 | } ); |
| | 366 | |
| | 367 | // Add some post meta |
| | 368 | update_post_meta( $post_id, 'publish_meta_test', 'original' ); |
| | 369 | |
| | 370 | // These two $_POST variables are required for wp_create_post_autosave |
| | 371 | $_POST['post_ID'] = $post_id; |
| | 372 | $_POST['post_type'] = 'post'; |
| | 373 | |
| | 374 | // Create an autosave |
| | 375 | $id = wp_create_post_autosave( $post_id ); |
| | 376 | |
| | 377 | // Test that the preview meta is not set |
| | 378 | $this->assertEquals( get_post_meta( $id, 'publish_meta_test', true ), 'original' ); |
| | 379 | |
| | 380 | wp_delete_post( $post_id ); |
| | 381 | wp_delete_post( $id ); |
| | 382 | |
| | 383 | |
| | 384 | |
| | 385 | wp_delete_post( $post_id ); |
| | 386 | } |
| | 387 | |
| | 388 | |