Make WordPress Core

Ticket #34560: 34560.diff

File 34560.diff, 2.8 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 && $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/revision.php

     
    434434}
    435435
    436436/**
     437 * Return the count of revisions for a given post.
     438 *
     439 * @since 4.5.0
     440 *
     441 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     442 * @return int The count of revisions for this post, false if post invalid.
     443 */
     444function wp_get_post_revision_count( $post_id = 0 ) {
     445        global $wpdb;
     446
     447        $post = get_post( $post_id );
     448        if ( ! $post || empty( $post->ID ) ) {
     449                return false;
     450        }
     451
     452        $revision_count = intval(
     453                $wpdb->get_var(
     454                        $wpdb->prepare( "
     455                                SELECT COUNT(1)
     456                                FROM $wpdb->posts
     457                                WHERE post_parent = %d
     458                                AND   post_type   = 'revision'
     459                                AND   post_status = 'inherit'",
     460                        $post->ID
     461                        )
     462                )
     463        );
     464        return $revision_count;
     465}
     466
     467/**
     468 * Return the id of the last stored revision.
     469 *
     470 * @since 4.5.0
     471 *
     472 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     473 * @return int The id of the last stored revision for this post, false if post invalid.
     474 */
     475function wp_get_last_revision_id( $post_id = 0 ) {
     476        global $wpdb;
     477
     478        $post = get_post( $post_id );
     479        if ( ! $post || empty( $post->ID ) ) {
     480                return false;
     481        }
     482
     483        $last_revision_id = intval(
     484                $wpdb->get_var(
     485                        $wpdb->prepare( "
     486                                SELECT ID, post_date
     487                                FROM $wpdb->posts
     488                                WHERE post_parent = %d
     489                                AND   post_type   = 'revision'
     490                                AND   post_status = 'inherit'
     491                                ORDER BY post_date DESC, ID DESC
     492                                LIMIT 1",
     493                        $post->ID
     494                        )
     495                )
     496        );
     497        return $last_revision_id;
     498}
     499
     500/**
    437501 * Determine if revisions are enabled for a given post.
    438502 *
    439503 * @since 3.6.0