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