Make WordPress Core

Ticket #34560: 34560.3.diff

File 34560.3.diff, 4.7 KB (added by adamsilverstein, 8 years ago)
  • src/wp-admin/edit-form-advanced.php

     
    217217
    218218$publish_callback_args = null;
    219219if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) {
    220         $revisions = wp_get_post_revisions( $post_ID );
    221 
     220        $revision_count = wp_get_post_revision_count( $post_id );
    222221        // We should aim to show the revisions metabox only when there are revisions.
    223         if ( count( $revisions ) > 1 ) {
    224                 reset( $revisions ); // Reset pointer for key()
    225                 $publish_callback_args = array( 'revisions_count' => count( $revisions ), 'revision_id' => key( $revisions ) );
     222        if ( $revision_count > 1 ) {
     223                $last_revision = wp_get_last_revision_id( $post_id );
     224                $publish_callback_args = array( 'revisions_count' => $revision_count, 'revision_id' => $last_revision ? $last_revision: 0 );
    226225                add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
    227226        }
    228227}
  • src/wp-includes/post-template.php

     
    16611661        $autosavef = __( '%1$s [Autosave]' );
    16621662        $currentf  = __( '%1$s [Current Revision]' );
    16631663
    1664         if ( !wp_is_post_revision( $revision ) )
     1664        if ( !wp_is_post_revision( $revision->ID ) )
    16651665                $revision_date_author = sprintf( $currentf, $revision_date_author );
    1666         elseif ( wp_is_post_autosave( $revision ) )
     1666        elseif ( wp_is_post_autosave( $revision->ID ) )
    16671667                $revision_date_author = sprintf( $autosavef, $revision_date_author );
    16681668
    16691669        /**
     
    17001700                _deprecated_argument( __FUNCTION__, '3.6' );
    17011701        }
    17021702
    1703         if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
     1703        if ( ! $revisions = wp_get_post_revisions_details( $post->ID ) )
    17041704                return;
    17051705
    17061706        $rows = '';
  • src/wp-includes/revision.php

     
    434434}
    435435
    436436/**
     437 * Returns the revision details of specified post.
     438 *
     439 * Data includes details about each revision on a post. Includes ID, post_author,
     440 * post_date, post_date_gmt, post_title, post_status, post_parent, and post_modified.
     441 *
     442 * @since 4.5.0
     443 *
     444 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     445 * @return array An array of revision details, or an empty array if post invalid.
     446 */
     447function wp_get_post_revisions_details( $post_id = 0, $args = null ) {
     448        global $wpdb;
     449
     450        $post = get_post( $post_id );
     451        if ( ! $post || empty( $post->ID ) ) {
     452                return array();
     453        }
     454
     455        $revision_details = $wpdb->get_results(
     456                $wpdb->prepare( "
     457                        SELECT ID, post_author, post_date, post_date_gmt, post_title, post_status, post_parent, post_modified
     458                        FROM $wpdb->posts
     459                        WHERE post_parent = %d
     460                        AND   post_type   = 'revision'
     461                        AND   post_status = 'inherit'
     462                        ORDER BY post_date DESC, ID DESC",
     463                        $post->ID
     464                )
     465        );
     466
     467        return $revision_details;
     468}
     469
     470/**
     471 * Return the count of revisions for a given post.
     472 *
     473 * @since 4.5.0
     474 *
     475 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     476 * @return int The count of revisions for this post, false if post invalid.
     477 */
     478function wp_get_post_revision_count( $post_id = 0 ) {
     479        global $wpdb;
     480
     481        $post = get_post( $post_id );
     482        if ( ! $post || empty( $post->ID ) ) {
     483                return false;
     484        }
     485
     486        $revision_count = intval(
     487                $wpdb->get_var(
     488                        $wpdb->prepare( "
     489                                SELECT COUNT(*)
     490                                FROM $wpdb->posts
     491                                WHERE post_parent = %d
     492                                AND   post_type   = 'revision'
     493                                AND   post_status = 'inherit'",
     494                        $post->ID
     495                        )
     496                )
     497        );
     498        return $revision_count;
     499}
     500
     501/**
     502 * Return the id of the last stored revision.
     503 *
     504 * @since 4.5.0
     505 *
     506 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     507 * @return int The id of the last stored revision for this post, false if post invalid.
     508 */
     509function wp_get_last_revision_id( $post_id = 0 ) {
     510        global $wpdb;
     511
     512        $post = get_post( $post_id );
     513        if ( ! $post || empty( $post->ID ) ) {
     514                return false;
     515        }
     516
     517        $last_revision_id = intval(
     518                $wpdb->get_var(
     519                        $wpdb->prepare( "
     520                                SELECT ID, post_date
     521                                FROM $wpdb->posts
     522                                WHERE post_parent = %d
     523                                AND   post_type   = 'revision'
     524                                AND   post_status = 'inherit'
     525                                ORDER BY post_date DESC, ID DESC
     526                                LIMIT 1",
     527                        $post->ID
     528                        )
     529                )
     530        );
     531        return $last_revision_id;
     532}
     533
     534/**
    437535 * Determine if revisions are enabled for a given post.
    438536 *
    439537 * @since 3.6.0