52 if ( empty( $compare_to->post_title ) ) |
53 if ( empty( $compare_to->post_title ) ) |
53 $compare_to->post_title = __( '(no title)' ); |
54 $compare_to->post_title = __( '(no title)' ); |
54 |
55 |
55 $return = array(); |
56 $return = array(); |
56 |
57 |
57 foreach ( _wp_post_revision_fields() as $field => $name ) { |
58 foreach ( _wp_post_revision_fields( $post ) as $field => $name ) { |
58 /** |
59 /** |
59 * Contextually filter a post revision field. |
60 * Contextually filter a post revision field. |
60 * |
61 * |
61 * The dynamic portion of the hook name, `$field`, corresponds to each of the post |
62 * The dynamic portion of the hook name, `$field`, corresponds to each of the post |
62 * fields of the revision object being iterated over in a foreach statement. |
63 * fields of the revision object being iterated over in a foreach statement. |
67 * @param string $field The current revision field. |
68 * @param string $field The current revision field. |
68 * @param WP_Post $compare_from The revision post object to compare to or from. |
69 * @param WP_Post $compare_from The revision post object to compare to or from. |
69 * @param string null The context of whether the current revision is the old |
70 * @param string null The context of whether the current revision is the old |
70 * or the new one. Values are 'to' or 'from'. |
71 * or the new one. Values are 'to' or 'from'. |
71 */ |
72 */ |
72 $content_from = $compare_from ? apply_filters( "_wp_post_revision_field_$field", $compare_from->$field, $field, $compare_from, 'from' ) : ''; |
73 $content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : ''; |
73 |
74 |
74 /** This filter is documented in wp-admin/includes/revision.php */ |
75 /** This filter is documented in wp-admin/includes/revision.php */ |
75 $content_to = apply_filters( "_wp_post_revision_field_$field", $compare_to->$field, $field, $compare_to, 'to' ); |
76 $content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' ); |
76 |
77 |
77 $args = array( |
78 $args = array( |
78 'show_split_view' => true |
79 'show_split_view' => true |
79 ); |
80 ); |
80 |
81 |
81 /** |
82 /** |
82 * Filter revisions text diff options. |
83 * Filters revisions text diff options. |
83 * |
84 * |
84 * Filter the options passed to {@see wp_text_diff()} when viewing a post revision. |
85 * Filters the options passed to wp_text_diff() when viewing a post revision. |
85 * |
86 * |
86 * @since 4.1.0 |
87 * @since 4.1.0 |
87 * |
88 * |
88 * @param array $args { |
89 * @param array $args { |
89 * Associative array of options to pass to {@see wp_text_diff()}. |
90 * Associative array of options to pass to wp_text_diff(). |
90 * |
91 * |
91 * @type bool $show_split_view True for split view (two columns), false for |
92 * @type bool $show_split_view True for split view (two columns), false for |
92 * un-split view (single column). Default true. |
93 * un-split view (single column). Default true. |
93 * } |
94 * } |
94 * @param string $field The current revision field. |
95 * @param string $field The current revision field. |
163 $can_restore = current_user_can( 'edit_post', $post->ID ); |
164 $can_restore = current_user_can( 'edit_post', $post->ID ); |
164 $current_id = false; |
165 $current_id = false; |
165 |
166 |
166 foreach ( $revisions as $revision ) { |
167 foreach ( $revisions as $revision ) { |
167 $modified = strtotime( $revision->post_modified ); |
168 $modified = strtotime( $revision->post_modified ); |
168 $modified_gmt = strtotime( $revision->post_modified_gmt ); |
169 $modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' ); |
169 if ( $can_restore ) { |
170 if ( $can_restore ) { |
170 $restore_link = str_replace( '&', '&', wp_nonce_url( |
171 $restore_link = str_replace( '&', '&', wp_nonce_url( |
171 add_query_arg( |
172 add_query_arg( |
172 array( 'revision' => $revision->ID, |
173 array( 'revision' => $revision->ID, |
173 'action' => 'restore' ), |
174 'action' => 'restore' ), |
197 } |
198 } |
198 } elseif ( $current ) { |
199 } elseif ( $current ) { |
199 $current_id = $revision->ID; |
200 $current_id = $revision->ID; |
200 } |
201 } |
201 |
202 |
202 $revisions[ $revision->ID ] = array( |
203 $revisions_data = array( |
203 'id' => $revision->ID, |
204 'id' => $revision->ID, |
204 'title' => get_the_title( $post->ID ), |
205 'title' => get_the_title( $post->ID ), |
205 'author' => $authors[ $revision->post_author ], |
206 'author' => $authors[ $revision->post_author ], |
206 'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ), |
207 'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ), |
207 'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ), |
208 'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ), |
208 'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ), |
209 'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ), |
209 'autosave' => $autosave, |
210 'autosave' => $autosave, |
210 'current' => $current, |
211 'current' => $current, |
211 'restoreUrl' => $can_restore ? $restore_link : false, |
212 'restoreUrl' => $can_restore ? $restore_link : false, |
212 ); |
213 ); |
|
214 |
|
215 /** |
|
216 * Filters the array of revisions used on the revisions screen. |
|
217 * |
|
218 * @since 4.4.0 |
|
219 * |
|
220 * @param array $revisions_data { |
|
221 * The bootstrapped data for the revisions screen. |
|
222 * |
|
223 * @type int $id Revision ID. |
|
224 * @type string $title Title for the revision's parent WP_Post object. |
|
225 * @type int $author Revision post author ID. |
|
226 * @type string $date Date the revision was modified. |
|
227 * @type string $dateShort Short-form version of the date the revision was modified. |
|
228 * @type string $timeAgo GMT-aware amount of time ago the revision was modified. |
|
229 * @type bool $autosave Whether the revision is an autosave. |
|
230 * @type bool $current Whether the revision is both not an autosave and the post |
|
231 * modified date matches the revision modified date (GMT-aware). |
|
232 * @type bool|false $restoreUrl URL if the revision can be restored, false otherwise. |
|
233 * } |
|
234 * @param WP_Post $revision The revision's WP_Post object. |
|
235 * @param WP_Post $post The revision's parent WP_Post object. |
|
236 */ |
|
237 $revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post ); |
213 } |
238 } |
214 |
239 |
215 /** |
240 /** |
216 * If we only have one revision, the initial revision is missing; This happens |
241 * If we only have one revision, the initial revision is missing; This happens |
217 * when we have an autsosave and the user has clicked 'View the Autosave' |
242 * when we have an autsosave and the user has clicked 'View the Autosave' |