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 function redirect_post($post_ID = '') {
13 if ( !empty($_POST['referredby']) ) {
14 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
15 $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
17 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
19 if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
20 $location = $_POST['referredby'];
21 } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
22 $location = 'sidebar.php?a=b';
23 } elseif ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
24 if ( $_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 )
25 $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "post.php?action=edit&post=$post_ID&message=1" );
27 $location = "post.php?action=edit&post=$post_ID&message=4";
28 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
29 $location = add_query_arg( 'message', 2, wp_get_referer() );
30 $location = explode('#', $location);
31 $location = $location[0] . '#postcustom';
32 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
33 $location = add_query_arg( 'message', 3, wp_get_referer() );
34 $location = explode('#', $location);
35 $location = $location[0] . '#postcustom';
36 } elseif (!empty($referredby) && $referredby != $referer) {
37 $location = $_POST['referredby'];
38 $location = remove_query_arg('_wp_original_http_referer', $location);
39 if ( $_POST['referredby'] == 'redo' )
40 $location = get_permalink( $post_ID );
41 elseif ( false !== strpos($location, 'edit.php') )
42 $location = add_query_arg('posted', $post_ID, $location);
43 elseif ( false !== strpos($location, 'wp-admin') )
44 $location = "post-new.php?posted=$post_ID";
45 } elseif ( isset($_POST['publish']) ) {
46 $location = "post-new.php?posted=$post_ID";
47 } elseif ($action == 'editattachment') {
48 $location = 'attachments.php';
50 $location = "post.php?action=edit&post=$post_ID&message=4";
53 wp_redirect( $location );
56 if ( isset( $_POST['deletepost'] ) )
62 check_admin_referer('add-post');
64 $post_ID = 'post' == $action ? write_post() : edit_post();
66 redirect_post($post_ID);
74 if ( empty( $_GET['post'] ) ) {
75 wp_redirect("post.php");
78 $post_ID = $p = (int) $_GET['post'];
79 $post = get_post($post_ID);
81 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
83 if ( 'page' == $post->post_type ) {
84 wp_redirect("page.php?action=edit&post=$post_ID");
88 wp_enqueue_script('post');
89 if ( user_can_richedit() )
90 wp_enqueue_script('editor');
91 wp_enqueue_script('thickbox');
92 wp_enqueue_script('media-upload');
94 if ( current_user_can('edit_post', $post_ID) ) {
95 if ( $last = wp_check_post_lock( $post->ID ) ) {
96 $last_user = get_userdata( $last );
97 $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
98 $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
99 $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
100 add_action('admin_notices', create_function( '', "echo '$message';" ) );
102 wp_set_post_lock( $post->ID );
103 wp_enqueue_script('autosave');
107 require_once('admin-header.php');
109 if ( !current_user_can('edit_post', $post_ID) )
110 die ( __('You are not allowed to edit this post.') );
112 $post = get_post_to_edit($post_ID);
114 include('edit-form-advanced.php');
118 case 'editattachment':
119 $post_id = (int) $_POST['post_ID'];
121 check_admin_referer('update-attachment_' . $post_id);
123 // Don't let these be changed
124 unset($_POST['guid']);
125 $_POST['post_type'] = 'attachment';
127 // Update the thumbnail filename
128 $newmeta = wp_get_attachment_metadata( $post_id, true );
129 $newmeta['thumb'] = $_POST['thumb'];
131 wp_update_attachment_metadata( $post_id, $newmeta );
134 $post_ID = (int) $_POST['post_ID'];
135 check_admin_referer('update-post_' . $post_ID);
137 $post_ID = edit_post();
139 redirect_post($post_ID); // 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');