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']) ) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
42 if ( isset($_POST['_wp_original_http_referer']) && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post-new.php') === false )
43 $location = add_query_arg( array(
44 '_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ),
46 ), get_edit_post_link( $post_ID, 'url' ) );
48 if ( isset( $_POST['publish'] ) ) {
49 if ( 'pending' == get_post_status( $post_ID ) )
50 $location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) );
52 $location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) );
54 $location = add_query_arg( 'message', 7, get_edit_post_link( $post_ID, 'url' ) );
57 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
58 $location = add_query_arg( 'message', 2, wp_get_referer() );
59 $location = explode('#', $location);
60 $location = $location[0] . '#postcustom';
61 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
62 $location = add_query_arg( 'message', 3, wp_get_referer() );
63 $location = explode('#', $location);
64 $location = $location[0] . '#postcustom';
65 } elseif (!empty($referredby) && $referredby != $referer) {
66 $location = $_POST['referredby'];
67 $location = remove_query_arg('_wp_original_http_referer', $location);
68 if ( false !== strpos($location, 'edit.php') || false !== strpos($location, 'edit-post-drafts.php') )
69 $location = add_query_arg('posted', $post_ID, $location);
70 elseif ( false !== strpos($location, 'wp-admin') )
71 $location = "post-new.php?posted=$post_ID";
72 } elseif ( isset($_POST['publish']) ) {
73 $location = "post-new.php?posted=$post_ID";
74 } elseif ($action == 'editattachment') {
75 $location = 'attachments.php';
76 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
77 $location = "post.php?action=edit&post=$post_ID&message=7";
79 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
82 wp_redirect( $location );
85 if ( isset( $_POST['deletepost'] ) )
87 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
93 case 'post-quickpress-publish':
94 case 'post-quickpress-save':
95 check_admin_referer('add-post');
97 if ( 'post-quickpress-publish' == $action )
98 $_POST['publish'] = 'publish'; // tell write_post() to publish
100 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
101 $_POST['comment_status'] = get_option('default_comment_status');
102 $_POST['ping_status'] = get_option('default_ping_status');
105 if ( !empty( $_POST['quickpress_post_ID'] ) ) {
106 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
107 $post_ID = edit_post();
109 $post_ID = 'postajaxpost' == $action ? edit_post() : write_post();
112 if ( 0 === strpos( $action, 'post-quickpress' ) ) {
113 $_POST['post_ID'] = $post_ID;
114 // output the quickpress dashboard widget
115 require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
116 wp_dashboard_quick_press();
120 redirect_post($post_ID);
127 if ( empty( $_GET['post'] ) ) {
128 wp_redirect("post.php");
131 $post_ID = $p = (int) $_GET['post'];
132 $post = get_post($post_ID);
134 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
136 if ( 'post' != $post->post_type ) {
137 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
141 wp_enqueue_script('post');
142 if ( user_can_richedit() )
143 wp_enqueue_script('editor');
145 wp_enqueue_script('media-upload');
146 wp_enqueue_script('word-count');
147 wp_enqueue_script( 'admin-comments' );
148 enqueue_comment_hotkeys_js();
150 if ( current_user_can('edit_post', $post_ID) ) {
151 if ( $last = wp_check_post_lock( $post->ID ) ) {
152 $last_user = get_userdata( $last );
153 $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
154 $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
155 $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
156 add_action('admin_notices', create_function( '', "echo '$message';" ) );
158 wp_set_post_lock( $post->ID );
159 wp_enqueue_script('autosave');
163 $title = __('Edit Post');
165 if ( !current_user_can('edit_post', $post_ID) )
166 die ( __('You are not allowed to edit this post.') );
168 $post = get_post_to_edit($post_ID);
170 include('edit-form-advanced.php');
174 case 'editattachment':
175 $post_id = (int) $_POST['post_ID'];
177 check_admin_referer('update-attachment_' . $post_id);
179 // Don't let these be changed
180 unset($_POST['guid']);
181 $_POST['post_type'] = 'attachment';
183 // Update the thumbnail filename
184 $newmeta = wp_get_attachment_metadata( $post_id, true );
185 $newmeta['thumb'] = $_POST['thumb'];
187 wp_update_attachment_metadata( $post_id, $newmeta );
190 $post_ID = (int) $_POST['post_ID'];
191 check_admin_referer('update-post_' . $post_ID);
193 $post_ID = edit_post();
195 redirect_post($post_ID); // Send user on their way while we keep working
201 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
202 check_admin_referer('delete-post_' . $post_id);
204 $post = & get_post($post_id);
206 if ( !current_user_can('delete_post', $post_id) )
207 wp_die( __('You are not allowed to delete this post.') );
209 if ( $post->post_type == 'attachment' ) {
210 if ( ! wp_delete_attachment($post_id) )
211 wp_die( __('Error in deleting...') );
213 if ( !wp_delete_post($post_id) )
214 wp_die( __('Error in deleting...') );
217 $sendback = wp_get_referer();
218 if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1');
219 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
220 else $sendback = add_query_arg('deleted', 1, $sendback);
221 wp_redirect($sendback);
226 check_admin_referer( 'autosave', 'autosavenonce' );
228 $url = post_preview();
235 wp_redirect('edit.php');
239 include('admin-footer.php');