|
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']) && 'bookmarklet' == $_POST['mode'] ) { |
|
35 $location = $_POST['referredby']; |
|
36 } elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) { |
|
37 $location = 'sidebar.php?a=b'; |
|
38 } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) { |
|
39 if ( isset( $_POST['publish'] ) ) { |
|
40 if ( 'pending' == get_post_status( $page_ID ) ) |
|
41 $location = add_query_arg( 'message', 6, get_edit_post_link( $page_ID, 'url' ) ); |
|
42 else |
|
43 $location = add_query_arg( 'message', 5, get_edit_post_link( $page_ID, 'url' ) ); |
|
44 } else { |
|
45 $location = add_query_arg( 'message', 1, get_edit_post_link( $page_ID, 'url' ) ); |
|
46 } |
|
47 } elseif ( isset($_POST['addmeta']) ) { |
|
48 $location = add_query_arg( 'message', 2, wp_get_referer() ); |
|
49 $location = explode('#', $location); |
|
50 $location = $location[0] . '#postcustom'; |
|
51 } elseif ( isset($_POST['deletemeta']) ) { |
|
52 $location = add_query_arg( 'message', 3, wp_get_referer() ); |
|
53 $location = explode('#', $location); |
|
54 $location = $location[0] . '#postcustom'; |
|
55 } elseif ($action == 'editattachment') { |
|
56 $location = 'attachments.php'; |
|
57 } else { |
|
58 $location = add_query_arg( 'message', 1, get_edit_post_link( $page_ID, 'url' ) ); |
|
59 } |
|
60 |
|
61 wp_redirect($location); |
|
62 } |
|
63 |
|
64 if (isset($_POST['deletepost'])) |
|
65 $action = "delete"; |
|
66 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) |
|
67 $action = 'preview'; |
|
68 |
|
69 switch($action) { |
|
70 case 'post': |
|
71 check_admin_referer('add-page'); |
|
72 $page_ID = write_post(); |
|
73 |
|
74 redirect_page($page_ID); |
|
75 |
|
76 exit(); |
|
77 break; |
|
78 |
|
79 case 'edit': |
|
80 $title = __('Edit Page'); |
|
81 $editing = true; |
|
82 $page_ID = $post_ID = $p = (int) $_GET['post']; |
|
83 $post = get_post_to_edit($page_ID); |
|
84 |
|
85 if ( empty($post->ID) ) wp_die( __('You attempted to edit a page that doesn’t exist. Perhaps it was deleted?') ); |
|
86 |
|
87 if ( 'page' != $post->post_type ) { |
|
88 wp_redirect( get_edit_post_link( $post_ID, 'url' ) ); |
|
89 exit(); |
|
90 } |
|
91 |
|
92 wp_enqueue_script('page'); |
|
93 if ( user_can_richedit() ) |
|
94 wp_enqueue_script('editor'); |
|
95 add_thickbox(); |
|
96 wp_enqueue_script('media-upload'); |
|
97 wp_enqueue_script('word-count'); |
|
98 |
|
99 if ( current_user_can('edit_page', $page_ID) ) { |
|
100 if ( $last = wp_check_post_lock( $post->ID ) ) { |
|
101 add_action('admin_notices', '_admin_notice_post_locked' ); |
|
102 } else { |
|
103 wp_set_post_lock( $post->ID ); |
|
104 wp_enqueue_script('autosave'); |
|
105 } |
|
106 } |
|
107 |
|
108 if ( !current_user_can('edit_page', $page_ID) ) |
|
109 die ( __('You are not allowed to edit this page.') ); |
|
110 |
|
111 include('edit-page-form.php'); |
|
112 break; |
|
113 |
|
114 case 'editattachment': |
|
115 $page_id = $post_ID = (int) $_POST['post_ID']; |
|
116 check_admin_referer('update-attachment_' . $page_id); |
|
117 |
|
118 // Don't let these be changed |
|
119 unset($_POST['guid']); |
|
120 $_POST['post_type'] = 'attachment'; |
|
121 |
|
122 // Update the thumbnail filename |
|
123 $newmeta = wp_get_attachment_metadata( $page_id, true ); |
|
124 $newmeta['thumb'] = $_POST['thumb']; |
|
125 |
|
126 wp_update_attachment_metadata( $newmeta ); |
|
127 |
|
128 case 'editpost': |
|
129 $page_ID = (int) $_POST['post_ID']; |
|
130 check_admin_referer('update-page_' . $page_ID); |
|
131 |
|
132 $page_ID = edit_post(); |
|
133 |
|
134 redirect_page($page_ID); |
|
135 |
|
136 exit(); |
|
137 break; |
|
138 |
|
139 case 'delete': |
|
140 $page_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']); |
|
141 check_admin_referer('delete-page_' . $page_id); |
|
142 |
|
143 $page = & get_post($page_id); |
|
144 |
|
145 if ( !current_user_can('delete_page', $page_id) ) |
|
146 wp_die( __('You are not allowed to delete this page.') ); |
|
147 |
|
148 if ( $page->post_type == 'attachment' ) { |
|
149 if ( ! wp_delete_attachment($page_id) ) |
|
150 wp_die( __('Error in deleting...') ); |
|
151 } else { |
|
152 if ( !wp_delete_post($page_id) ) |
|
153 wp_die( __('Error in deleting...') ); |
|
154 } |
|
155 |
|
156 $sendback = wp_get_referer(); |
|
157 if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?deleted=1'); |
|
158 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php'); |
|
159 else $sendback = add_query_arg('deleted', 1, $sendback); |
|
160 wp_redirect($sendback); |
|
161 exit(); |
|
162 break; |
|
163 |
|
164 case 'preview': |
|
165 check_admin_referer( 'autosave', 'autosavenonce' ); |
|
166 |
|
167 $url = post_preview(); |
|
168 |
|
169 wp_redirect($url); |
|
170 exit(); |
|
171 break; |
|
172 |
|
173 default: |
|
174 wp_redirect('edit-pages.php'); |
|
175 exit(); |
|
176 break; |
|
177 } // end switch |
|
178 include('admin-footer.php'); |
|
179 ?> |