Changeset 12708 for trunk/wp-admin/post.php
- Timestamp:
- 01/12/2010 04:50:37 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/post.php
r12597 r12708 17 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 18 19 if ( isset($_GET['post']) ) 20 $post_id = (int) $_GET['post']; 21 elseif ( isset($_POST['post_ID']) ) 22 $post_id = (int) $_POST['post_ID']; 23 else 24 $post_id = 0; 25 $post_ID = $post_id; 26 27 $post = null; 28 $post_type_object = null; 29 $post_type_cap = null; 30 if ( $post_id ) { 31 $post = get_post($post_id); 32 if ( $post ) { 33 $post_type_object = get_post_type_object($post->post_type); 34 if ( $post_type_object ) 35 $post_type_cap = $post_type_object->capability_type; 36 } 37 } 38 19 39 /** 20 40 * Redirect to previous page. 21 41 * 22 * @param int $post_ IDOptional. Post ID.42 * @param int $post_id Optional. Post ID. 23 43 */ 24 function redirect_post($post_ ID= '') {44 function redirect_post($post_id = '') { 25 45 global $action; 26 46 … … 38 58 $location = 'sidebar.php?a=b'; 39 59 } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) { 40 $status = get_post_status( $post_ ID);60 $status = get_post_status( $post_id ); 41 61 42 62 if ( isset( $_POST['publish'] ) ) { … … 55 75 } 56 76 57 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_ ID, 'url' ) );77 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); 58 78 } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { 59 79 $location = add_query_arg( 'message', 2, wp_get_referer() ); … … 65 85 $location = $location[0] . '#postcustom'; 66 86 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { 67 $location = "post.php?action=edit&post=$post_ ID&message=7";68 } else { 69 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ ID, 'url' ) );70 } 71 72 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_ ID) );87 $location = "post.php?action=edit&post=$post_id&message=7"; 88 } else { 89 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); 90 } 91 92 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); 73 93 } 74 94 … … 101 121 if ( !empty( $_POST['quickpress_post_ID'] ) ) { 102 122 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID']; 103 $post_ ID= edit_post();104 } else { 105 $post_ ID= 'postajaxpost' == $action ? edit_post() : write_post();123 $post_id = edit_post(); 124 } else { 125 $post_id = 'postajaxpost' == $action ? edit_post() : write_post(); 106 126 } 107 127 108 128 if ( 0 === strpos( $action, 'post-quickpress' ) ) { 109 $_POST['post_ID'] = $post_ ID;129 $_POST['post_ID'] = $post_id; 110 130 // output the quickpress dashboard widget 111 131 require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); … … 114 134 } 115 135 116 redirect_post($post_ ID);136 redirect_post($post_id); 117 137 exit(); 118 138 break; … … 121 141 $editing = true; 122 142 123 if ( empty( $ _GET['post']) ) {143 if ( empty( $post_id ) ) { 124 144 wp_redirect("post.php"); 125 145 exit(); 126 146 } 127 $post_ID = $p = (int) $_GET['post']; 128 $post = get_post($post_ID); 129 $post_type_object = get_post_type_object($post->post_type); 147 148 $p = $post_id; 130 149 131 150 if ( empty($post->ID) ) 132 wp_die( __('You attempted to edit a postthat doesn’t exist. Perhaps it was deleted?') );133 134 if ( !current_user_can( 'edit_post', $post_ID) )135 wp_die( __('You are not allowed to edit this post.') );151 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') ); 152 153 if ( !current_user_can($post_type_object->edit_cap, $post_id) ) 154 wp_die( __('You are not allowed to edit this item.') ); 136 155 137 156 if ( 'trash' == $post->post_status ) 138 wp_die( __('You can’t edit this postbecause it is in the Trash. Please restore it and try again.') );157 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') ); 139 158 140 159 if ( null == $post_type_object ) 141 160 wp_die( __('Unknown post type.') ); 142 161 143 if ( 'post' != $post->post_type && $post_type_object->_builtin ) {144 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );145 exit();146 }147 148 162 $post_type = $post->post_type; 149 if ( 'post' != $post_type ) { 150 $parent_file = "edit.php?post_type=$post_type"; 151 $submenu_file = "edit.php?post_type=$post_type"; 163 if ( 'post' == $post_type ) { 164 $parent_file = "edit.php"; 165 $submenu_file = "edit.php"; 166 } elseif ( 'page' == $post_type ) { 167 $parent_file = "edit-pages.php"; 168 $submenu_file = "edit-pages.php"; 169 } else { 170 if ( $post_type_object->hierarchical ) { 171 $parent_file = "edit-pages.php?post_type=$post_type"; 172 $submenu_file = "edit-pages.php?post_type=$post_type"; 173 } else { 174 $parent_file = "edit.php?post_type=$post_type"; 175 $submenu_file = "edit.php?post_type=$post_type"; 176 } 152 177 } 153 178 … … 169 194 170 195 $title = sprintf(__('Edit %s'), $post_type_object->label); 171 $post = get_post_to_edit($post_ ID);196 $post = get_post_to_edit($post_id); 172 197 173 198 include('edit-form-advanced.php'); … … 176 201 177 202 case 'editattachment': 178 $post_id = (int) $_POST['post_ID'];179 180 203 check_admin_referer('update-attachment_' . $post_id); 181 204 … … 191 214 192 215 case 'editpost': 193 $post_ID = (int) $_POST['post_ID']; 194 check_admin_referer('update-post_' . $post_ID); 195 196 $post_ID = edit_post(); 197 198 redirect_post($post_ID); // Send user on their way while we keep working 216 check_admin_referer('update-' . $post->post_type . '_' . $post_id); 217 218 $post_id = edit_post(); 219 220 redirect_post($post_id); // Send user on their way while we keep working 199 221 200 222 exit(); … … 202 224 203 225 case 'trash': 204 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);205 226 check_admin_referer('trash-post_' . $post_id); 206 227 207 228 $post = & get_post($post_id); 208 229 209 if ( !current_user_can('delete_ post', $post_id) )210 wp_die( __('You are not allowed to move this postto the trash.') );230 if ( !current_user_can('delete_' . $post_type_cap, $post_id) ) 231 wp_die( __('You are not allowed to move this item to the trash.') ); 211 232 212 233 if ( ! wp_trash_post($post_id) ) … … 218 239 219 240 case 'untrash': 220 $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);221 241 check_admin_referer('untrash-post_' . $post_id); 222 242 223 $post = & get_post($post_id); 224 225 if ( !current_user_can('delete_post', $post_id) ) 226 wp_die( __('You are not allowed to move this post out of the trash.') ); 243 if ( !current_user_can('delete_' . $post_type_cap, $post_id) ) 244 wp_die( __('You are not allowed to move this item out of the trash.') ); 227 245 228 246 if ( ! wp_untrash_post($post_id) ) … … 234 252 235 253 case 'delete': 236 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);237 254 check_admin_referer('delete-post_' . $post_id); 238 255 239 $post = & get_post($post_id); 240 241 if ( !current_user_can('delete_post', $post_id) ) 242 wp_die( __('You are not allowed to delete this post.') ); 256 if ( !current_user_can('delete_' . $post_type_cap, $post_id) ) 257 wp_die( __('You are not allowed to delete this item.') ); 243 258 244 259 $force = !EMPTY_TRASH_DAYS; … … 266 281 267 282 default: 268 wp_redirect('edit.php'); 283 if ( $post_type_object->hierarchical ) 284 wp_redirect('edit-pages.php'); 285 else 286 wp_redirect('edit.php'); 269 287 exit(); 270 288 break;
Note: See TracChangeset
for help on using the changeset viewer.