Ticket #34560: 34560.9.diff
File 34560.9.diff, 5.9 KB (added by , 7 years ago) |
---|
-
wp-admin/edit-form-advanced.php
217 217 218 218 $publish_callback_args = null; 219 219 if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) { 220 $revisions = wp_get_post_revisions( $post_ID );221 220 221 222 require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' ); 223 $wp_revisions = new WP_PostRevisions( $post->ID ); 224 222 225 // 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 ) ); 226 if ( $wp_revisions->revisions_count > 1 ) { 227 $publish_callback_args = array( 228 'revisions_count' => $wp_revisions->revisions_count, 229 'revision_id' => $wp_revisions->last_revision_id, 230 ); 226 231 add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); 227 232 } 228 233 } -
wp-admin/includes/class-wp-revisions.php
1 <?php 2 /** 3 * WP_Revisions helper class. 4 */ 5 class WP_PostRevisions { 6 7 8 /** 9 * WP_PostRevisions constructor. 10 * @param $post_id - ID of the post in question 11 */ 12 public function __construct( $post_id ) { 13 $this->revisions_details = false; 14 $this->revisions_count = 0; 15 $this->last_revision_id = false; 16 $this->init( $post_id ); 17 } 18 19 /** 20 * Initialize this instance of the revisions class 21 * @param $post_id 22 */ 23 public function init( $post_id ) { 24 global $wpdb; 25 26 // Grab all the revision details we need to the Post Edit screen. 27 $this->revisions_details = $wpdb->get_results( 28 $wpdb->prepare( " 29 SELECT ID, post_author, post_date, post_date_gmt, 30 post_title, post_status, post_parent, post_modified, post_type 31 FROM $wpdb->posts 32 WHERE post_parent = %d 33 AND post_type = 'revision' 34 AND post_status = 'inherit' 35 ORDER BY post_date DESC, ID DESC", 36 $post_id 37 ) 38 ); 39 40 // Store the total revisions count. 41 $this->revisions_count = $wpdb->num_rows; 42 43 // Store the id of the last revision. 44 $this->last_revision_id = isset( $this->revisions_details[0] ) ? $this->revisions_details[0]->ID : false; 45 } 46 47 /** 48 * The number of revisions for the current object. 49 * @var int 50 */ 51 public $revisions_count; 52 53 /** 54 * Details about the revisions. 55 * @var Array 56 */ 57 public $revisions_details; 58 59 /** 60 * The id of the last revision. 61 * @var int 62 */ 63 public $last_revision_id; 64 } 65 66 -
wp-includes/post-template.php
1649 1649 * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. 1650 1650 */ 1651 1651 function wp_post_revision_title_expanded( $revision, $link = true ) { 1652 if ( !$revision = get_post( $revision ) )1653 return $revision;1654 1652 1655 1653 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1656 1654 return false; … … 1662 1660 $gravatar = get_avatar( $revision->post_author, 24 ); 1663 1661 1664 1662 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1665 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID) )1663 if ( $link && $link = admin_url( sprintf( 'revision.php?revision=%d&action=edit', $revision->ID ) ) ) 1666 1664 $date = "<a href='$link'>$date</a>"; 1667 1665 1668 1666 $revision_date_author = sprintf( … … 1710 1708 if ( ! $post = get_post( $post_id ) ) 1711 1709 return; 1712 1710 1711 if ( ! current_user_can( 'read_post', $post->ID ) ) 1712 return; 1713 1713 1714 // $args array with (parent, format, right, left, type) deprecated since 3.6 1714 1715 if ( is_array( $type ) ) { 1715 1716 $type = ! empty( $type['type'] ) ? $type['type'] : $type; 1716 1717 _deprecated_argument( __FUNCTION__, '3.6' ); 1717 1718 } 1718 1719 1719 if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) 1720 require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' ); 1721 $wp_revisions = new WP_PostRevisions( $post->ID ); 1722 1723 if ( ! $revisions = $wp_revisions->revisions_details ) { 1720 1724 return; 1725 } 1721 1726 1722 1727 $rows = ''; 1723 1728 foreach ( $revisions as $revision ) { 1724 if ( ! current_user_can( 'read_post', $revision->ID ) )1725 continue;1726 1727 1729 $is_autosave = wp_is_post_autosave( $revision ); 1728 1730 if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) 1729 1731 continue; -
wp-includes/revision.php
198 198 * @return WP_Post|false The autosaved data or false on failure or when no autosave exists. 199 199 */ 200 200 function wp_get_post_autosave( $post_id, $user_id = 0 ) { 201 $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );201 global $wpdb; 202 202 203 foreach ( $revisions as $revision ) { 204 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { 205 if ( $user_id && $user_id != $revision->post_author ) 206 continue; 203 // Contruct the autosave query. 204 $autosave_query = " 205 SELECT * 206 FROM $wpdb->posts 207 WHERE post_parent = %d 208 AND post_type = 'revision' 209 AND post_status = 'inherit' 210 AND post_name = %s 211 AND post_author = %s 212 LIMIT 1"; 207 213 208 return $revision; 209 } 214 $autosave_details = $wpdb->get_results( 215 $wpdb->prepare( 216 $autosave_query, 217 $post_id, 218 $post_id . '-autosave-v1', 219 ( 0 !== $user_id ) ? $user_id : get_current_user_id() 220 ) 221 ); 222 223 if ( empty( $autosave_details ) ) { 224 return false; 210 225 } 211 226 212 return false;227 return $autosave_details[0]; 213 228 } 214 229 215 230 /**