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 ( false !== strpos($location, 'edit.php') )
40 $location = add_query_arg('posted', $post_ID, $location);
41 elseif ( false !== strpos($location, 'wp-admin') )
42 $location = "post-new.php?posted=$post_ID";
43 } elseif ( isset($_POST['publish']) ) {
44 $location = "post-new.php?posted=$post_ID";
45 } elseif ($action == 'editattachment') {
46 $location = 'attachments.php';
48 $location = "post.php?action=edit&post=$post_ID&message=4";
51 wp_redirect( $location );
54 if ( isset( $_POST['deletepost'] ) )
60 check_admin_referer('add-post');
62 $post_ID = 'post' == $action ? write_post() : edit_post();
64 redirect_post($post_ID);
72 if ( empty( $_GET['post'] ) ) {
73 wp_redirect("post.php");
76 $post_ID = $p = (int) $_GET['post'];
77 $post = get_post($post_ID);
79 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
81 if ( 'post' != $post->post_type ) {
82 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
86 wp_enqueue_script('post');
87 if ( user_can_richedit() )
88 wp_enqueue_script('editor');
90 wp_enqueue_script('media-upload');
91 wp_enqueue_script('word-count');
93 if ( current_user_can('edit_post', $post_ID) ) {
94 if ( $last = wp_check_post_lock( $post->ID ) ) {
95 $last_user = get_userdata( $last );
96 $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
97 $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
98 $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
99 add_action('admin_notices', create_function( '', "echo '$message';" ) );
101 wp_set_post_lock( $post->ID );
102 wp_enqueue_script('autosave');
106 require_once('admin-header.php');
108 if ( !current_user_can('edit_post', $post_ID) )
109 die ( __('You are not allowed to edit this post.') );
111 $post = get_post_to_edit($post_ID);
113 include('edit-form-advanced.php');
117 case 'editattachment':
118 $post_id = (int) $_POST['post_ID'];
120 check_admin_referer('update-attachment_' . $post_id);
122 // Don't let these be changed
123 unset($_POST['guid']);
124 $_POST['post_type'] = 'attachment';
126 // Update the thumbnail filename
127 $newmeta = wp_get_attachment_metadata( $post_id, true );
128 $newmeta['thumb'] = $_POST['thumb'];
130 wp_update_attachment_metadata( $post_id, $newmeta );
133 $post_ID = (int) $_POST['post_ID'];
134 check_admin_referer('update-post_' . $post_ID);
136 $post_ID = edit_post();
138 redirect_post($post_ID); // Send user on their way while we keep working
144 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
145 check_admin_referer('delete-post_' . $post_id);
147 $post = & get_post($post_id);
149 if ( !current_user_can('delete_post', $post_id) )
150 wp_die( __('You are not allowed to delete this post.') );
152 if ( $post->post_type == 'attachment' ) {
153 if ( ! wp_delete_attachment($post_id) )
154 wp_die( __('Error in deleting...') );
156 if ( !wp_delete_post($post_id) )
157 wp_die( __('Error in deleting...') );
160 $sendback = wp_get_referer();
161 if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('post-new.php');
162 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
163 $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
164 wp_redirect($sendback);
169 wp_redirect('edit.php');
173 include('admin-footer.php');