From 9fe85b154e4137e1635a20672260f73f88d64502 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 6 Apr 2013 23:43:05 +0000 Subject: [PATCH] Revisions: move the call to _wp_upgrade_revisions_of_post() to edit-form-advanced.php, in the code block checking whether we should show the revisions postbox. See #16215 git-svn-id: http://core.svn.wordpress.org/trunk@23929 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 14 +++++++++++--- wp-admin/post.php | 3 --- wp-includes/revision.php | 27 +++++---------------------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index e5e244c40d..bfcbee0795 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -227,9 +227,17 @@ if ( post_type_supports($post_type, 'author') ) { add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); } -// We should aim to show the revisions metabox only when there are revisions. -if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status && count( wp_get_post_revisions( $post_ID ) ) > 1 ) - add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); +if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) { + $revisions = wp_get_post_revisions( $post_ID ); + + // Check if the revisions have been upgraded + if ( ! empty( $revisions ) && _wp_get_post_revision_version( reset( $revisions ) ) < 1 ) + _wp_upgrade_revisions_of_post( $post, $revisions ); + + // We should aim to show the revisions metabox only when there are revisions. + if ( count( $revisions ) > 1 ) + add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); +} do_action('add_meta_boxes', $post_type, $post); do_action('add_meta_boxes_' . $post_type, $post); diff --git a/wp-admin/post.php b/wp-admin/post.php index 5e6356ad60..d6b91d5a60 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -154,9 +154,6 @@ case 'edit': exit(); } - //upgrade any old bad revision data (#16215) - _wp_upgrade_revisions_of_post( $p ); - $post_type = $post->post_type; if ( 'post' == $post_type ) { $parent_file = "edit.php"; diff --git a/wp-includes/revision.php b/wp-includes/revision.php index 5aa82f0b5b..da51fd4705 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -586,38 +586,21 @@ function _wp_get_post_revision_version( $revision ) { } /** - * Upgrade the data + * Upgrade the revisions author, add the current post as a revision and set the revisions version to 1 * * @package WordPress * @subpackage Post_Revisions * @since 3.6.0 * - * @uses get_post() - * @uses post_type_supports() * @uses wp_get_post_revisions() * - * @param int|object $post_id Post ID or post object - * @return true if success, false if problems + * @param object $post Post object + * @param array $revisions Current revisions of the post + * @return bool true if the revisions were upgraded, false if problems */ -function _wp_upgrade_revisions_of_post( $post ) { +function _wp_upgrade_revisions_of_post( $post, $revisions ) { global $wpdb; - $post = get_post( $post ); - if ( ! $post ) - return false; - - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) - return false; - - $revisions = wp_get_post_revisions( $post->ID ); // array( 'order' => 'DESC', 'orderby' => 'date' ); // Always work from most recent to oldest - - if ( ! $first = reset( $revisions ) ) - return true; - - // Check if the revisions have already been updated - if ( preg_match( '/^\d+-(?:autosave|revision)-v\d+$/', $first->post_name ) ) - return true; - // Add post option exclusively $lock = "revision-upgrade-{$post->ID}"; $now = time();