|
1 <?php |
|
2 /** |
|
3 * Edit page administration panel. |
|
4 * |
|
5 * Manage edit page: 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-pages.php'; |
|
15 $submenu_file = 'edit-pages.php'; |
|
16 |
|
17 wp_reset_vars(array('action')); |
|
18 |
|
19 /** |
|
20 * Redirect to previous page. |
|
21 * |
|
22 * @param int $page_ID Page ID. |
|
23 */ |
|
24 function redirect_page($page_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 ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) { |
|
35 $location = 'sidebar.php?a=b'; |
|
36 } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) { |
|
37 $status = get_post_status( $page_ID ); |
|
38 |
|
39 if ( isset( $_POST['publish'] ) ) { |
|
40 switch ( $status ) { |
|
41 case 'pending': |
|
42 $message = 6; |
|
43 break; |
|
44 case 'future': |
|
45 $message = 7; |
|
46 break; |
|
47 default: |
|
48 $message = 4; |
|
49 } |
|
50 } else { |
|
51 $message = 'draft' == $status ? 8 : 1; |
|
52 } |
|
53 |
|
54 $location = add_query_arg( 'message', $message, get_edit_post_link( $page_ID, 'url' ) ); |
|
55 } elseif ( isset($_POST['addmeta']) ) { |
|
56 $location = add_query_arg( 'message', 2, wp_get_referer() ); |
|
57 $location = explode('#', $location); |
|
58 $location = $location[0] . '#postcustom'; |
|
59 } elseif ( isset($_POST['deletemeta']) ) { |
|
60 $location = add_query_arg( 'message', 3, wp_get_referer() ); |
|
61 $location = explode('#', $location); |
|
62 $location = $location[0] . '#postcustom'; |
|
63 } else { |
|
64 $location = add_query_arg( 'message', 1, get_edit_post_link( $page_ID, 'url' ) ); |
|
65 } |
|
66 |
|
67 wp_redirect( apply_filters( 'redirect_page_location', $location, $page_ID ) ); |
|
68 } |
|
69 |
|
70 if (isset($_POST['deletepost'])) |
|
71 $action = "delete"; |
|
72 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) |
|
73 $action = 'preview'; |
|
74 |
|
75 $sendback = wp_get_referer(); |
|
76 if ( strpos($sendback, 'page.php') !== false || strpos($sendback, 'page-new.php') !== false ) |
|
77 $sendback = admin_url('edit-pages.php'); |
|
78 else |
|
79 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); |
|
80 |
|
81 switch($action) { |
|
82 case 'post': |
|
83 check_admin_referer('add-page'); |
|
84 $page_ID = write_post(); |
|
85 |
|
86 redirect_page($page_ID); |
|
87 |
|
88 exit(); |
|
89 break; |
|
90 |
|
91 case 'edit': |
|
92 $title = __('Edit Page'); |
|
93 $editing = true; |
|
94 $page_ID = $post_ID = $p = (int) $_GET['post']; |
|
95 $post = get_post_to_edit($page_ID); |
|
96 |
|
97 if ( empty($post->ID) ) |
|
98 wp_die( __('You attempted to edit a page that doesn’t exist. Perhaps it was deleted?') ); |
|
99 |
|
100 if ( !current_user_can('edit_page', $page_ID) ) |
|
101 wp_die( __('You are not allowed to edit this page.') ); |
|
102 |
|
103 if ( 'trash' == $post->post_status ) |
|
104 wp_die( __('You can’t edit this page because it is in the Trash. Please move it out of the Trash and try again.') ); |
|
105 |
|
106 if ( 'page' != $post->post_type ) { |
|
107 wp_redirect( get_edit_post_link( $post_ID, 'url' ) ); |
|
108 exit(); |
|
109 } |
|
110 |
|
111 wp_enqueue_script('post'); |
|
112 if ( user_can_richedit() ) |
|
113 wp_enqueue_script('editor'); |
|
114 add_thickbox(); |
|
115 wp_enqueue_script('media-upload'); |
|
116 wp_enqueue_script('word-count'); |
|
117 |
|
118 if ( $last = wp_check_post_lock( $post->ID ) ) { |
|
119 add_action('admin_notices', '_admin_notice_post_locked' ); |
|
120 } else { |
|
121 wp_set_post_lock( $post->ID ); |
|
122 wp_enqueue_script('autosave'); |
|
123 } |
|
124 |
|
125 include('edit-page-form.php'); |
|
126 break; |
|
127 |
|
128 case 'editattachment': |
|
129 $page_id = $post_ID = (int) $_POST['post_ID']; |
|
130 check_admin_referer('update-attachment_' . $page_id); |
|
131 |
|
132 // Don't let these be changed |
|
133 unset($_POST['guid']); |
|
134 $_POST['post_type'] = 'attachment'; |
|
135 |
|
136 // Update the thumbnail filename |
|
137 $newmeta = wp_get_attachment_metadata( $page_id, true ); |
|
138 $newmeta['thumb'] = $_POST['thumb']; |
|
139 |
|
140 wp_update_attachment_metadata( $newmeta ); |
|
141 |
|
142 case 'editpost': |
|
143 $page_ID = (int) $_POST['post_ID']; |
|
144 check_admin_referer('update-page_' . $page_ID); |
|
145 |
|
146 $page_ID = edit_post(); |
|
147 |
|
148 redirect_page($page_ID); |
|
149 |
|
150 exit(); |
|
151 break; |
|
152 |
|
153 case 'trash': |
|
154 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']); |
|
155 check_admin_referer('trash-page_' . $post_id); |
|
156 |
|
157 $post = & get_post($post_id); |
|
158 |
|
159 if ( !current_user_can('delete_page', $post_id) ) |
|
160 wp_die( __('You are not allowed to move this page to the trash.') ); |
|
161 |
|
162 if ( !wp_trash_post($post_id) ) |
|
163 wp_die( __('Error in moving to trash...') ); |
|
164 |
|
165 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) ); |
|
166 exit(); |
|
167 break; |
|
168 |
|
169 case 'untrash': |
|
170 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']); |
|
171 check_admin_referer('untrash-page_' . $post_id); |
|
172 |
|
173 $post = & get_post($post_id); |
|
174 |
|
175 if ( !current_user_can('delete_page', $post_id) ) |
|
176 wp_die( __('You are not allowed to move this page out of the trash.') ); |
|
177 |
|
178 if ( !wp_untrash_post($post_id) ) |
|
179 wp_die( __('Error in restoring from trash...') ); |
|
180 |
|
181 wp_redirect( add_query_arg('untrashed', 1, $sendback) ); |
|
182 exit(); |
|
183 break; |
|
184 |
|
185 case 'delete': |
|
186 $page_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']); |
|
187 check_admin_referer('delete-page_' . $page_id); |
|
188 |
|
189 $page = & get_post($page_id); |
|
190 |
|
191 if ( !current_user_can('delete_page', $page_id) ) |
|
192 wp_die( __('You are not allowed to delete this page.') ); |
|
193 |
|
194 if ( $page->post_type == 'attachment' ) { |
|
195 if ( ! wp_delete_attachment($page_id) ) |
|
196 wp_die( __('Error in deleting...') ); |
|
197 } else { |
|
198 if ( !wp_delete_post($page_id) ) |
|
199 wp_die( __('Error in deleting...') ); |
|
200 } |
|
201 |
|
202 wp_redirect( add_query_arg('deleted', 1, $sendback) ); |
|
203 exit(); |
|
204 break; |
|
205 |
|
206 case 'preview': |
|
207 check_admin_referer( 'autosave', 'autosavenonce' ); |
|
208 |
|
209 $url = post_preview(); |
|
210 |
|
211 wp_redirect($url); |
|
212 exit(); |
|
213 break; |
|
214 |
|
215 default: |
|
216 wp_redirect('edit-pages.php'); |
|
217 exit(); |
|
218 break; |
|
219 } // end switch |
|
220 include('admin-footer.php'); |
|
221 ?> |