0
|
1 |
<?php |
|
2 |
/** |
|
3 |
* Edit post administration panel. |
|
4 |
* |
|
5 |
* Manage Post actions: post, edit, delete, etc. |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Administration |
|
9 |
*/ |
|
10 |
|
|
11 |
/** WordPress Administration Bootstrap */ |
|
12 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
13 |
|
|
14 |
$parent_file = 'edit.php'; |
|
15 |
$submenu_file = 'edit.php'; |
|
16 |
|
|
17 |
wp_reset_vars( array( 'action' ) ); |
|
18 |
|
|
19 |
if ( isset( $_GET['post'] ) ) |
|
20 |
$post_id = $post_ID = (int) $_GET['post']; |
|
21 |
elseif ( isset( $_POST['post_ID'] ) ) |
|
22 |
$post_id = $post_ID = (int) $_POST['post_ID']; |
|
23 |
else |
|
24 |
$post_id = $post_ID = 0; |
|
25 |
|
5
|
26 |
global $post_type, $post_type_object, $post; |
0
|
27 |
|
|
28 |
if ( $post_id ) |
|
29 |
$post = get_post( $post_id ); |
|
30 |
|
|
31 |
if ( $post ) { |
|
32 |
$post_type = $post->post_type; |
|
33 |
$post_type_object = get_post_type_object( $post_type ); |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Redirect to previous page. |
|
38 |
* |
|
39 |
* @param int $post_id Optional. Post ID. |
|
40 |
*/ |
|
41 |
function redirect_post($post_id = '') { |
|
42 |
if ( isset($_POST['save']) || isset($_POST['publish']) ) { |
|
43 |
$status = get_post_status( $post_id ); |
|
44 |
|
|
45 |
if ( isset( $_POST['publish'] ) ) { |
|
46 |
switch ( $status ) { |
|
47 |
case 'pending': |
|
48 |
$message = 8; |
|
49 |
break; |
|
50 |
case 'future': |
|
51 |
$message = 9; |
|
52 |
break; |
|
53 |
default: |
|
54 |
$message = 6; |
|
55 |
} |
|
56 |
} else { |
|
57 |
$message = 'draft' == $status ? 10 : 1; |
|
58 |
} |
|
59 |
|
|
60 |
$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); |
|
61 |
} elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { |
|
62 |
$location = add_query_arg( 'message', 2, wp_get_referer() ); |
|
63 |
$location = explode('#', $location); |
|
64 |
$location = $location[0] . '#postcustom'; |
|
65 |
} elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) { |
|
66 |
$location = add_query_arg( 'message', 3, wp_get_referer() ); |
|
67 |
$location = explode('#', $location); |
|
68 |
$location = $location[0] . '#postcustom'; |
|
69 |
} else { |
|
70 |
$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); |
|
71 |
} |
|
72 |
|
5
|
73 |
/** |
|
74 |
* Filter the post redirect destination URL. |
|
75 |
* |
|
76 |
* @since 2.9.0 |
|
77 |
* |
|
78 |
* @param string $location The destination URL. |
|
79 |
* @param int $post_id The post ID. |
|
80 |
*/ |
0
|
81 |
wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); |
|
82 |
exit; |
|
83 |
} |
|
84 |
|
|
85 |
if ( isset( $_POST['deletepost'] ) ) |
|
86 |
$action = 'delete'; |
|
87 |
elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) |
|
88 |
$action = 'preview'; |
|
89 |
|
|
90 |
$sendback = wp_get_referer(); |
|
91 |
if ( ! $sendback || |
|
92 |
strpos( $sendback, 'post.php' ) !== false || |
|
93 |
strpos( $sendback, 'post-new.php' ) !== false ) { |
|
94 |
if ( 'attachment' == $post_type ) { |
|
95 |
$sendback = admin_url( 'upload.php' ); |
|
96 |
} else { |
|
97 |
$sendback = admin_url( 'edit.php' ); |
5
|
98 |
if ( ! empty( $post_type ) ) { |
|
99 |
$sendback = add_query_arg( 'post_type', $post_type, $sendback ); |
|
100 |
} |
0
|
101 |
} |
|
102 |
} else { |
|
103 |
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); |
|
104 |
} |
|
105 |
|
|
106 |
switch($action) { |
5
|
107 |
case 'post-quickdraft-save': |
|
108 |
// Check nonce and capabilities |
|
109 |
$nonce = $_REQUEST['_wpnonce']; |
|
110 |
$error_msg = false; |
|
111 |
|
|
112 |
// For output of the quickdraft dashboard widget |
|
113 |
require_once ABSPATH . 'wp-admin/includes/dashboard.php'; |
|
114 |
|
|
115 |
if ( ! wp_verify_nonce( $nonce, 'add-post' ) ) |
|
116 |
$error_msg = __( 'Unable to submit this form, please refresh and try again.' ); |
|
117 |
|
|
118 |
if ( ! current_user_can( 'edit_posts' ) ) |
|
119 |
$error_msg = __( 'Oops, you don’t have access to add new drafts.' ); |
|
120 |
|
|
121 |
if ( $error_msg ) |
|
122 |
return wp_dashboard_quick_press( $error_msg ); |
|
123 |
|
|
124 |
$post = get_post( $_REQUEST['post_ID'] ); |
|
125 |
check_admin_referer( 'add-' . $post->post_type ); |
|
126 |
|
|
127 |
$_POST['comment_status'] = get_option( 'default_comment_status' ); |
|
128 |
$_POST['ping_status'] = get_option( 'default_ping_status' ); |
|
129 |
|
|
130 |
edit_post(); |
|
131 |
wp_dashboard_quick_press(); |
|
132 |
exit; |
|
133 |
|
0
|
134 |
case 'postajaxpost': |
|
135 |
case 'post': |
5
|
136 |
check_admin_referer( 'add-' . $post_type ); |
|
137 |
$post_id = 'postajaxpost' == $action ? edit_post() : write_post(); |
|
138 |
redirect_post( $post_id ); |
0
|
139 |
exit(); |
|
140 |
|
|
141 |
case 'edit': |
|
142 |
$editing = true; |
|
143 |
|
|
144 |
if ( empty( $post_id ) ) { |
|
145 |
wp_redirect( admin_url('post.php') ); |
|
146 |
exit(); |
|
147 |
} |
|
148 |
|
|
149 |
if ( ! $post ) |
|
150 |
wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); |
|
151 |
|
|
152 |
if ( ! $post_type_object ) |
|
153 |
wp_die( __( 'Unknown post type.' ) ); |
|
154 |
|
|
155 |
if ( ! current_user_can( 'edit_post', $post_id ) ) |
|
156 |
wp_die( __( 'You are not allowed to edit this item.' ) ); |
|
157 |
|
|
158 |
if ( 'trash' == $post->post_status ) |
|
159 |
wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) ); |
|
160 |
|
|
161 |
if ( ! empty( $_GET['get-post-lock'] ) ) { |
|
162 |
wp_set_post_lock( $post_id ); |
|
163 |
wp_redirect( get_edit_post_link( $post_id, 'url' ) ); |
|
164 |
exit(); |
|
165 |
} |
|
166 |
|
|
167 |
$post_type = $post->post_type; |
|
168 |
if ( 'post' == $post_type ) { |
|
169 |
$parent_file = "edit.php"; |
|
170 |
$submenu_file = "edit.php"; |
|
171 |
$post_new_file = "post-new.php"; |
|
172 |
} elseif ( 'attachment' == $post_type ) { |
|
173 |
$parent_file = 'upload.php'; |
|
174 |
$submenu_file = 'upload.php'; |
|
175 |
$post_new_file = 'media-new.php'; |
|
176 |
} else { |
|
177 |
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) |
|
178 |
$parent_file = $post_type_object->show_in_menu; |
|
179 |
else |
|
180 |
$parent_file = "edit.php?post_type=$post_type"; |
|
181 |
$submenu_file = "edit.php?post_type=$post_type"; |
|
182 |
$post_new_file = "post-new.php?post_type=$post_type"; |
|
183 |
} |
|
184 |
|
|
185 |
if ( ! wp_check_post_lock( $post->ID ) ) { |
|
186 |
$active_post_lock = wp_set_post_lock( $post->ID ); |
|
187 |
|
|
188 |
if ( 'attachment' !== $post_type ) |
|
189 |
wp_enqueue_script('autosave'); |
|
190 |
} |
|
191 |
|
|
192 |
if ( is_multisite() ) { |
|
193 |
add_action( 'admin_footer', '_admin_notice_post_locked' ); |
|
194 |
} else { |
|
195 |
$check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) ); |
|
196 |
|
|
197 |
if ( count( $check_users ) > 1 ) |
|
198 |
add_action( 'admin_footer', '_admin_notice_post_locked' ); |
|
199 |
|
|
200 |
unset( $check_users ); |
|
201 |
} |
|
202 |
|
|
203 |
$title = $post_type_object->labels->edit_item; |
|
204 |
$post = get_post($post_id, OBJECT, 'edit'); |
|
205 |
|
|
206 |
if ( post_type_supports($post_type, 'comments') ) { |
|
207 |
wp_enqueue_script('admin-comments'); |
|
208 |
enqueue_comment_hotkeys_js(); |
|
209 |
} |
|
210 |
|
|
211 |
include( ABSPATH . 'wp-admin/edit-form-advanced.php' ); |
|
212 |
|
|
213 |
break; |
|
214 |
|
|
215 |
case 'editattachment': |
|
216 |
check_admin_referer('update-post_' . $post_id); |
|
217 |
|
|
218 |
// Don't let these be changed |
|
219 |
unset($_POST['guid']); |
|
220 |
$_POST['post_type'] = 'attachment'; |
|
221 |
|
|
222 |
// Update the thumbnail filename |
|
223 |
$newmeta = wp_get_attachment_metadata( $post_id, true ); |
|
224 |
$newmeta['thumb'] = $_POST['thumb']; |
|
225 |
|
|
226 |
wp_update_attachment_metadata( $post_id, $newmeta ); |
|
227 |
|
|
228 |
case 'editpost': |
|
229 |
check_admin_referer('update-post_' . $post_id); |
|
230 |
|
|
231 |
$post_id = edit_post(); |
|
232 |
|
|
233 |
// Session cookie flag that the post was saved |
5
|
234 |
if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) { |
|
235 |
setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS ); |
|
236 |
} |
0
|
237 |
|
|
238 |
redirect_post($post_id); // Send user on their way while we keep working |
|
239 |
|
|
240 |
exit(); |
|
241 |
|
|
242 |
case 'trash': |
|
243 |
check_admin_referer('trash-post_' . $post_id); |
|
244 |
|
|
245 |
if ( ! $post ) |
|
246 |
wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) ); |
|
247 |
|
|
248 |
if ( ! $post_type_object ) |
|
249 |
wp_die( __( 'Unknown post type.' ) ); |
|
250 |
|
|
251 |
if ( ! current_user_can( 'delete_post', $post_id ) ) |
|
252 |
wp_die( __( 'You are not allowed to move this item to the Trash.' ) ); |
|
253 |
|
|
254 |
if ( $user_id = wp_check_post_lock( $post_id ) ) { |
|
255 |
$user = get_userdata( $user_id ); |
|
256 |
wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) ); |
|
257 |
} |
|
258 |
|
|
259 |
if ( ! wp_trash_post( $post_id ) ) |
|
260 |
wp_die( __( 'Error in moving to Trash.' ) ); |
|
261 |
|
|
262 |
wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) ); |
|
263 |
exit(); |
|
264 |
|
|
265 |
case 'untrash': |
|
266 |
check_admin_referer('untrash-post_' . $post_id); |
|
267 |
|
|
268 |
if ( ! $post ) |
|
269 |
wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) ); |
|
270 |
|
|
271 |
if ( ! $post_type_object ) |
|
272 |
wp_die( __( 'Unknown post type.' ) ); |
|
273 |
|
|
274 |
if ( ! current_user_can( 'delete_post', $post_id ) ) |
|
275 |
wp_die( __( 'You are not allowed to move this item out of the Trash.' ) ); |
|
276 |
|
|
277 |
if ( ! wp_untrash_post( $post_id ) ) |
|
278 |
wp_die( __( 'Error in restoring from Trash.' ) ); |
|
279 |
|
|
280 |
wp_redirect( add_query_arg('untrashed', 1, $sendback) ); |
|
281 |
exit(); |
|
282 |
|
|
283 |
case 'delete': |
|
284 |
check_admin_referer('delete-post_' . $post_id); |
|
285 |
|
|
286 |
if ( ! $post ) |
|
287 |
wp_die( __( 'This item has already been deleted.' ) ); |
|
288 |
|
|
289 |
if ( ! $post_type_object ) |
|
290 |
wp_die( __( 'Unknown post type.' ) ); |
|
291 |
|
|
292 |
if ( ! current_user_can( 'delete_post', $post_id ) ) |
|
293 |
wp_die( __( 'You are not allowed to delete this item.' ) ); |
|
294 |
|
|
295 |
$force = ! EMPTY_TRASH_DAYS; |
|
296 |
if ( $post->post_type == 'attachment' ) { |
|
297 |
$force = ( $force || ! MEDIA_TRASH ); |
|
298 |
if ( ! wp_delete_attachment( $post_id, $force ) ) |
|
299 |
wp_die( __( 'Error in deleting.' ) ); |
|
300 |
} else { |
|
301 |
if ( ! wp_delete_post( $post_id, $force ) ) |
|
302 |
wp_die( __( 'Error in deleting.' ) ); |
|
303 |
} |
|
304 |
|
|
305 |
wp_redirect( add_query_arg('deleted', 1, $sendback) ); |
|
306 |
exit(); |
|
307 |
|
|
308 |
case 'preview': |
5
|
309 |
check_admin_referer( 'update-post_' . $post_id ); |
0
|
310 |
|
|
311 |
$url = post_preview(); |
|
312 |
|
|
313 |
wp_redirect($url); |
|
314 |
exit(); |
|
315 |
|
|
316 |
default: |
|
317 |
wp_redirect( admin_url('edit.php') ); |
|
318 |
exit(); |
|
319 |
} // end switch |
|
320 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |