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