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 | $last_user = get_userdata( $last );
|
---|
102 | $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
|
---|
103 | $message = sprintf( __( 'Warning: %s is currently editing this page' ), esc_html( $last_user_name ) );
|
---|
104 | $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
|
---|
105 | add_action('admin_notices', create_function( '', "echo '$message';" ) );
|
---|
106 | } else {
|
---|
107 | wp_set_post_lock( $post->ID );
|
---|
108 | wp_enqueue_script('autosave');
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | if ( !current_user_can('edit_page', $page_ID) )
|
---|
113 | die ( __('You are not allowed to edit this page.') );
|
---|
114 |
|
---|
115 | include('edit-page-form.php');
|
---|
116 | break;
|
---|
117 |
|
---|
118 | case 'editattachment':
|
---|
119 | $page_id = $post_ID = (int) $_POST['post_ID'];
|
---|
120 | check_admin_referer('update-attachment_' . $page_id);
|
---|
121 |
|
---|
122 | // Don't let these be changed
|
---|
123 | unset($_POST['guid']);
|
---|
124 | $_POST['post_type'] = 'attachment';
|
---|
125 |
|
---|
126 | // Update the thumbnail filename
|
---|
127 | $newmeta = wp_get_attachment_metadata( $page_id, true );
|
---|
128 | $newmeta['thumb'] = $_POST['thumb'];
|
---|
129 |
|
---|
130 | wp_update_attachment_metadata( $newmeta );
|
---|
131 |
|
---|
132 | case 'editpost':
|
---|
133 | $page_ID = (int) $_POST['post_ID'];
|
---|
134 | check_admin_referer('update-page_' . $page_ID);
|
---|
135 |
|
---|
136 | $page_ID = edit_post();
|
---|
137 |
|
---|
138 | redirect_page($page_ID);
|
---|
139 |
|
---|
140 | exit();
|
---|
141 | break;
|
---|
142 |
|
---|
143 | case 'delete':
|
---|
144 | $page_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
|
---|
145 | check_admin_referer('delete-page_' . $page_id);
|
---|
146 |
|
---|
147 | $page = & get_post($page_id);
|
---|
148 |
|
---|
149 | if ( !current_user_can('delete_page', $page_id) )
|
---|
150 | wp_die( __('You are not allowed to delete this page.') );
|
---|
151 |
|
---|
152 | if ( $page->post_type == 'attachment' ) {
|
---|
153 | if ( ! wp_delete_attachment($page_id) )
|
---|
154 | wp_die( __('Error in deleting...') );
|
---|
155 | } else {
|
---|
156 | if ( !wp_delete_post($page_id) )
|
---|
157 | wp_die( __('Error in deleting...') );
|
---|
158 | }
|
---|
159 |
|
---|
160 | $sendback = wp_get_referer();
|
---|
161 | if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?deleted=1');
|
---|
162 | elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
|
---|
163 | else $sendback = add_query_arg('deleted', 1, $sendback);
|
---|
164 | wp_redirect($sendback);
|
---|
165 | exit();
|
---|
166 | break;
|
---|
167 |
|
---|
168 | case 'preview':
|
---|
169 | check_admin_referer( 'autosave', 'autosavenonce' );
|
---|
170 |
|
---|
171 | $url = post_preview();
|
---|
172 |
|
---|
173 | wp_redirect($url);
|
---|
174 | exit();
|
---|
175 | break;
|
---|
176 |
|
---|
177 | default:
|
---|
178 | wp_redirect('edit-pages.php');
|
---|
179 | exit();
|
---|
180 | break;
|
---|
181 | } // end switch
|
---|
182 | include('admin-footer.php');
|
---|
183 | ?>
|
---|