2 require_once('admin.php');
4 $parent_file = 'edit.php';
5 $submenu_file = 'edit.php';
7 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
9 if ( isset( $_POST['deletepost'] ) )
15 $parent_file = 'post-new.php';
16 $submenu_file = 'post-new.php';
17 check_admin_referer('add-post');
19 $post_ID = 'post' == $action ? write_post() : edit_post();
22 if (!empty($_POST['mode'])) {
23 switch($_POST['mode']) {
25 $location = $_POST['referredby'];
28 $location = 'sidebar.php?a=b';
31 $location = 'post-new.php';
35 $location = "post-new.php?posted=$post_ID";
38 if ( isset($_POST['save']) )
39 $location = "post.php?action=edit&post=$post_ID";
41 if ( empty($post_ID) )
42 $location = 'post-new.php';
44 wp_redirect($location);
51 $post_ID = $p = (int) $_GET['post'];
52 $post = get_post($post_ID);
54 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
56 if ( 'page' == $post->post_type ) {
57 wp_redirect("page.php?action=edit&post=$post_ID");
61 if($post->post_status == 'draft') {
62 wp_enqueue_script('prototype');
63 wp_enqueue_script('autosave');
65 require_once('admin-header.php');
67 if ( !current_user_can('edit_post', $post_ID) )
68 die ( __('You are not allowed to edit this post.') );
70 $post = get_post_to_edit($post_ID);
72 include('edit-form-advanced.php');
76 case 'editattachment':
77 $post_id = (int) $_POST['post_ID'];
79 check_admin_referer('update-attachment_' . $post_id);
81 // Don't let these be changed
82 unset($_POST['guid']);
83 $_POST['post_type'] = 'attachment';
85 // Update the thumbnail filename
86 $newmeta = wp_get_attachment_metadata( $post_id, true );
87 $newmeta['thumb'] = $_POST['thumb'];
89 wp_update_attachment_metadata( $post_id, $newmeta );
92 $post_ID = (int) $_POST['post_ID'];
93 check_admin_referer('update-post_' . $post_ID);
95 $post_ID = edit_post();
97 if ( 'post' == $_POST['originalaction'] ) {
98 if (!empty($_POST['mode'])) {
99 switch($_POST['mode']) {
101 $location = $_POST['referredby'];
104 $location = 'sidebar.php?a=b';
107 $location = 'post-new.php';
111 $location = "post-new.php?posted=$post_ID";
114 if ( isset($_POST['save']) )
115 $location = "post.php?action=edit&post=$post_ID";
118 if ( !empty($_POST['referredby']) )
119 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
120 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
122 if ($_POST['save']) {
123 $location = "post.php?action=edit&post=$post_ID";
124 } elseif ($_POST['updatemeta']) {
125 $location = wp_get_referer() . '&message=2#postcustom';
126 } elseif ($_POST['deletemeta']) {
127 $location = wp_get_referer() . '&message=3#postcustom';
128 } elseif (!empty($referredby) && $referredby != $referer) {
129 $location = $_POST['referredby'];
130 if ( $_POST['referredby'] == 'redo' )
131 $location = get_permalink( $post_ID );
132 } elseif ($action == 'editattachment') {
133 $location = 'attachments.php';
135 $location = 'post-new.php';
139 wp_redirect($location); // Send user on their way while we keep working
145 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
146 check_admin_referer('delete-post_' . $post_id);
148 $post = & get_post($post_id);
150 if ( !current_user_can('delete_post', $post_id) )
151 wp_die( __('You are not allowed to delete this post.') );
153 if ( $post->post_type == 'attachment' ) {
154 if ( ! wp_delete_attachment($post_id) )
155 wp_die( __('Error in deleting...') );
157 if ( !wp_delete_post($post_id) )
158 wp_die( __('Error in deleting...') );
161 $sendback = wp_get_referer();
162 if (strpos($sendback, 'post.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/post-new.php';
163 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/attachments.php';
164 $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
165 wp_redirect($sendback);
170 wp_redirect('edit.php');
174 include('admin-footer.php');