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'));
20 * Redirect to previous page.
22 * @param int $post_ID Optional. Post ID.
24 function redirect_post($post_ID = '') {
28 if ( !empty($_POST['referredby']) ) {
29 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
30 $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
32 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
34 if ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
35 if ( isset($_POST['saveasdraft']) )
36 $location = 'sidebar.php?a=c';
37 elseif ( isset($_POST['publish']) )
38 $location = 'sidebar.php?a=b';
39 } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) {
40 $status = get_post_status( $post_ID );
42 if ( isset( $_POST['publish'] ) ) {
54 $message = 'draft' == $status ? 10 : 1;
57 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_ID, 'url' ) );
58 } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
59 $location = add_query_arg( 'message', 2, wp_get_referer() );
60 $location = explode('#', $location);
61 $location = $location[0] . '#postcustom';
62 } elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
63 $location = add_query_arg( 'message', 3, wp_get_referer() );
64 $location = explode('#', $location);
65 $location = $location[0] . '#postcustom';
66 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
67 $location = "post.php?action=edit&post=$post_ID&message=7";
69 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
72 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_ID ) );
75 if ( isset( $_POST['deletepost'] ) )
77 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
80 $sendback = wp_get_referer();
81 if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false )
82 $sendback = admin_url('edit.php');
84 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
89 case 'post-quickpress-publish':
90 case 'post-quickpress-save':
91 check_admin_referer('add-post');
93 if ( 'post-quickpress-publish' == $action )
94 $_POST['publish'] = 'publish'; // tell write_post() to publish
96 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
97 $_POST['comment_status'] = get_option('default_comment_status');
98 $_POST['ping_status'] = get_option('default_ping_status');
101 if ( !empty( $_POST['quickpress_post_ID'] ) ) {
102 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
103 $post_ID = edit_post();
105 $post_ID = 'postajaxpost' == $action ? edit_post() : write_post();
108 if ( 0 === strpos( $action, 'post-quickpress' ) ) {
109 $_POST['post_ID'] = $post_ID;
110 // output the quickpress dashboard widget
111 require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
112 wp_dashboard_quick_press();
116 redirect_post($post_ID);
123 if ( empty( $_GET['post'] ) ) {
124 wp_redirect("post.php");
127 $post_ID = $p = (int) $_GET['post'];
128 $post = get_post($post_ID);
130 if ( empty($post->ID) )
131 wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') );
133 if ( !current_user_can('edit_post', $post_ID) )
134 wp_die( __('You are not allowed to edit this post.') );
136 if ( 'trash' == $post->post_status )
137 wp_die( __('You can’t edit this post because it is in the Trash. Please restore it and try again.') );
139 if ( 'post' != $post->post_type ) {
140 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
144 wp_enqueue_script('post');
145 if ( user_can_richedit() )
146 wp_enqueue_script('editor');
148 wp_enqueue_script('media-upload');
149 wp_enqueue_script('word-count');
150 wp_enqueue_script( 'admin-comments' );
151 enqueue_comment_hotkeys_js();
153 if ( $last = wp_check_post_lock( $post->ID ) ) {
154 add_action('admin_notices', '_admin_notice_post_locked' );
156 wp_set_post_lock( $post->ID );
157 wp_enqueue_script('autosave');
160 $title = __('Edit Post');
161 $post = get_post_to_edit($post_ID);
163 include('edit-form-advanced.php');
167 case 'editattachment':
168 $post_id = (int) $_POST['post_ID'];
170 check_admin_referer('update-attachment_' . $post_id);
172 // Don't let these be changed
173 unset($_POST['guid']);
174 $_POST['post_type'] = 'attachment';
176 // Update the thumbnail filename
177 $newmeta = wp_get_attachment_metadata( $post_id, true );
178 $newmeta['thumb'] = $_POST['thumb'];
180 wp_update_attachment_metadata( $post_id, $newmeta );
183 $post_ID = (int) $_POST['post_ID'];
184 check_admin_referer('update-post_' . $post_ID);
186 $post_ID = edit_post();
188 redirect_post($post_ID); // Send user on their way while we keep working
194 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
195 check_admin_referer('trash-post_' . $post_id);
197 $post = & get_post($post_id);
199 if ( !current_user_can('delete_post', $post_id) )
200 wp_die( __('You are not allowed to move this post to the trash.') );
202 if ( ! wp_trash_post($post_id) )
203 wp_die( __('Error in moving to trash...') );
205 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
210 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
211 check_admin_referer('untrash-post_' . $post_id);
213 $post = & get_post($post_id);
215 if ( !current_user_can('delete_post', $post_id) )
216 wp_die( __('You are not allowed to move this post out of the trash.') );
218 if ( ! wp_untrash_post($post_id) )
219 wp_die( __('Error in restoring from trash...') );
221 wp_redirect( add_query_arg('untrashed', 1, $sendback) );
226 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
227 check_admin_referer('delete-post_' . $post_id);
229 $post = & get_post($post_id);
231 if ( !current_user_can('delete_post', $post_id) )
232 wp_die( __('You are not allowed to delete this post.') );
234 $force = !EMPTY_TRASH_DAYS;
235 if ( $post->post_type == 'attachment' ) {
236 $force = ( $force || !MEDIA_TRASH );
237 if ( ! wp_delete_attachment($post_id, $force) )
238 wp_die( __('Error in deleting...') );
240 if ( !wp_delete_post($post_id, $force) )
241 wp_die( __('Error in deleting...') );
244 wp_redirect( add_query_arg('deleted', 1, $sendback) );
249 check_admin_referer( 'autosave', 'autosavenonce' );
251 $url = post_preview();
258 wp_redirect('edit.php');
262 include('admin-footer.php');