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']) && 'bookmarklet' == $_POST['mode'] ) {
35 $location = $_POST['referredby'];
36 } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
37 if ( isset($_POST['saveasdraft']) )
38 $location = 'sidebar.php?a=c';
39 elseif ( isset($_POST['publish']) )
40 $location = 'sidebar.php?a=b';
41 } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) {
42 if ( isset( $_POST['publish'] ) ) {
43 if ( 'pending' == get_post_status( $post_ID ) )
44 $location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) );
46 $location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) );
48 $location = add_query_arg( 'message', 1, get_edit_post_link( $post_ID, 'url' ) );
50 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
51 $location = add_query_arg( 'message', 2, wp_get_referer() );
52 $location = explode('#', $location);
53 $location = $location[0] . '#postcustom';
54 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
55 $location = add_query_arg( 'message', 3, wp_get_referer() );
56 $location = explode('#', $location);
57 $location = $location[0] . '#postcustom';
58 } elseif ($action == 'editattachment') {
59 $location = 'attachments.php';
60 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
61 $location = "post.php?action=edit&post=$post_ID&message=7";
63 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
66 wp_redirect( $location );
69 if ( isset( $_POST['deletepost'] ) )
71 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
77 case 'post-quickpress-publish':
78 case 'post-quickpress-save':
79 check_admin_referer('add-post');
81 if ( 'post-quickpress-publish' == $action )
82 $_POST['publish'] = 'publish'; // tell write_post() to publish
84 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
85 $_POST['comment_status'] = get_option('default_comment_status');
86 $_POST['ping_status'] = get_option('default_ping_status');
89 if ( !empty( $_POST['quickpress_post_ID'] ) ) {
90 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
91 $post_ID = edit_post();
93 $post_ID = 'postajaxpost' == $action ? edit_post() : write_post();
96 if ( 0 === strpos( $action, 'post-quickpress' ) ) {
97 $_POST['post_ID'] = $post_ID;
98 // output the quickpress dashboard widget
99 require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
100 wp_dashboard_quick_press();
104 redirect_post($post_ID);
111 if ( empty( $_GET['post'] ) ) {
112 wp_redirect("post.php");
115 $post_ID = $p = (int) $_GET['post'];
116 $post = get_post($post_ID);
118 if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') );
120 if ( 'post' != $post->post_type ) {
121 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
125 wp_enqueue_script('post');
126 if ( user_can_richedit() )
127 wp_enqueue_script('editor');
129 wp_enqueue_script('media-upload');
130 wp_enqueue_script('word-count');
131 wp_enqueue_script( 'admin-comments' );
132 enqueue_comment_hotkeys_js();
134 if ( current_user_can('edit_post', $post_ID) ) {
135 if ( $last = wp_check_post_lock( $post->ID ) ) {
136 add_action('admin_notices', '_admin_notice_post_locked' );
138 wp_set_post_lock( $post->ID );
139 wp_enqueue_script('autosave');
143 $title = __('Edit Post');
145 if ( !current_user_can('edit_post', $post_ID) )
146 die ( __('You are not allowed to edit this post.') );
148 $post = get_post_to_edit($post_ID);
150 include('edit-form-advanced.php');
154 case 'editattachment':
155 $post_id = (int) $_POST['post_ID'];
157 check_admin_referer('update-attachment_' . $post_id);
159 // Don't let these be changed
160 unset($_POST['guid']);
161 $_POST['post_type'] = 'attachment';
163 // Update the thumbnail filename
164 $newmeta = wp_get_attachment_metadata( $post_id, true );
165 $newmeta['thumb'] = $_POST['thumb'];
167 wp_update_attachment_metadata( $post_id, $newmeta );
170 $post_ID = (int) $_POST['post_ID'];
171 check_admin_referer('update-post_' . $post_ID);
173 $post_ID = edit_post();
175 redirect_post($post_ID); // Send user on their way while we keep working
181 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
182 check_admin_referer('delete-post_' . $post_id);
184 $post = & get_post($post_id);
186 if ( !current_user_can('delete_post', $post_id) )
187 wp_die( __('You are not allowed to delete this post.') );
189 if ( $post->post_type == 'attachment' ) {
190 if ( ! wp_delete_attachment($post_id) )
191 wp_die( __('Error in deleting...') );
193 if ( !wp_delete_post($post_id) )
194 wp_die( __('Error in deleting...') );
197 $sendback = wp_get_referer();
198 if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1');
199 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
200 else $sendback = add_query_arg('deleted', 1, $sendback);
201 wp_redirect($sendback);
206 check_admin_referer( 'autosave', 'autosavenonce' );
208 $url = post_preview();
215 wp_redirect('edit.php');
219 include('admin-footer.php');