| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Edit post administration panel. 4 * 5 * Manage Post actions: 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.php'; 15 $submenu_file = 'edit.php'; 16 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 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 $post = null; 27 $post_type_object = null; 28 $post_type = null; 29 if ( $post_id ) { 30 $post = get_post($post_id); 31 if ( $post ) { 32 $post_type_object = get_post_type_object($post->post_type); 33 if ( $post_type_object ) { 34 $post_type = $post->post_type; 35 $current_screen->post_type = $post->post_type; 36 $current_screen->id = $current_screen->post_type; 37 } 38 } 39 } elseif ( isset($_POST['post_type']) ) { 40 $post_type_object = get_post_type_object($_POST['post_type']); 41 if ( $post_type_object ) { 42 $post_type = $post_type_object->name; 43 $current_screen->post_type = $post_type; 44 $current_screen->id = $current_screen->post_type; 45 } 46 } 47 48 /** 49 * Redirect to previous page. 50 * 51 * @param int $post_id Optional. Post ID. 52 */ 53 function redirect_post($post_id = '') { 54 if ( isset($_POST['save']) || isset($_POST['publish']) ) { 55 $status = get_post_status( $post_id ); 56 57 if ( isset( $_POST['publish'] ) ) { 58 switch ( $status ) { 59 case 'pending': 60 $message = 8; 61 break; 62 case 'future': 63 $message = 9; 64 break; 65 default: 66 $message = 6; 67 } 68 } else { 69 $message = 'draft' == $status ? 10 : 1; 70 } 71 72 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); 73 } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { 74 $location = add_query_arg( 'message', 2, wp_get_referer() ); 75 $location = explode('#', $location); 76 $location = $location[0] . '#postcustom'; 77 } elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) { 78 $location = add_query_arg( 'message', 3, wp_get_referer() ); 79 $location = explode('#', $location); 80 $location = $location[0] . '#postcustom'; 81 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { 82 $location = "post.php?action=edit&post=$post_id&message=7"; 83 } else { 84 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); 85 } 86 87 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); 88 exit; 89 } 90 91 if ( isset( $_POST['deletepost'] ) ) 92 $action = 'delete'; 93 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) 94 $action = 'preview'; 95 96 $sendback = wp_get_referer(); 97 if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false ) { 98 $sendback = admin_url('edit.php'); 99 $sendback .= ( !empty( $post_type ) ) ? '?post_type=' . $post_type : ''; 100 } else { 101 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); 102 } 103 104 switch($action) { 105 case 'postajaxpost': 106 case 'post': 107 case 'post-quickpress-publish': 108 case 'post-quickpress-save': 109 check_admin_referer('add-' . $post_type); 110 111 if ( 'post-quickpress-publish' == $action ) 112 $_POST['publish'] = 'publish'; // tell write_post() to publish 113 114 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) { 115 $_POST['comment_status'] = get_option('default_comment_status'); 116 $_POST['ping_status'] = get_option('default_ping_status'); 117 } 118 119 if ( !empty( $_POST['quickpress_post_ID'] ) ) { 120 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID']; 121 $post_id = edit_post(); 122 } else { 123 $post_id = 'postajaxpost' == $action ? edit_post() : write_post(); 124 } 125 126 if ( 0 === strpos( $action, 'post-quickpress' ) ) { 127 $_POST['post_ID'] = $post_id; 128 // output the quickpress dashboard widget 129 require_once (ABSPATH . 'wp-admin/includes/dashboard.php'); 130 wp_dashboard_quick_press(); 131 exit; 132 } 133 134 redirect_post($post_id); 135 exit(); 136 break; 137 138 case 'edit': 139 $editing = true; 140 141 if ( empty( $post_id ) ) { 142 wp_redirect( admin_url('post.php') ); 143 exit(); 144 } 145 146 $p = $post_id; 147 148 if ( empty($post->ID) ) 149 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') ); 150 151 if ( !current_user_can($post_type_object->cap->edit_post, $post_id) ) 152 wp_die( __('You are not allowed to edit this item.') ); 153 154 if ( 'trash' == $post->post_status ) 155 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') ); 156 157 if ( null == $post_type_object ) 158 wp_die( __('Unknown post type.') ); 159 160 $post_type = $post->post_type; 161 if ( 'post' == $post_type ) { 162 $parent_file = "edit.php"; 163 $submenu_file = "edit.php"; 164 $post_new_file = "post-new.php"; 165 } else { 166 if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) 167 $parent_file = $post_type_object->show_in_menu; 168 else 169 $parent_file = "edit.php?post_type=$post_type"; 170 $submenu_file = "edit.php?post_type=$post_type"; 171 $post_new_file = "post-new.php?post_type=$post_type"; 172 } 173 174 if ( $last = wp_check_post_lock( $post->ID ) ) { 175 add_action('admin_notices', '_admin_notice_post_locked' ); 176 } else { 177 wp_set_post_lock( $post->ID ); 178 wp_enqueue_script('autosave'); 179 } 180 181 $title = $post_type_object->labels->edit_item; 182 $post = get_post_to_edit($post_id); 183 184 if ( post_type_supports($post_type, 'comments') ) { 185 wp_enqueue_script('admin-comments'); 186 enqueue_comment_hotkeys_js(); 187 } 188 189 include ('./edit-form-advanced.php'); 190 191 break; 192 193 case 'editattachment': 194 check_admin_referer('update-attachment_' . $post_id); 195 196 // Don't let these be changed 197 unset($_POST['guid']); 198 $_POST['post_type'] = 'attachment'; 199 200 // Update the thumbnail filename 201 $newmeta = wp_get_attachment_metadata( $post_id, true ); 202 $newmeta['thumb'] = $_POST['thumb']; 203 204 wp_update_attachment_metadata( $post_id, $newmeta ); 205 206 case 'editpost': 207 check_admin_referer('update-' . $post_type . '_' . $post_id); 208 209 $post_id = edit_post(); 210 211 redirect_post($post_id); // Send user on their way while we keep working 212 213 exit(); 214 break; 215 216 case 'trash': 217 check_admin_referer('trash-' . $post_type . '_' . $post_id); 218 219 $post = & get_post($post_id); 220 221 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) 222 wp_die( __('You are not allowed to move this item to the Trash.') ); 223 224 if ( ! wp_trash_post($post_id) ) 225 wp_die( __('Error in moving to Trash.') ); 226 227 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) ); 228 exit(); 229 break; 230 231 case 'untrash': 232 check_admin_referer('untrash-' . $post_type . '_' . $post_id); 233 234 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) 235 wp_die( __('You are not allowed to move this item out of the Trash.') ); 236 237 if ( ! wp_untrash_post($post_id) ) 238 wp_die( __('Error in restoring from Trash.') ); 239 240 wp_redirect( add_query_arg('untrashed', 1, $sendback) ); 241 exit(); 242 break; 243 244 case 'delete': 245 check_admin_referer('delete-' . $post_type . '_' . $post_id); 246 247 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) 248 wp_die( __('You are not allowed to delete this item.') ); 249 250 $force = !EMPTY_TRASH_DAYS; 251 if ( $post->post_type == 'attachment' ) { 252 $force = ( $force || !MEDIA_TRASH ); 253 if ( ! wp_delete_attachment($post_id, $force) ) 254 wp_die( __('Error in deleting.') ); 255 } else { 256 if ( !wp_delete_post($post_id, $force) ) 257 wp_die( __('Error in deleting.') ); 258 } 259 260 wp_redirect( add_query_arg('deleted', 1, $sendback) ); 261 exit(); 262 break; 263 264 case 'preview': 265 check_admin_referer( 'autosave', 'autosavenonce' ); 266 267 $url = post_preview(); 268 269 wp_redirect($url); 270 exit(); 271 break; 272 273 default: 274 wp_redirect( admin_url('edit.php') ); 275 exit(); 276 break; 277 } // end switch 278 include ('./admin-footer.php'); 279 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |