3 * Edit post administration panel.
5 * Manage Post actions: post, edit, delete, etc.
8 * @subpackage Administration
11 /** WordPress Administration Bootstrap */
12 require_once('./admin.php');
14 $parent_file = 'edit.php';
15 $submenu_file = 'edit.php';
17 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
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'];
24 $post_id = $post_ID = 0;
26 $post = $post_type = $post_type_object = null;
29 $post = get_post( $post_id );
32 $post_type = $post->post_type;
33 $post_type_object = get_post_type_object( $post_type );
37 * Redirect to previous page.
39 * @param int $post_id Optional. Post ID.
41 function redirect_post($post_id = '') {
42 if ( isset($_POST['save']) || isset($_POST['publish']) ) {
43 $status = get_post_status( $post_id );
45 if ( isset( $_POST['publish'] ) ) {
57 $message = 'draft' == $status ? 10 : 1;
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";
72 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
75 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
79 if ( isset( $_POST['deletepost'] ) )
81 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
84 $sendback = wp_get_referer();
86 strpos( $sendback, 'post.php' ) !== false ||
87 strpos( $sendback, 'post-new.php' ) !== false ) {
88 if ( 'attachment' == $post_type ) {
89 $sendback = admin_url( 'upload.php' );
91 $sendback = admin_url( 'edit.php' );
92 $sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : '';
95 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
101 case 'post-quickpress-publish':
102 case 'post-quickpress-save':
103 check_admin_referer('add-' . $post_type);
105 if ( 'post-quickpress-publish' == $action )
106 $_POST['publish'] = 'publish'; // tell write_post() to publish
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();
113 $post_id = 'postajaxpost' == $action ? edit_post() : write_post();
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();
124 redirect_post($post_id);
131 if ( empty( $post_id ) ) {
132 wp_redirect( admin_url('post.php') );
138 if ( empty($post->ID) )
139 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') );
141 if ( null == $post_type_object )
142 wp_die( __('Unknown post type.') );
144 if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )
145 wp_die( __('You are not allowed to edit this item.') );
147 if ( 'trash' == $post->post_status )
148 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') );
150 $post_type = $post->post_type;
151 if ( 'post' == $post_type ) {
152 $parent_file = "edit.php";
153 $submenu_file = "edit.php";
154 $post_new_file = "post-new.php";
155 } elseif ( 'attachment' == $post_type ) {
156 $parent_file = 'upload.php';
157 $submenu_file = 'upload.php';
158 $post_new_file = 'media-new.php';
160 if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
161 $parent_file = $post_type_object->show_in_menu;
163 $parent_file = "edit.php?post_type=$post_type";
164 $submenu_file = "edit.php?post_type=$post_type";
165 $post_new_file = "post-new.php?post_type=$post_type";
168 if ( $last = wp_check_post_lock( $post->ID ) ) {
169 add_action('admin_notices', '_admin_notice_post_locked' );
171 $active_post_lock = wp_set_post_lock( $post->ID );
173 if ( 'attachment' !== $post_type )
174 wp_enqueue_script('autosave');
177 $title = $post_type_object->labels->edit_item;
178 $post = get_post($post_id, OBJECT, 'edit');
180 if ( post_type_supports($post_type, 'comments') ) {
181 wp_enqueue_script('admin-comments');
182 enqueue_comment_hotkeys_js();
185 include('./edit-form-advanced.php');
189 case 'editattachment':
190 check_admin_referer('update-post_' . $post_id);
192 // Don't let these be changed
193 unset($_POST['guid']);
194 $_POST['post_type'] = 'attachment';
196 // Update the thumbnail filename
197 $newmeta = wp_get_attachment_metadata( $post_id, true );
198 $newmeta['thumb'] = $_POST['thumb'];
200 wp_update_attachment_metadata( $post_id, $newmeta );
203 check_admin_referer('update-post_' . $post_id);
205 $post_id = edit_post();
207 redirect_post($post_id); // Send user on their way while we keep working
213 check_admin_referer('trash-post_' . $post_id);
215 $post = get_post($post_id);
217 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
218 wp_die( __('You are not allowed to move this item to the Trash.') );
220 if ( ! wp_trash_post($post_id) )
221 wp_die( __('Error in moving to Trash.') );
223 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
228 check_admin_referer('untrash-post_' . $post_id);
230 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
231 wp_die( __('You are not allowed to move this item out of the Trash.') );
233 if ( ! wp_untrash_post($post_id) )
234 wp_die( __('Error in restoring from Trash.') );
236 wp_redirect( add_query_arg('untrashed', 1, $sendback) );
241 check_admin_referer('delete-post_' . $post_id);
243 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
244 wp_die( __('You are not allowed to delete this item.') );
246 $force = !EMPTY_TRASH_DAYS;
247 if ( $post->post_type == 'attachment' ) {
248 $force = ( $force || !MEDIA_TRASH );
249 if ( ! wp_delete_attachment($post_id, $force) )
250 wp_die( __('Error in deleting.') );
252 if ( !wp_delete_post($post_id, $force) )
253 wp_die( __('Error in deleting.') );
256 wp_redirect( add_query_arg('deleted', 1, $sendback) );
261 check_admin_referer( 'autosave', 'autosavenonce' );
263 $url = post_preview();
270 wp_redirect( admin_url('edit.php') );
274 include('./admin-footer.php');