|
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 |
|
26 $post = $post_type = $post_type_object = null; |
|
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 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { |
|
70 $location = "post.php?action=edit&post=$post_id&message=7"; |
|
71 } else { |
|
72 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); |
|
73 } |
|
74 |
|
75 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); |
|
76 exit; |
|
77 } |
|
78 |
|
79 if ( isset( $_POST['deletepost'] ) ) |
|
80 $action = 'delete'; |
|
81 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) |
|
82 $action = 'preview'; |
|
83 |
|
84 $sendback = wp_get_referer(); |
|
85 if ( ! $sendback || |
|
86 strpos( $sendback, 'post.php' ) !== false || |
|
87 strpos( $sendback, 'post-new.php' ) !== false ) { |
|
88 if ( 'attachment' == $post_type ) { |
|
89 $sendback = admin_url( 'upload.php' ); |
|
90 } else { |
|
91 $sendback = admin_url( 'edit.php' ); |
|
92 $sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : ''; |
|
93 } |
|
94 } else { |
|
95 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); |
|
96 } |
|
97 |
|
98 switch($action) { |
|
99 case 'postajaxpost': |
|
100 case 'post': |
|
101 case 'post-quickpress-publish': |
|
102 case 'post-quickpress-save': |
|
103 check_admin_referer('add-' . $post_type); |
|
104 |
|
105 if ( 'post-quickpress-publish' == $action ) |
|
106 $_POST['publish'] = 'publish'; // tell write_post() to publish |
|
107 |
|
108 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) { |
|
109 $_POST['comment_status'] = get_option('default_comment_status'); |
|
110 $_POST['ping_status'] = get_option('default_ping_status'); |
|
111 $post_id = edit_post(); |
|
112 } else { |
|
113 $post_id = 'postajaxpost' == $action ? edit_post() : write_post(); |
|
114 } |
|
115 |
|
116 if ( 0 === strpos( $action, 'post-quickpress' ) ) { |
|
117 $_POST['post_ID'] = $post_id; |
|
118 // output the quickpress dashboard widget |
|
119 require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); |
|
120 wp_dashboard_quick_press(); |
|
121 exit; |
|
122 } |
|
123 |
|
124 redirect_post($post_id); |
|
125 exit(); |
|
126 break; |
|
127 |
|
128 case 'edit': |
|
129 $editing = true; |
|
130 |
|
131 if ( empty( $post_id ) ) { |
|
132 wp_redirect( admin_url('post.php') ); |
|
133 exit(); |
|
134 } |
|
135 |
|
136 if ( ! $post ) |
|
137 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); |
|
138 |
|
139 if ( ! $post_type_object ) |
|
140 wp_die( __( 'Unknown post type.' ) ); |
|
141 |
|
142 if ( ! current_user_can( 'edit_post', $post_id ) ) |
|
143 wp_die( __( 'You are not allowed to edit this item.' ) ); |
|
144 |
|
145 if ( 'trash' == $post->post_status ) |
|
146 wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) ); |
|
147 |
|
148 if ( ! empty( $_GET['get-post-lock'] ) ) { |
|
149 wp_set_post_lock( $post_id ); |
|
150 wp_redirect( get_edit_post_link( $post_id, 'url' ) ); |
|
151 exit(); |
|
152 } |
|
153 |
|
154 $post_type = $post->post_type; |
|
155 if ( 'post' == $post_type ) { |
|
156 $parent_file = "edit.php"; |
|
157 $submenu_file = "edit.php"; |
|
158 $post_new_file = "post-new.php"; |
|
159 } elseif ( 'attachment' == $post_type ) { |
|
160 $parent_file = 'upload.php'; |
|
161 $submenu_file = 'upload.php'; |
|
162 $post_new_file = 'media-new.php'; |
|
163 } else { |
|
164 if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) |
|
165 $parent_file = $post_type_object->show_in_menu; |
|
166 else |
|
167 $parent_file = "edit.php?post_type=$post_type"; |
|
168 $submenu_file = "edit.php?post_type=$post_type"; |
|
169 $post_new_file = "post-new.php?post_type=$post_type"; |
|
170 } |
|
171 |
|
172 if ( ! wp_check_post_lock( $post->ID ) ) { |
|
173 $active_post_lock = wp_set_post_lock( $post->ID ); |
|
174 |
|
175 if ( 'attachment' !== $post_type ) |
|
176 wp_enqueue_script('autosave'); |
|
177 } |
|
178 |
|
179 if ( is_multisite() ) { |
|
180 add_action( 'admin_footer', '_admin_notice_post_locked' ); |
|
181 } else { |
|
182 $check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) ); |
|
183 |
|
184 if ( count( $check_users ) > 1 ) |
|
185 add_action( 'admin_footer', '_admin_notice_post_locked' ); |
|
186 |
|
187 unset( $check_users ); |
|
188 } |
|
189 |
|
190 $title = $post_type_object->labels->edit_item; |
|
191 $post = get_post($post_id, OBJECT, 'edit'); |
|
192 |
|
193 if ( post_type_supports($post_type, 'comments') ) { |
|
194 wp_enqueue_script('admin-comments'); |
|
195 enqueue_comment_hotkeys_js(); |
|
196 } |
|
197 |
|
198 include( ABSPATH . 'wp-admin/edit-form-advanced.php' ); |
|
199 |
|
200 break; |
|
201 |
|
202 case 'editattachment': |
|
203 check_admin_referer('update-post_' . $post_id); |
|
204 |
|
205 // Don't let these be changed |
|
206 unset($_POST['guid']); |
|
207 $_POST['post_type'] = 'attachment'; |
|
208 |
|
209 // Update the thumbnail filename |
|
210 $newmeta = wp_get_attachment_metadata( $post_id, true ); |
|
211 $newmeta['thumb'] = $_POST['thumb']; |
|
212 |
|
213 wp_update_attachment_metadata( $post_id, $newmeta ); |
|
214 |
|
215 case 'editpost': |
|
216 check_admin_referer('update-post_' . $post_id); |
|
217 |
|
218 $post_id = edit_post(); |
|
219 |
|
220 // Session cookie flag that the post was saved |
|
221 if ( isset( $_COOKIE['wp-saving-post-' . $post_id] ) ) |
|
222 setcookie( 'wp-saving-post-' . $post_id, 'saved' ); |
|
223 |
|
224 redirect_post($post_id); // Send user on their way while we keep working |
|
225 |
|
226 exit(); |
|
227 break; |
|
228 |
|
229 case 'trash': |
|
230 check_admin_referer('trash-post_' . $post_id); |
|
231 |
|
232 if ( ! $post ) |
|
233 wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) ); |
|
234 |
|
235 if ( ! $post_type_object ) |
|
236 wp_die( __( 'Unknown post type.' ) ); |
|
237 |
|
238 if ( ! current_user_can( 'delete_post', $post_id ) ) |
|
239 wp_die( __( 'You are not allowed to move this item to the Trash.' ) ); |
|
240 |
|
241 if ( $user_id = wp_check_post_lock( $post_id ) ) { |
|
242 $user = get_userdata( $user_id ); |
|
243 wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) ); |
|
244 } |
|
245 |
|
246 if ( ! wp_trash_post( $post_id ) ) |
|
247 wp_die( __( 'Error in moving to Trash.' ) ); |
|
248 |
|
249 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) ); |
|
250 exit(); |
|
251 break; |
|
252 |
|
253 case 'untrash': |
|
254 check_admin_referer('untrash-post_' . $post_id); |
|
255 |
|
256 if ( ! $post ) |
|
257 wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) ); |
|
258 |
|
259 if ( ! $post_type_object ) |
|
260 wp_die( __( 'Unknown post type.' ) ); |
|
261 |
|
262 if ( ! current_user_can( 'delete_post', $post_id ) ) |
|
263 wp_die( __( 'You are not allowed to move this item out of the Trash.' ) ); |
|
264 |
|
265 if ( ! wp_untrash_post( $post_id ) ) |
|
266 wp_die( __( 'Error in restoring from Trash.' ) ); |
|
267 |
|
268 wp_redirect( add_query_arg('untrashed', 1, $sendback) ); |
|
269 exit(); |
|
270 break; |
|
271 |
|
272 case 'delete': |
|
273 check_admin_referer('delete-post_' . $post_id); |
|
274 |
|
275 if ( ! $post ) |
|
276 wp_die( __( 'This item has already been deleted.' ) ); |
|
277 |
|
278 if ( ! $post_type_object ) |
|
279 wp_die( __( 'Unknown post type.' ) ); |
|
280 |
|
281 if ( ! current_user_can( 'delete_post', $post_id ) ) |
|
282 wp_die( __( 'You are not allowed to delete this item.' ) ); |
|
283 |
|
284 $force = ! EMPTY_TRASH_DAYS; |
|
285 if ( $post->post_type == 'attachment' ) { |
|
286 $force = ( $force || ! MEDIA_TRASH ); |
|
287 if ( ! wp_delete_attachment( $post_id, $force ) ) |
|
288 wp_die( __( 'Error in deleting.' ) ); |
|
289 } else { |
|
290 if ( ! wp_delete_post( $post_id, $force ) ) |
|
291 wp_die( __( 'Error in deleting.' ) ); |
|
292 } |
|
293 |
|
294 wp_redirect( add_query_arg('deleted', 1, $sendback) ); |
|
295 exit(); |
|
296 break; |
|
297 |
|
298 case 'preview': |
|
299 check_admin_referer( 'autosave', 'autosavenonce' ); |
|
300 |
|
301 $url = post_preview(); |
|
302 |
|
303 wp_redirect($url); |
|
304 exit(); |
|
305 break; |
|
306 |
|
307 default: |
|
308 wp_redirect( admin_url('edit.php') ); |
|
309 exit(); |
|
310 break; |
|
311 } // end switch |
|
312 include( ABSPATH . 'wp-admin/admin-footer.php' ); |