diff --git src/wp-admin/includes/meta-boxes.php src/wp-admin/includes/meta-boxes.php
index 4584fff555..95513ae74e 100644
|
|
function register_and_do_post_meta_boxes( $post ) { |
1437 | 1437 | |
1438 | 1438 | $publish_callback_args = array( '__back_compat_meta_box' => true ); |
1439 | 1439 | if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== $post->post_status ) { |
1440 | | $revisions = wp_get_post_revisions( $post->ID ); |
| 1440 | $revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) ); |
1441 | 1441 | |
1442 | 1442 | // We should aim to show the revisions meta box only when there are revisions. |
1443 | 1443 | if ( count( $revisions ) > 1 ) { |
1444 | 1444 | reset( $revisions ); // Reset pointer for key(). |
1445 | 1445 | $publish_callback_args = array( |
1446 | 1446 | 'revisions_count' => count( $revisions ), |
1447 | | 'revision_id' => key( $revisions ), |
| 1447 | 'revision_id' => array_shift( $revisions ), |
1448 | 1448 | '__back_compat_meta_box' => true, |
1449 | 1449 | ); |
1450 | 1450 | add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) ); |
diff --git src/wp-includes/revision.php src/wp-includes/revision.php
index 9eb74b98a9..119bef816b 100644
|
|
function wp_save_post_revision( $post_id ) { |
221 | 221 | /** |
222 | 222 | * Retrieve the autosaved data of the specified post. |
223 | 223 | * |
224 | | * Returns a post object containing the information that was autosaved for the |
| 224 | * Returns an object containing the information that was autosaved for the |
225 | 225 | * specified post. If the optional $user_id is passed, returns the autosave for that user |
226 | 226 | * otherwise returns the latest autosave. |
227 | 227 | * |
… |
… |
function wp_save_post_revision( $post_id ) { |
232 | 232 | * @return WP_Post|false The autosaved data or false on failure or when no autosave exists. |
233 | 233 | */ |
234 | 234 | function wp_get_post_autosave( $post_id, $user_id = 0 ) { |
235 | | $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) ); |
| 235 | global $wpdb; |
236 | 236 | |
237 | | foreach ( $revisions as $revision ) { |
238 | | if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { |
239 | | if ( $user_id && $user_id != $revision->post_author ) { |
240 | | continue; |
241 | | } |
| 237 | $autosave_name = $post_id . '-autosave-v1'; |
| 238 | $user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null; |
| 239 | |
| 240 | // Construct the autosave query |
| 241 | $autosave_query = " |
| 242 | SELECT * |
| 243 | FROM $wpdb->posts |
| 244 | WHERE post_parent = %d |
| 245 | AND post_type = 'revision' |
| 246 | AND post_status = 'inherit' |
| 247 | AND post_name = %s " . $user_id_query . ' |
| 248 | ORDER BY post_date DESC |
| 249 | LIMIT 1'; |
| 250 | |
| 251 | $autosave = $wpdb->get_results( |
| 252 | $wpdb->prepare( |
| 253 | $autosave_query, |
| 254 | $post_id, |
| 255 | $autosave_name |
| 256 | ) |
| 257 | ); |
242 | 258 | |
243 | | return $revision; |
244 | | } |
| 259 | if ( ! $autosave ) { |
| 260 | return false; |
245 | 261 | } |
246 | 262 | |
247 | | return false; |
| 263 | return $autosave[0]; |
248 | 264 | } |
249 | 265 | |
250 | 266 | /** |
diff --git tests/phpunit/tests/ajax/CustomizeManager.php tests/phpunit/tests/ajax/CustomizeManager.php
index 1126e8e667..1ed20de31f 100644
|
|
class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { |
472 | 472 | $this->assertTrue( $this->_last_response_parsed['success'] ); |
473 | 473 | $this->assertEquals( 'draft', $this->_last_response_parsed['data']['changeset_status'] ); |
474 | 474 | $autosave_revision = wp_get_post_autosave( $post_id ); |
475 | | $this->assertInstanceOf( 'WP_Post', $autosave_revision ); |
| 475 | $this->assertInstanceOf( 'stdClass', $autosave_revision ); |
476 | 476 | |
477 | 477 | $this->assertContains( 'New Site Title', get_post( $post_id )->post_content ); |
478 | 478 | $this->assertContains( 'Autosaved Site Title', $autosave_revision->post_content ); |
… |
… |
class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { |
699 | 699 | ); |
700 | 700 | $this->assertNotWPError( $r ); |
701 | 701 | $autosave_revision = wp_get_post_autosave( $wp_customize->changeset_post_id() ); |
702 | | $this->assertInstanceOf( 'WP_Post', $autosave_revision ); |
| 702 | $this->assertInstanceOf( 'stdClass', $autosave_revision ); |
703 | 703 | $this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content ); |
704 | 704 | $this->assertContains( 'Bar', $autosave_revision->post_content ); |
705 | 705 | |
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php
index 00dcd333c6..dda069dfc1 100644
|
|
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
1891 | 1891 | |
1892 | 1892 | // Verify that autosave happened. |
1893 | 1893 | $autosave_revision = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); |
1894 | | $this->assertInstanceOf( 'WP_Post', $autosave_revision ); |
| 1894 | $this->assertInstanceOf( 'stdClass', $autosave_revision ); |
1895 | 1895 | $this->assertContains( 'Draft Title', get_post( $changeset_post_id )->post_content ); |
1896 | 1896 | $this->assertContains( 'Autosave Title', $autosave_revision->post_content ); |
1897 | 1897 | } |