diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
index e8e0a84d45..a606d52bdf 100644
|
a
|
b
|
add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); |
| 380 | 380 | add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); |
| 381 | 381 | // Create a revision whenever a post is updated. |
| 382 | 382 | add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); |
| | 383 | add_action( 'new_to_publish', 'wp_save_post_revision', 10, 1 ); |
| 383 | 384 | add_action( 'publish_post', '_publish_post_hook', 5, 1 ); |
| 384 | 385 | add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); |
| 385 | 386 | add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); |
diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php
index 916c836f43..7b478bc0ae 100644
|
a
|
b
|
function wp_update_custom_css_post( $css, $args = array() ) { |
| 2002 | 2002 | } else { |
| 2003 | 2003 | $r = wp_insert_post( wp_slash( $post_data ), true ); |
| 2004 | 2004 | |
| 2005 | | if ( ! is_wp_error( $r ) ) { |
| 2006 | | if ( get_stylesheet() === $args['stylesheet'] ) { |
| 2007 | | set_theme_mod( 'custom_css_post_id', $r ); |
| 2008 | | } |
| 2009 | | |
| 2010 | | // Trigger creation of a revision. This should be removed once #30854 is resolved. |
| 2011 | | if ( 0 === count( wp_get_post_revisions( $r ) ) ) { |
| 2012 | | wp_save_post_revision( $r ); |
| 2013 | | } |
| | 2005 | if ( ! is_wp_error( $r ) && get_stylesheet() === $args['stylesheet'] ) { |
| | 2006 | set_theme_mod( 'custom_css_post_id', $r ); |
| 2014 | 2007 | } |
| 2015 | 2008 | } |
| 2016 | 2009 | |
diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php
index 95efe83578..0d05bad182 100644
|
a
|
b
|
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | 236 | $revisions = wp_get_post_revisions( $post_id ); |
| 237 | | $this->assertCount( 1, $revisions ); |
| | 237 | $this->assertCount( 2, $revisions ); |
| 238 | 238 | $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) ); |
| 239 | 239 | |
| 240 | 240 | foreach ( $revisions as $revision ) { |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | 269 | $revisions = wp_get_post_revisions( $post_id ); |
| 270 | | $this->assertCount( 1, $revisions ); |
| | 270 | $this->assertCount( 2, $revisions ); |
| 271 | 271 | foreach ( $revisions as $revision ) { |
| 272 | 272 | $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) ); |
| 273 | 273 | } |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 305 | 305 | |
| 306 | 306 | // Diff checks if you can read both left and right revisions. |
| 307 | 307 | $revisions = wp_get_post_revisions( $post_id ); |
| 308 | | $this->assertCount( 2, $revisions ); |
| | 308 | $this->assertCount( 3, $revisions ); |
| 309 | 309 | foreach ( $revisions as $revision ) { |
| 310 | 310 | $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); |
| 311 | 311 | } |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 345 | 345 | ); |
| 346 | 346 | |
| 347 | 347 | $revisions = wp_get_post_revisions( $post_id ); |
| 348 | | $this->assertCount( 1, $revisions ); |
| | 348 | $this->assertCount( 2, $revisions ); |
| 349 | 349 | $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) ); |
| 350 | 350 | |
| 351 | 351 | foreach ( $revisions as $revision ) { |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 392 | 392 | ); |
| 393 | 393 | |
| 394 | 394 | $revisions = wp_get_post_revisions( $post_id ); |
| 395 | | $this->assertCount( 1, $revisions ); |
| | 395 | $this->assertCount( 2, $revisions ); |
| 396 | 396 | foreach ( $revisions as $revision ) { |
| 397 | 397 | $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) ); |
| 398 | 398 | } |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 456 | 456 | ); |
| 457 | 457 | |
| 458 | 458 | $revisions = wp_get_post_revisions( $post_id ); |
| 459 | | $this->assertCount( 2, $revisions ); |
| | 459 | $this->assertCount( 3, $revisions ); |
| 460 | 460 | foreach ( $revisions as $revision ) { |
| 461 | 461 | $this->assertFalse( current_user_can( 'edit_post', $revision->post_parent ) ); |
| 462 | 462 | $this->assertFalse( current_user_can( 'edit_post', $revision->ID ) ); |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 517 | 517 | function test_wp_get_post_revisions_should_order_by_post_date() { |
| 518 | 518 | global $wpdb; |
| 519 | 519 | |
| | 520 | $now = time(); |
| | 521 | $date = date( 'Y-m-d H:i:s', $now ); |
| 520 | 522 | $post = self::factory()->post->create_and_get( |
| 521 | 523 | array( |
| 522 | | 'post_title' => 'some-post', |
| 523 | | 'post_type' => 'post', |
| 524 | | 'post_content' => 'some_content', |
| | 524 | 'post_title' => 'some-post', |
| | 525 | 'post_type' => 'post', |
| | 526 | 'post_content' => 'some_content', |
| | 527 | 'post_date' => $date, |
| | 528 | 'post_date_gmt' => $date |
| 525 | 529 | ) |
| 526 | 530 | ); |
| 527 | 531 | |
| 528 | 532 | $post = (array) $post; |
| | 533 | $revision_ids = array(); |
| | 534 | $revisions = wp_get_post_revisions( $post['ID'] ); |
| | 535 | $revision_ids[] = current( $revisions )->ID; |
| 529 | 536 | $post_revision_fields = _wp_post_revision_data( $post ); |
| 530 | 537 | $post_revision_fields = wp_slash( $post_revision_fields ); |
| 531 | 538 | |
| 532 | | $revision_ids = array(); |
| 533 | | $now = time(); |
| 534 | 539 | for ( $j = 1; $j < 3; $j++ ) { |
| 535 | 540 | // Manually modify dates to ensure they're different. |
| 536 | 541 | $date = gmdate( 'Y-m-d H:i:s', $now - ( $j * 10 ) ); |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 551 | 556 | * @ticket 26042 |
| 552 | 557 | */ |
| 553 | 558 | function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() { |
| 554 | | $post = self::factory()->post->create_and_get( |
| | 559 | $revision_ids = array(); |
| | 560 | $date = date( 'Y-m-d H:i:s', time() - 10 ); |
| | 561 | $post = self::factory()->post->create_and_get( |
| 555 | 562 | array( |
| 556 | | 'post_title' => 'some-post', |
| 557 | | 'post_type' => 'post', |
| 558 | | 'post_content' => 'some_content', |
| | 563 | 'post_title' => 'some-post', |
| | 564 | 'post_type' => 'post', |
| | 565 | 'post_content' => 'some_content', |
| | 566 | 'post_date' => $date, |
| | 567 | 'post_date_gmt' => $date |
| 559 | 568 | ) |
| 560 | 569 | ); |
| 561 | 570 | |
| 562 | 571 | $post = (array) $post; |
| 563 | 572 | $post_revision_fields = _wp_post_revision_data( $post ); |
| 564 | 573 | $post_revision_fields = wp_slash( $post_revision_fields ); |
| | 574 | $revisions = wp_get_post_revisions( $post['ID'] ); |
| | 575 | $revision_ids[] = current( $revisions )->ID; |
| 565 | 576 | |
| 566 | | $revision_ids = array(); |
| 567 | | $date = gmdate( 'Y-m-d H:i:s', time() - 10 ); |
| 568 | 577 | for ( $j = 1; $j < 3; $j++ ) { |
| 569 | 578 | // Manually modify dates to ensure they're the same. |
| 570 | 579 | $post_revision_fields['post_date'] = $date; |
| … |
… |
class Tests_Post_Revisions extends WP_UnitTestCase { |
| 581 | 590 | |
| 582 | 591 | $this->assertSame( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); |
| 583 | 592 | } |
| | 593 | |
| | 594 | /** |
| | 595 | * @ticket 30854 |
| | 596 | */ |
| | 597 | function test_wp_first_revision_is_not_lost() { |
| | 598 | $post = self::factory()->post->create_and_get( array( |
| | 599 | 'post_title' => 'some-post', |
| | 600 | 'post_type' => 'post', |
| | 601 | 'post_content' => 'Initial Content', |
| | 602 | ) ); |
| | 603 | |
| | 604 | wp_update_post( array( |
| | 605 | 'ID' => $post->ID, |
| | 606 | 'post_content' => 'Update #1', |
| | 607 | ) ); |
| | 608 | |
| | 609 | wp_update_post( array( |
| | 610 | 'ID' => $post->ID, |
| | 611 | 'post_content' => 'Update #2', |
| | 612 | ) ); |
| | 613 | |
| | 614 | $revisions = wp_get_post_revisions( $post->ID ); |
| | 615 | $earliest_revision = end( $revisions ); |
| | 616 | |
| | 617 | $this->assertEquals( 'Initial Content', $earliest_revision->post_content ); |
| | 618 | } |
| 584 | 619 | } |