author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Revisions administration panel |
|
4 |
* |
|
5 |
* Requires wp-admin/includes/revision.php. |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Administration |
|
9 |
* @since 2.6.0 |
|
10 |
*/ |
|
11 |
||
12 |
/** WordPress Administration Bootstrap */ |
|
16 | 13 |
require_once __DIR__ . '/admin.php'; |
0 | 14 |
|
15 |
require ABSPATH . 'wp-admin/includes/revision.php'; |
|
16 |
||
9 | 17 |
/** |
18 |
* @global int $revision Optional. The revision ID. |
|
19 |
* @global string $action The action to take. |
|
20 |
* Accepts 'restore', 'view' or 'edit'. |
|
21 |
* @global int $from The revision to compare from. |
|
22 |
* @global int $to Optional, required if revision missing. The revision to compare to. |
|
23 |
*/ |
|
0 | 24 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
$revision_id = ! empty( $_REQUEST['revision'] ) ? absint( $_REQUEST['revision'] ) : 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
26 |
$action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
$from = ! empty( $_REQUEST['from'] ) && is_numeric( $_REQUEST['from'] ) ? absint( $_REQUEST['from'] ) : null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
$to = ! empty( $_REQUEST['to'] ) && is_numeric( $_REQUEST['to'] ) ? absint( $_REQUEST['to'] ) : null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
|
9 | 30 |
if ( ! $revision_id ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
$revision_id = $to; |
9 | 32 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
|
0 | 34 |
$redirect = 'edit.php'; |
35 |
||
5 | 36 |
switch ( $action ) { |
9 | 37 |
case 'restore': |
16 | 38 |
$revision = wp_get_post_revision( $revision_id ); |
39 |
if ( ! $revision ) { |
|
9 | 40 |
break; |
41 |
} |
|
0 | 42 |
|
9 | 43 |
if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) { |
44 |
break; |
|
45 |
} |
|
0 | 46 |
|
16 | 47 |
$post = get_post( $revision->post_parent ); |
48 |
if ( ! $post ) { |
|
9 | 49 |
break; |
50 |
} |
|
0 | 51 |
|
16 | 52 |
// Don't restore if revisions are disabled and this is not an autosave. |
9 | 53 |
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) { |
54 |
$redirect = 'edit.php?post_type=' . $post->post_type; |
|
55 |
break; |
|
56 |
} |
|
0 | 57 |
|
16 | 58 |
// Don't restore if the post is locked. |
9 | 59 |
if ( wp_check_post_lock( $post->ID ) ) { |
60 |
break; |
|
61 |
} |
|
0 | 62 |
|
9 | 63 |
check_admin_referer( "restore-post_{$revision->ID}" ); |
0 | 64 |
|
16 | 65 |
/* |
66 |
* Ensure the global $post remains the same after revision is restored. |
|
67 |
* Because wp_insert_post() and wp_transition_post_status() are called |
|
68 |
* during the process, plugins can unexpectedly modify $post. |
|
69 |
*/ |
|
70 |
$backup_global_post = clone $post; |
|
71 |
||
9 | 72 |
wp_restore_post_revision( $revision->ID ); |
16 | 73 |
|
74 |
// Restore the global $post as it was before. |
|
75 |
$post = $backup_global_post; |
|
76 |
||
9 | 77 |
$redirect = add_query_arg( |
78 |
array( |
|
79 |
'message' => 5, |
|
80 |
'revision' => $revision->ID, |
|
81 |
), |
|
82 |
get_edit_post_link( $post->ID, 'url' ) |
|
83 |
); |
|
0 | 84 |
break; |
9 | 85 |
case 'view': |
86 |
case 'edit': |
|
87 |
default: |
|
16 | 88 |
$revision = wp_get_post_revision( $revision_id ); |
89 |
if ( ! $revision ) { |
|
9 | 90 |
break; |
91 |
} |
|
16 | 92 |
|
93 |
$post = get_post( $revision->post_parent ); |
|
94 |
if ( ! $post ) { |
|
9 | 95 |
break; |
96 |
} |
|
0 | 97 |
|
9 | 98 |
if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) ) { |
99 |
break; |
|
100 |
} |
|
101 |
||
16 | 102 |
// Bail if revisions are disabled and this is not an autosave. |
9 | 103 |
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) { |
104 |
$redirect = 'edit.php?post_type=' . $post->post_type; |
|
105 |
break; |
|
106 |
} |
|
0 | 107 |
|
9 | 108 |
$post_edit_link = get_edit_post_link(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
$post_title = '<a href="' . esc_url( $post_edit_link ) . '">' . _draft_or_post_title() . '</a>'; |
16 | 110 |
/* translators: %s: Post title. */ |
9 | 111 |
$h1 = sprintf( __( 'Compare Revisions of “%s”' ), $post_title ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
$return_to_post = '<a href="' . esc_url( $post_edit_link ) . '">' . __( '← Go to editor' ) . '</a>'; |
19 | 113 |
// Used in the HTML title tag. |
114 |
$title = __( 'Revisions' ); |
|
0 | 115 |
|
9 | 116 |
$redirect = false; |
117 |
break; |
|
5 | 118 |
} |
0 | 119 |
|
120 |
// Empty post_type means either malformed object found, or no valid parent was found. |
|
9 | 121 |
if ( ! $redirect && empty( $post->post_type ) ) { |
0 | 122 |
$redirect = 'edit.php'; |
9 | 123 |
} |
0 | 124 |
|
125 |
if ( ! empty( $redirect ) ) { |
|
126 |
wp_redirect( $redirect ); |
|
127 |
exit; |
|
128 |
} |
|
129 |
||
130 |
// This is so that the correct "Edit" menu item is selected. |
|
19 | 131 |
if ( ! empty( $post->post_type ) && 'post' !== $post->post_type ) { |
16 | 132 |
$parent_file = 'edit.php?post_type=' . $post->post_type; |
9 | 133 |
} else { |
16 | 134 |
$parent_file = 'edit.php'; |
9 | 135 |
} |
16 | 136 |
$submenu_file = $parent_file; |
0 | 137 |
|
138 |
wp_enqueue_script( 'revisions' ); |
|
139 |
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) ); |
|
140 |
||
141 |
/* Revisions Help Tab */ |
|
142 |
||
143 |
$revisions_overview = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>'; |
|
144 |
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>'; |
|
145 |
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>'; |
|
146 |
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>'; |
|
147 |
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>'; |
|
148 |
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>'; |
|
149 |
||
9 | 150 |
get_current_screen()->add_help_tab( |
151 |
array( |
|
152 |
'id' => 'revisions-overview', |
|
153 |
'title' => __( 'Overview' ), |
|
154 |
'content' => $revisions_overview, |
|
155 |
) |
|
156 |
); |
|
0 | 157 |
|
158 |
$revisions_sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/documentation/article/revisions/">Revisions Management</a>' ) . '</p>'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
160 |
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'; |
0 | 161 |
|
162 |
get_current_screen()->set_help_sidebar( $revisions_sidebar ); |
|
163 |
||
16 | 164 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 165 |
|
166 |
?> |
|
167 |
||
168 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
<h1 class="long-header"><?php echo $h1; ?></h1> |
5 | 170 |
<?php echo $return_to_post; ?> |
0 | 171 |
</div> |
5 | 172 |
<?php |
173 |
wp_print_revision_templates(); |
|
0 | 174 |
|
16 | 175 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |