3 * Edit post administration panel.
5 * Manage Post actions: post, edit, delete, etc.
8 * @subpackage Administration
11 /** WordPress Administration Bootstrap */
12 require_once( dirname( __FILE__ ) . '/admin.php' );
14 $parent_file = 'edit.php';
15 $submenu_file = 'edit.php';
17 wp_reset_vars( array( 'action' ) );
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;
27 * @global string $post_type
28 * @global object $post_type_object
29 * @global WP_Post $post
31 global $post_type, $post_type_object, $post;
34 $post = get_post( $post_id );
37 $post_type = $post->post_type;
38 $post_type_object = get_post_type_object( $post_type );
41 if ( isset( $_POST['deletepost'] ) )
43 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
46 $sendback = wp_get_referer();
48 strpos( $sendback, 'post.php' ) !== false ||
49 strpos( $sendback, 'post-new.php' ) !== false ) {
50 if ( 'attachment' == $post_type ) {
51 $sendback = admin_url( 'upload.php' );
53 $sendback = admin_url( 'edit.php' );
54 if ( ! empty( $post_type ) ) {
55 $sendback = add_query_arg( 'post_type', $post_type, $sendback );
59 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
63 case 'post-quickdraft-save':
64 // Check nonce and capabilities
65 $nonce = $_REQUEST['_wpnonce'];
68 // For output of the quickdraft dashboard widget
69 require_once ABSPATH . 'wp-admin/includes/dashboard.php';
71 if ( ! wp_verify_nonce( $nonce, 'add-post' ) )
72 $error_msg = __( 'Unable to submit this form, please refresh and try again.' );
74 if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
79 return wp_dashboard_quick_press( $error_msg );
81 $post = get_post( $_REQUEST['post_ID'] );
82 check_admin_referer( 'add-' . $post->post_type );
84 $_POST['comment_status'] = get_default_comment_status( $post->post_type );
85 $_POST['ping_status'] = get_default_comment_status( $post->post_type, 'pingback' );
88 wp_dashboard_quick_press();
93 check_admin_referer( 'add-' . $post_type );
94 $post_id = 'postajaxpost' == $action ? edit_post() : write_post();
95 redirect_post( $post_id );
101 if ( empty( $post_id ) ) {
102 wp_redirect( admin_url('post.php') );
107 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
109 if ( ! $post_type_object )
110 wp_die( __( 'Unknown post type.' ) );
112 if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
113 wp_die( __( 'You are not allowed to edit posts in this post type.' ) );
116 if ( ! current_user_can( 'edit_post', $post_id ) )
117 wp_die( __( 'You are not allowed to edit this item.' ) );
119 if ( 'trash' == $post->post_status )
120 wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) );
122 if ( ! empty( $_GET['get-post-lock'] ) ) {
123 check_admin_referer( 'lock-post_' . $post_id );
124 wp_set_post_lock( $post_id );
125 wp_redirect( get_edit_post_link( $post_id, 'url' ) );
129 $post_type = $post->post_type;
130 if ( 'post' == $post_type ) {
131 $parent_file = "edit.php";
132 $submenu_file = "edit.php";
133 $post_new_file = "post-new.php";
134 } elseif ( 'attachment' == $post_type ) {
135 $parent_file = 'upload.php';
136 $submenu_file = 'upload.php';
137 $post_new_file = 'media-new.php';
139 if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
140 $parent_file = $post_type_object->show_in_menu;
142 $parent_file = "edit.php?post_type=$post_type";
143 $submenu_file = "edit.php?post_type=$post_type";
144 $post_new_file = "post-new.php?post_type=$post_type";
147 if ( ! wp_check_post_lock( $post->ID ) ) {
148 $active_post_lock = wp_set_post_lock( $post->ID );
150 if ( 'attachment' !== $post_type )
151 wp_enqueue_script('autosave');
154 if ( is_multisite() ) {
155 add_action( 'admin_footer', '_admin_notice_post_locked' );
157 $check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) );
159 if ( count( $check_users ) > 1 )
160 add_action( 'admin_footer', '_admin_notice_post_locked' );
162 unset( $check_users );
165 $title = $post_type_object->labels->edit_item;
166 $post = get_post($post_id, OBJECT, 'edit');
168 if ( post_type_supports($post_type, 'comments') ) {
169 wp_enqueue_script('admin-comments');
170 enqueue_comment_hotkeys_js();
173 include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
177 case 'editattachment':
178 check_admin_referer('update-post_' . $post_id);
180 // Don't let these be changed
181 unset($_POST['guid']);
182 $_POST['post_type'] = 'attachment';
184 // Update the thumbnail filename
185 $newmeta = wp_get_attachment_metadata( $post_id, true );
186 $newmeta['thumb'] = $_POST['thumb'];
188 wp_update_attachment_metadata( $post_id, $newmeta );
191 check_admin_referer('update-post_' . $post_id);
193 $post_id = edit_post();
195 // Session cookie flag that the post was saved
196 if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
197 setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
200 redirect_post($post_id); // Send user on their way while we keep working
205 check_admin_referer('trash-post_' . $post_id);
208 wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
210 if ( ! $post_type_object )
211 wp_die( __( 'Unknown post type.' ) );
213 if ( ! current_user_can( 'delete_post', $post_id ) )
214 wp_die( __( 'You are not allowed to move this item to the Trash.' ) );
216 if ( $user_id = wp_check_post_lock( $post_id ) ) {
217 $user = get_userdata( $user_id );
218 wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
221 if ( ! wp_trash_post( $post_id ) )
222 wp_die( __( 'Error in moving to Trash.' ) );
224 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
228 check_admin_referer('untrash-post_' . $post_id);
231 wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
233 if ( ! $post_type_object )
234 wp_die( __( 'Unknown post type.' ) );
236 if ( ! current_user_can( 'delete_post', $post_id ) )
237 wp_die( __( 'You are not allowed to restore this item from the Trash.' ) );
239 if ( ! wp_untrash_post( $post_id ) )
240 wp_die( __( 'Error in restoring from Trash.' ) );
242 wp_redirect( add_query_arg('untrashed', 1, $sendback) );
246 check_admin_referer('delete-post_' . $post_id);
249 wp_die( __( 'This item has already been deleted.' ) );
251 if ( ! $post_type_object )
252 wp_die( __( 'Unknown post type.' ) );
254 if ( ! current_user_can( 'delete_post', $post_id ) )
255 wp_die( __( 'You are not allowed to delete this item.' ) );
257 if ( $post->post_type == 'attachment' ) {
258 $force = ( ! MEDIA_TRASH );
259 if ( ! wp_delete_attachment( $post_id, $force ) )
260 wp_die( __( 'Error in deleting.' ) );
262 if ( ! wp_delete_post( $post_id, true ) )
263 wp_die( __( 'Error in deleting.' ) );
266 wp_redirect( add_query_arg('deleted', 1, $sendback) );
270 check_admin_referer( 'update-post_' . $post_id );
272 $url = post_preview();
278 wp_redirect( admin_url('edit.php') );
281 include( ABSPATH . 'wp-admin/admin-footer.php' );