author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Administration Revisions API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.6.0 |
0 | 8 |
*/ |
9 |
||
10 |
/** |
|
11 |
* Get the revision UI diff. |
|
12 |
* |
|
13 |
* @since 3.6.0 |
|
14 |
* |
|
16 | 15 |
* @param WP_Post|int $post The post object or post ID. |
16 |
* @param int $compare_from The revision ID to compare from. |
|
17 |
* @param int $compare_to The revision ID to come to. |
|
18 | 18 |
* @return array|false Associative array of a post's revisioned fields and their diffs. |
19 | 19 |
* Or, false on failure. |
0 | 20 |
*/ |
21 |
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { |
|
16 | 22 |
$post = get_post( $post ); |
23 |
if ( ! $post ) { |
|
0 | 24 |
return false; |
9 | 25 |
} |
0 | 26 |
|
27 |
if ( $compare_from ) { |
|
16 | 28 |
$compare_from = get_post( $compare_from ); |
29 |
if ( ! $compare_from ) { |
|
0 | 30 |
return false; |
9 | 31 |
} |
0 | 32 |
} else { |
33 |
// If we're dealing with the first revision... |
|
34 |
$compare_from = false; |
|
35 |
} |
|
36 |
||
16 | 37 |
$compare_to = get_post( $compare_to ); |
38 |
if ( ! $compare_to ) { |
|
0 | 39 |
return false; |
9 | 40 |
} |
0 | 41 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
43 |
* If comparing revisions, make sure we are dealing with the right post parent. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
44 |
* The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
45 |
*/ |
9 | 46 |
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) { |
0 | 47 |
return false; |
9 | 48 |
} |
49 |
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) { |
|
0 | 50 |
return false; |
9 | 51 |
} |
0 | 52 |
|
53 |
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) { |
|
9 | 54 |
$temp = $compare_from; |
0 | 55 |
$compare_from = $compare_to; |
9 | 56 |
$compare_to = $temp; |
0 | 57 |
} |
58 |
||
16 | 59 |
// Add default title if title field is empty. |
9 | 60 |
if ( $compare_from && empty( $compare_from->post_title ) ) { |
0 | 61 |
$compare_from->post_title = __( '(no title)' ); |
9 | 62 |
} |
63 |
if ( empty( $compare_to->post_title ) ) { |
|
0 | 64 |
$compare_to->post_title = __( '(no title)' ); |
9 | 65 |
} |
0 | 66 |
|
67 |
$return = array(); |
|
68 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) { |
0 | 70 |
/** |
71 |
* Contextually filter a post revision field. |
|
72 |
* |
|
18 | 73 |
* The dynamic portion of the hook name, `$field`, corresponds to a name of a |
74 |
* field of the revision object. |
|
75 |
* |
|
76 |
* Possible hook names include: |
|
77 |
* |
|
78 |
* - `_wp_post_revision_field_post_title` |
|
79 |
* - `_wp_post_revision_field_post_content` |
|
80 |
* - `_wp_post_revision_field_post_excerpt` |
|
0 | 81 |
* |
82 |
* @since 3.6.0 |
|
83 |
* |
|
16 | 84 |
* @param string $revision_field The current revision field to compare to or from. |
85 |
* @param string $field The current revision field. |
|
86 |
* @param WP_Post $compare_from The revision post object to compare to or from. |
|
87 |
* @param string $context The context of whether the current revision is the old |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
* or the new one. Either 'to' or 'from'. |
0 | 89 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : ''; |
0 | 91 |
|
92 |
/** This filter is documented in wp-admin/includes/revision.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' ); |
0 | 94 |
|
5 | 95 |
$args = array( |
9 | 96 |
'show_split_view' => true, |
18 | 97 |
'title_left' => __( 'Removed' ), |
98 |
'title_right' => __( 'Added' ), |
|
5 | 99 |
); |
100 |
||
101 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* Filters revisions text diff options. |
5 | 103 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* Filters the options passed to wp_text_diff() when viewing a post revision. |
5 | 105 |
* |
106 |
* @since 4.1.0 |
|
107 |
* |
|
108 |
* @param array $args { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* Associative array of options to pass to wp_text_diff(). |
5 | 110 |
* |
111 |
* @type bool $show_split_view True for split view (two columns), false for |
|
112 |
* un-split view (single column). Default true. |
|
113 |
* } |
|
114 |
* @param string $field The current revision field. |
|
115 |
* @param WP_Post $compare_from The revision post to compare from. |
|
116 |
* @param WP_Post $compare_to The revision post to compare to. |
|
117 |
*/ |
|
118 |
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to ); |
|
119 |
||
120 |
$diff = wp_text_diff( $content_from, $content_to, $args ); |
|
0 | 121 |
|
122 |
if ( ! $diff && 'post_title' === $field ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
* It's a better user experience to still show the Title, even if it didn't change. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
* No, you didn't see this. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
*/ |
0 | 127 |
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>'; |
9 | 128 |
|
129 |
// In split screen mode, show the title before/after side by side. |
|
130 |
if ( true === $args['show_split_view'] ) { |
|
131 |
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>'; |
|
132 |
} else { |
|
133 |
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td>'; |
|
134 |
||
135 |
// In single column mode, only show the title once if unchanged. |
|
136 |
if ( $compare_from->post_title !== $compare_to->post_title ) { |
|
137 |
$diff .= '</tr><tr><td>' . esc_html( $compare_to->post_title ) . '</td>'; |
|
138 |
} |
|
139 |
} |
|
140 |
||
0 | 141 |
$diff .= '</tr></tbody>'; |
142 |
$diff .= '</table>'; |
|
143 |
} |
|
144 |
||
145 |
if ( $diff ) { |
|
146 |
$return[] = array( |
|
9 | 147 |
'id' => $field, |
0 | 148 |
'name' => $name, |
149 |
'diff' => $diff, |
|
150 |
); |
|
151 |
} |
|
152 |
} |
|
5 | 153 |
|
154 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* Filters the fields displayed in the post revision diff UI. |
5 | 156 |
* |
157 |
* @since 4.1.0 |
|
158 |
* |
|
9 | 159 |
* @param array[] $return Array of revision UI fields. Each item is an array of id, name, and diff. |
5 | 160 |
* @param WP_Post $compare_from The revision post to compare from. |
161 |
* @param WP_Post $compare_to The revision post to compare to. |
|
162 |
*/ |
|
163 |
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to ); |
|
0 | 164 |
} |
165 |
||
166 |
/** |
|
167 |
* Prepare revisions for JavaScript. |
|
168 |
* |
|
169 |
* @since 3.6.0 |
|
170 |
* |
|
16 | 171 |
* @param WP_Post|int $post The post object or post ID. |
172 |
* @param int $selected_revision_id The selected revision ID. |
|
173 |
* @param int $from Optional. The revision ID to compare from. |
|
0 | 174 |
* @return array An associative array of revision data and related settings. |
175 |
*/ |
|
176 |
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) { |
|
9 | 177 |
$post = get_post( $post ); |
5 | 178 |
$authors = array(); |
0 | 179 |
$now_gmt = time(); |
180 |
||
9 | 181 |
$revisions = wp_get_post_revisions( |
182 |
$post->ID, |
|
183 |
array( |
|
184 |
'order' => 'ASC', |
|
185 |
'check_enabled' => false, |
|
186 |
) |
|
187 |
); |
|
0 | 188 |
// If revisions are disabled, we only want autosaves and the current post. |
189 |
if ( ! wp_revisions_enabled( $post ) ) { |
|
190 |
foreach ( $revisions as $revision_id => $revision ) { |
|
9 | 191 |
if ( ! wp_is_post_autosave( $revision ) ) { |
0 | 192 |
unset( $revisions[ $revision_id ] ); |
9 | 193 |
} |
0 | 194 |
} |
195 |
$revisions = array( $post->ID => $post ) + $revisions; |
|
196 |
} |
|
197 |
||
198 |
$show_avatars = get_option( 'show_avatars' ); |
|
199 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
update_post_author_caches( $revisions ); |
0 | 201 |
|
202 |
$can_restore = current_user_can( 'edit_post', $post->ID ); |
|
9 | 203 |
$current_id = false; |
0 | 204 |
|
205 |
foreach ( $revisions as $revision ) { |
|
9 | 206 |
$modified = strtotime( $revision->post_modified ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' ); |
0 | 208 |
if ( $can_restore ) { |
9 | 209 |
$restore_link = str_replace( |
210 |
'&', |
|
211 |
'&', |
|
212 |
wp_nonce_url( |
|
213 |
add_query_arg( |
|
214 |
array( |
|
215 |
'revision' => $revision->ID, |
|
216 |
'action' => 'restore', |
|
217 |
), |
|
0 | 218 |
admin_url( 'revision.php' ) |
9 | 219 |
), |
220 |
"restore-post_{$revision->ID}" |
|
221 |
) |
|
222 |
); |
|
0 | 223 |
} |
224 |
||
225 |
if ( ! isset( $authors[ $revision->post_author ] ) ) { |
|
226 |
$authors[ $revision->post_author ] = array( |
|
9 | 227 |
'id' => (int) $revision->post_author, |
0 | 228 |
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '', |
9 | 229 |
'name' => get_the_author_meta( 'display_name', $revision->post_author ), |
0 | 230 |
); |
231 |
} |
|
232 |
||
233 |
$autosave = (bool) wp_is_post_autosave( $revision ); |
|
9 | 234 |
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt; |
0 | 235 |
if ( $current && ! empty( $current_id ) ) { |
236 |
// If multiple revisions have the same post_modified_gmt, highest ID is current. |
|
237 |
if ( $current_id < $revision->ID ) { |
|
238 |
$revisions[ $current_id ]['current'] = false; |
|
9 | 239 |
$current_id = $revision->ID; |
0 | 240 |
} else { |
241 |
$current = false; |
|
242 |
} |
|
243 |
} elseif ( $current ) { |
|
244 |
$current_id = $revision->ID; |
|
245 |
} |
|
246 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
$revisions_data = array( |
0 | 248 |
'id' => $revision->ID, |
249 |
'title' => get_the_title( $post->ID ), |
|
250 |
'author' => $authors[ $revision->post_author ], |
|
5 | 251 |
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ), |
252 |
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ), |
|
16 | 253 |
/* translators: %s: Human-readable time difference. */ |
0 | 254 |
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ), |
255 |
'autosave' => $autosave, |
|
256 |
'current' => $current, |
|
257 |
'restoreUrl' => $can_restore ? $restore_link : false, |
|
258 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
* Filters the array of revisions used on the revisions screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* @param array $revisions_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
* The bootstrapped data for the revisions screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* @type int $id Revision ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
* @type string $title Title for the revision's parent WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
* @type int $author Revision post author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
* @type string $date Date the revision was modified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* @type string $dateShort Short-form version of the date the revision was modified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
* @type string $timeAgo GMT-aware amount of time ago the revision was modified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
* @type bool $autosave Whether the revision is an autosave. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
* @type bool $current Whether the revision is both not an autosave and the post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
* modified date matches the revision modified date (GMT-aware). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* @param WP_Post $revision The revision's WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* @param WP_Post $post The revision's parent WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post ); |
0 | 283 |
} |
284 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
285 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
* If we only have one revision, the initial revision is missing. This happens |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
* when we have an autosave and the user has clicked 'View the Autosave'. |
5 | 288 |
*/ |
18 | 289 |
if ( 1 === count( $revisions ) ) { |
5 | 290 |
$revisions[ $post->ID ] = array( |
291 |
'id' => $post->ID, |
|
292 |
'title' => get_the_title( $post->ID ), |
|
18 | 293 |
'author' => $authors[ $revision->post_author ], |
5 | 294 |
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ), |
295 |
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ), |
|
16 | 296 |
/* translators: %s: Human-readable time difference. */ |
5 | 297 |
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ), |
298 |
'autosave' => false, |
|
299 |
'current' => true, |
|
300 |
'restoreUrl' => false, |
|
301 |
); |
|
9 | 302 |
$current_id = $post->ID; |
5 | 303 |
} |
304 |
||
305 |
/* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
* If a post has been saved since the latest revision (no revisioned fields |
5 | 307 |
* were changed), we may not have a "current" revision. Mark the latest |
308 |
* revision as "current". |
|
309 |
*/ |
|
0 | 310 |
if ( empty( $current_id ) ) { |
311 |
if ( $revisions[ $revision->ID ]['autosave'] ) { |
|
312 |
$revision = end( $revisions ); |
|
313 |
while ( $revision['autosave'] ) { |
|
314 |
$revision = prev( $revisions ); |
|
315 |
} |
|
316 |
$current_id = $revision['id']; |
|
317 |
} else { |
|
318 |
$current_id = $revision->ID; |
|
319 |
} |
|
320 |
$revisions[ $current_id ]['current'] = true; |
|
321 |
} |
|
322 |
||
5 | 323 |
// Now, grab the initial diff. |
0 | 324 |
$compare_two_mode = is_numeric( $from ); |
325 |
if ( ! $compare_two_mode ) { |
|
16 | 326 |
$found = array_search( $selected_revision_id, array_keys( $revisions ), true ); |
0 | 327 |
if ( $found ) { |
328 |
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) ); |
|
329 |
$from = reset( $from ); |
|
330 |
} else { |
|
331 |
$from = 0; |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
$from = absint( $from ); |
|
336 |
||
9 | 337 |
$diffs = array( |
338 |
array( |
|
339 |
'id' => $from . ':' . $selected_revision_id, |
|
340 |
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ), |
|
341 |
), |
|
342 |
); |
|
0 | 343 |
|
344 |
return array( |
|
9 | 345 |
'postId' => $post->ID, |
346 |
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), |
|
347 |
'revisionData' => array_values( $revisions ), |
|
348 |
'to' => $selected_revision_id, |
|
349 |
'from' => $from, |
|
350 |
'diffData' => $diffs, |
|
351 |
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ), |
|
16 | 352 |
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed. |
9 | 353 |
'revisionIds' => array_keys( $revisions ), |
0 | 354 |
); |
355 |
} |
|
5 | 356 |
|
357 |
/** |
|
358 |
* Print JavaScript templates required for the revisions experience. |
|
359 |
* |
|
360 |
* @since 4.1.0 |
|
361 |
* |
|
16 | 362 |
* @global WP_Post $post Global post object. |
5 | 363 |
*/ |
364 |
function wp_print_revision_templates() { |
|
365 |
global $post; |
|
366 |
?><script id="tmpl-revisions-frame" type="text/html"> |
|
367 |
<div class="revisions-control-frame"></div> |
|
368 |
<div class="revisions-diff-frame"></div> |
|
369 |
</script> |
|
370 |
||
371 |
<script id="tmpl-revisions-buttons" type="text/html"> |
|
372 |
<div class="revisions-previous"> |
|
373 |
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" /> |
|
374 |
</div> |
|
375 |
||
376 |
<div class="revisions-next"> |
|
377 |
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" /> |
|
378 |
</div> |
|
379 |
</script> |
|
380 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
381 |
<script id="tmpl-revisions-slider-hidden-help" type="text/html"> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
382 |
<h2 class="screen-reader-text"><?php esc_html_e( 'Select a revision' ); ?></h2> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
383 |
<p id="revisions-slider-hidden-help" hidden><?php esc_html_e( 'Change revision by using the left and right arrow keys' ); ?></p> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
384 |
</script> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
385 |
|
5 | 386 |
<script id="tmpl-revisions-checkbox" type="text/html"> |
387 |
<div class="revision-toggle-compare-mode"> |
|
388 |
<label> |
|
389 |
<input type="checkbox" class="compare-two-revisions" |
|
390 |
<# |
|
391 |
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) { |
|
392 |
#> checked="checked"<# |
|
393 |
} |
|
394 |
#> |
|
395 |
/> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
<?php esc_html_e( 'Compare any two revisions' ); ?> |
5 | 397 |
</label> |
398 |
</div> |
|
399 |
</script> |
|
400 |
||
401 |
<script id="tmpl-revisions-meta" type="text/html"> |
|
402 |
<# if ( ! _.isUndefined( data.attributes ) ) { #> |
|
403 |
<div class="diff-title"> |
|
404 |
<# if ( 'from' === data.type ) { #> |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
405 |
<strong id="diff-title-from"><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong> |
5 | 406 |
<# } else if ( 'to' === data.type ) { #> |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
407 |
<strong id="diff-title-to"><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong> |
5 | 408 |
<# } #> |
409 |
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>"> |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
410 |
<div> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
411 |
{{{ data.attributes.author.avatar }}} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
412 |
<div class="author-info" id="diff-title-author"> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
413 |
<# if ( data.attributes.autosave ) { #> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
414 |
<span class="byline"> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
415 |
<?php |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
416 |
printf( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
417 |
/* translators: %s: User's display name. */ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
418 |
__( 'Autosave by %s' ), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
419 |
'<span class="author-name">{{ data.attributes.author.name }}</span>' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
420 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
421 |
?> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
422 |
</span> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
423 |
<# } else if ( data.attributes.current ) { #> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
424 |
<span class="byline"> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
425 |
<?php |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
426 |
printf( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
427 |
/* translators: %s: User's display name. */ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
428 |
__( 'Current Revision by %s' ), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
429 |
'<span class="author-name">{{ data.attributes.author.name }}</span>' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
430 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
431 |
?> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
432 |
</span> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
433 |
<# } else { #> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
434 |
<span class="byline"> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
435 |
<?php |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
436 |
printf( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
437 |
/* translators: %s: User's display name. */ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
438 |
__( 'Revision by %s' ), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
439 |
'<span class="author-name">{{ data.attributes.author.name }}</span>' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
440 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
441 |
?> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
442 |
</span> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
443 |
<# } #> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
444 |
<span class="time-ago">{{ data.attributes.timeAgo }}</span> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
445 |
<span class="date">({{ data.attributes.dateShort }})</span> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
446 |
</div> |
5 | 447 |
</div> |
448 |
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #> |
|
449 |
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?> |
|
450 |
disabled="disabled" |
|
451 |
<?php } else { ?> |
|
452 |
<# if ( data.attributes.current ) { #> |
|
453 |
disabled="disabled" |
|
454 |
<# } #> |
|
455 |
<?php } ?> |
|
456 |
<# if ( data.attributes.autosave ) { #> |
|
457 |
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" /> |
|
458 |
<# } else { #> |
|
459 |
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" /> |
|
460 |
<# } #> |
|
461 |
<# } #> |
|
462 |
</div> |
|
463 |
<# if ( 'tooltip' === data.type ) { #> |
|
464 |
<div class="revisions-tooltip-arrow"><span></span></div> |
|
465 |
<# } #> |
|
466 |
<# } #> |
|
467 |
</script> |
|
468 |
||
469 |
<script id="tmpl-revisions-diff" type="text/html"> |
|
470 |
<div class="loading-indicator"><span class="spinner"></span></div> |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
471 |
<div class="diff-error"><?php _e( 'An error occurred while loading the comparison. Please refresh the page and try again.' ); ?></div> |
5 | 472 |
<div class="diff"> |
473 |
<# _.each( data.fields, function( field ) { #> |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
474 |
<h2>{{ field.name }}</h2> |
5 | 475 |
{{{ field.diff }}} |
476 |
<# }); #> |
|
477 |
</div> |
|
9 | 478 |
</script> |
479 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
} |