3 * Edit page administration panel.
5 * Manage edit page: post, edit, delete, etc.
8 * @subpackage Administration
11 /** WordPress Administration Bootstrap */
12 require_once('admin.php');
14 $parent_file = 'edit-pages.php';
15 $submenu_file = 'edit-pages.php';
17 wp_reset_vars(array('action'));
20 * Redirect to previous page.
22 * @param int $page_ID Page ID.
24 function redirect_page($page_ID) {
28 if ( !empty($_POST['referredby']) ) {
29 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
30 $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
32 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
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 );
39 if ( isset( $_POST['publish'] ) ) {
51 $message = 'draft' == $status ? 8 : 1;
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';
64 $location = add_query_arg( 'message', 1, get_edit_post_link( $page_ID, 'url' ) );
67 wp_redirect( apply_filters( 'redirect_page_location', $location, $page_ID ) );
70 if (isset($_POST['deletepost']))
72 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
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');
79 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
83 check_admin_referer('add-page');
84 $page_ID = write_post();
86 redirect_page($page_ID);
92 $title = __('Edit Page');
94 $page_ID = $post_ID = $p = (int) $_GET['post'];
95 $post = get_post_to_edit($page_ID);
97 if ( empty($post->ID) )
98 wp_die( __('You attempted to edit a page that doesn’t exist. Perhaps it was deleted?') );
100 if ( !current_user_can('edit_page', $page_ID) )
101 wp_die( __('You are not allowed to edit this page.') );
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.') );
106 if ( 'page' != $post->post_type ) {
107 wp_redirect( get_edit_post_link( $post_ID, 'url' ) );
111 wp_enqueue_script('post');
112 if ( user_can_richedit() )
113 wp_enqueue_script('editor');
115 wp_enqueue_script('media-upload');
116 wp_enqueue_script('word-count');
118 if ( $last = wp_check_post_lock( $post->ID ) ) {
119 add_action('admin_notices', '_admin_notice_post_locked' );
121 wp_set_post_lock( $post->ID );
122 wp_enqueue_script('autosave');
125 include('edit-page-form.php');
128 case 'editattachment':
129 $page_id = $post_ID = (int) $_POST['post_ID'];
130 check_admin_referer('update-attachment_' . $page_id);
132 // Don't let these be changed
133 unset($_POST['guid']);
134 $_POST['post_type'] = 'attachment';
136 // Update the thumbnail filename
137 $newmeta = wp_get_attachment_metadata( $page_id, true );
138 $newmeta['thumb'] = $_POST['thumb'];
140 wp_update_attachment_metadata( $newmeta );
143 $page_ID = (int) $_POST['post_ID'];
144 check_admin_referer('update-page_' . $page_ID);
146 $page_ID = edit_post();
148 redirect_page($page_ID);
154 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
155 check_admin_referer('trash-page_' . $post_id);
157 $post = & get_post($post_id);
159 if ( !current_user_can('delete_page', $post_id) )
160 wp_die( __('You are not allowed to move this page to the trash.') );
162 if ( !wp_trash_post($post_id) )
163 wp_die( __('Error in moving to trash...') );
165 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
170 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
171 check_admin_referer('untrash-page_' . $post_id);
173 $post = & get_post($post_id);
175 if ( !current_user_can('delete_page', $post_id) )
176 wp_die( __('You are not allowed to move this page out of the trash.') );
178 if ( !wp_untrash_post($post_id) )
179 wp_die( __('Error in restoring from trash...') );
181 wp_redirect( add_query_arg('untrashed', 1, $sendback) );
186 $page_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
187 check_admin_referer('delete-page_' . $page_id);
189 $page = & get_post($page_id);
191 if ( !current_user_can('delete_page', $page_id) )
192 wp_die( __('You are not allowed to delete this page.') );
194 if ( $page->post_type == 'attachment' ) {
195 if ( ! wp_delete_attachment($page_id) )
196 wp_die( __('Error in deleting...') );
198 if ( !wp_delete_post($page_id) )
199 wp_die( __('Error in deleting...') );
202 wp_redirect( add_query_arg('deleted', 1, $sendback) );
207 check_admin_referer( 'autosave', 'autosavenonce' );
209 $url = post_preview();
216 wp_redirect('edit-pages.php');
220 include('admin-footer.php');