|
1 <?php |
|
2 /** |
|
3 * Edit post administration panel. |
|
4 * |
|
5 * Manage Post actions: post, edit, delete, etc. |
|
6 * |
|
7 * @package WordPress |
|
8 * @subpackage Administration |
|
9 */ |
|
10 |
|
11 /** WordPress Administration Bootstrap */ |
|
12 require_once('admin.php'); |
|
13 |
|
14 $parent_file = 'edit.php'; |
|
15 $submenu_file = 'edit.php'; |
|
16 |
|
17 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder')); |
|
18 |
|
19 /** |
|
20 * Redirect to previous page. |
|
21 * |
|
22 * @param int $post_ID Optional. Post ID. |
|
23 */ |
|
24 function redirect_post($post_ID = '') { |
|
25 global $action; |
|
26 |
|
27 $referredby = ''; |
|
28 if ( !empty($_POST['referredby']) ) { |
|
29 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']); |
|
30 $referredby = remove_query_arg('_wp_original_http_referer', $referredby); |
|
31 } |
|
32 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer()); |
|
33 |
|
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']) ) ) { |
|
42 if ( isset( $_POST['publish'] ) ) { |
|
43 if ( 'pending' == get_post_status( $post_ID ) ) |
|
44 $location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) ); |
|
45 else |
|
46 $location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) ); |
|
47 } else { |
|
48 $location = add_query_arg( 'message', 1, get_edit_post_link( $post_ID, 'url' ) ); |
|
49 } |
|
50 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) { |
|
51 $location = add_query_arg( 'message', 2, wp_get_referer() ); |
|
52 $location = explode('#', $location); |
|
53 $location = $location[0] . '#postcustom'; |
|
54 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) { |
|
55 $location = add_query_arg( 'message', 3, wp_get_referer() ); |
|
56 $location = explode('#', $location); |
|
57 $location = $location[0] . '#postcustom'; |
|
58 } elseif ($action == 'editattachment') { |
|
59 $location = 'attachments.php'; |
|
60 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { |
|
61 $location = "post.php?action=edit&post=$post_ID&message=7"; |
|
62 } else { |
|
63 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) ); |
|
64 } |
|
65 |
|
66 wp_redirect( $location ); |
|
67 } |
|
68 |
|
69 if ( isset( $_POST['deletepost'] ) ) |
|
70 $action = 'delete'; |
|
71 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) |
|
72 $action = 'preview'; |
|
73 |
|
74 switch($action) { |
|
75 case 'postajaxpost': |
|
76 case 'post': |
|
77 case 'post-quickpress-publish': |
|
78 case 'post-quickpress-save': |
|
79 check_admin_referer('add-post'); |
|
80 |
|
81 if ( 'post-quickpress-publish' == $action ) |
|
82 $_POST['publish'] = 'publish'; // tell write_post() to publish |
|
83 |
|
84 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) { |
|
85 $_POST['comment_status'] = get_option('default_comment_status'); |
|
86 $_POST['ping_status'] = get_option('default_ping_status'); |
|
87 } |
|
88 |
|
89 if ( !empty( $_POST['quickpress_post_ID'] ) ) { |
|
90 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID']; |
|
91 $post_ID = edit_post(); |
|
92 } else { |
|
93 $post_ID = 'postajaxpost' == $action ? edit_post() : write_post(); |
|
94 } |
|
95 |
|
96 if ( 0 === strpos( $action, 'post-quickpress' ) ) { |
|
97 $_POST['post_ID'] = $post_ID; |
|
98 // output the quickpress dashboard widget |
|
99 require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); |
|
100 wp_dashboard_quick_press(); |
|
101 exit; |
|
102 } |
|
103 |
|
104 redirect_post($post_ID); |
|
105 exit(); |
|
106 break; |
|
107 |
|
108 case 'edit': |
|
109 $editing = true; |
|
110 |
|
111 if ( empty( $_GET['post'] ) ) { |
|
112 wp_redirect("post.php"); |
|
113 exit(); |
|
114 } |
|
115 $post_ID = $p = (int) $_GET['post']; |
|
116 $post = get_post($post_ID); |
|
117 |
|
118 if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') ); |
|
119 |
|
120 if ( 'post' != $post->post_type ) { |
|
121 wp_redirect( get_edit_post_link( $post->ID, 'url' ) ); |
|
122 exit(); |
|
123 } |
|
124 |
|
125 wp_enqueue_script('post'); |
|
126 if ( user_can_richedit() ) |
|
127 wp_enqueue_script('editor'); |
|
128 add_thickbox(); |
|
129 wp_enqueue_script('media-upload'); |
|
130 wp_enqueue_script('word-count'); |
|
131 wp_enqueue_script( 'admin-comments' ); |
|
132 enqueue_comment_hotkeys_js(); |
|
133 |
|
134 if ( current_user_can('edit_post', $post_ID) ) { |
|
135 if ( $last = wp_check_post_lock( $post->ID ) ) { |
|
136 add_action('admin_notices', '_admin_notice_post_locked' ); |
|
137 } else { |
|
138 wp_set_post_lock( $post->ID ); |
|
139 wp_enqueue_script('autosave'); |
|
140 } |
|
141 } |
|
142 |
|
143 $title = __('Edit Post'); |
|
144 |
|
145 if ( !current_user_can('edit_post', $post_ID) ) |
|
146 die ( __('You are not allowed to edit this post.') ); |
|
147 |
|
148 $post = get_post_to_edit($post_ID); |
|
149 |
|
150 include('edit-form-advanced.php'); |
|
151 |
|
152 break; |
|
153 |
|
154 case 'editattachment': |
|
155 $post_id = (int) $_POST['post_ID']; |
|
156 |
|
157 check_admin_referer('update-attachment_' . $post_id); |
|
158 |
|
159 // Don't let these be changed |
|
160 unset($_POST['guid']); |
|
161 $_POST['post_type'] = 'attachment'; |
|
162 |
|
163 // Update the thumbnail filename |
|
164 $newmeta = wp_get_attachment_metadata( $post_id, true ); |
|
165 $newmeta['thumb'] = $_POST['thumb']; |
|
166 |
|
167 wp_update_attachment_metadata( $post_id, $newmeta ); |
|
168 |
|
169 case 'editpost': |
|
170 $post_ID = (int) $_POST['post_ID']; |
|
171 check_admin_referer('update-post_' . $post_ID); |
|
172 |
|
173 $post_ID = edit_post(); |
|
174 |
|
175 redirect_post($post_ID); // Send user on their way while we keep working |
|
176 |
|
177 exit(); |
|
178 break; |
|
179 |
|
180 case 'delete': |
|
181 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']); |
|
182 check_admin_referer('delete-post_' . $post_id); |
|
183 |
|
184 $post = & get_post($post_id); |
|
185 |
|
186 if ( !current_user_can('delete_post', $post_id) ) |
|
187 wp_die( __('You are not allowed to delete this post.') ); |
|
188 |
|
189 if ( $post->post_type == 'attachment' ) { |
|
190 if ( ! wp_delete_attachment($post_id) ) |
|
191 wp_die( __('Error in deleting...') ); |
|
192 } else { |
|
193 if ( !wp_delete_post($post_id) ) |
|
194 wp_die( __('Error in deleting...') ); |
|
195 } |
|
196 |
|
197 $sendback = wp_get_referer(); |
|
198 if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1'); |
|
199 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php'); |
|
200 else $sendback = add_query_arg('deleted', 1, $sendback); |
|
201 wp_redirect($sendback); |
|
202 exit(); |
|
203 break; |
|
204 |
|
205 case 'preview': |
|
206 check_admin_referer( 'autosave', 'autosavenonce' ); |
|
207 |
|
208 $url = post_preview(); |
|
209 |
|
210 wp_redirect($url); |
|
211 exit(); |
|
212 break; |
|
213 |
|
214 default: |
|
215 wp_redirect('edit.php'); |
|
216 exit(); |
|
217 break; |
|
218 } // end switch |
|
219 include('admin-footer.php'); |
|
220 ?> |