WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[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 ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) { 55 if ( isset($_POST['saveasdraft']) ) 56 $location = 'sidebar.php?a=c'; 57 elseif ( isset($_POST['publish']) ) 58 $location = 'sidebar.php?a=b'; 59 } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) { 60 $status = get_post_status( $post_id ); 61 62 if ( isset( $_POST['publish'] ) ) { 63 switch ( $status ) { 64 case 'pending': 65 $message = 8; 66 break; 67 case 'future': 68 $message = 9; 69 break; 70 default: 71 $message = 6; 72 } 73 } else { 74 $message = 'draft' == $status ? 10 : 1; 75 } 76 77 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); 78 } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { 79 $location = add_query_arg( 'message', 2, wp_get_referer() ); 80 $location = explode('#', $location); 81 $location = $location[0] . '#postcustom'; 82 } elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) { 83 $location = add_query_arg( 'message', 3, wp_get_referer() ); 84 $location = explode('#', $location); 85 $location = $location[0] . '#postcustom'; 86 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { 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 ) ); 93 } 94 95 if ( isset( $_POST['deletepost'] ) ) 96 $action = 'delete'; 97 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) 98 $action = 'preview'; 99 100 $sendback = wp_get_referer(); 101 if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false ) { 102 $sendback = admin_url('edit.php'); 103 $sendback .= ( !empty( $post_type ) ) ? '?post_type=' . $post_type : ''; 104 } else { 105 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); 106 } 107 108 switch($action) { 109 case 'postajaxpost': 110 case 'post': 111 case 'post-quickpress-publish': 112 case 'post-quickpress-save': 113 check_admin_referer('add-' . $post_type); 114 115 if ( 'post-quickpress-publish' == $action ) 116 $_POST['publish'] = 'publish'; // tell write_post() to publish 117 118 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) { 119 $_POST['comment_status'] = get_option('default_comment_status'); 120 $_POST['ping_status'] = get_option('default_ping_status'); 121 } 122 123 if ( !empty( $_POST['quickpress_post_ID'] ) ) { 124 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID']; 125 $post_id = edit_post(); 126 } else { 127 $post_id = 'postajaxpost' == $action ? edit_post() : write_post(); 128 } 129 130 if ( 0 === strpos( $action, 'post-quickpress' ) ) { 131 $_POST['post_ID'] = $post_id; 132 // output the quickpress dashboard widget 133 require_once (ABSPATH . 'wp-admin/includes/dashboard.php'); 134 wp_dashboard_quick_press(); 135 exit; 136 } 137 138 redirect_post($post_id); 139 exit(); 140 break; 141 142 case 'edit': 143 $editing = true; 144 145 if ( empty( $post_id ) ) { 146 wp_redirect("post.php"); 147 exit(); 148 } 149 150 $p = $post_id; 151 152 if ( empty($post->ID) ) 153 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') ); 154 155 if ( !current_user_can($post_type_object->edit_cap, $post_id) ) 156 wp_die( __('You are not allowed to edit this item.') ); 157 158 if ( 'trash' == $post->post_status ) 159 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') ); 160 161 if ( null == $post_type_object ) 162 wp_die( __('Unknown post type.') ); 163 164 $post_type = $post->post_type; 165 if ( 'post' == $post_type ) { 166 $parent_file = "edit.php"; 167 $submenu_file = "edit.php"; 168 } else { 169 $parent_file = "edit.php?post_type=$post_type"; 170 $submenu_file = "edit.php?post_type=$post_type"; 171 } 172 173 wp_enqueue_script('post'); 174 if ( user_can_richedit() ) 175 wp_enqueue_script('editor'); 176 add_thickbox(); 177 wp_enqueue_script('media-upload'); 178 wp_enqueue_script('word-count'); 179 wp_enqueue_script( 'admin-comments' ); 180 enqueue_comment_hotkeys_js(); 181 182 if ( $last = wp_check_post_lock( $post->ID ) ) { 183 add_action('admin_notices', '_admin_notice_post_locked' ); 184 } else { 185 wp_set_post_lock( $post->ID ); 186 wp_enqueue_script('autosave'); 187 } 188 189 $title = sprintf(__('Edit %s'), $post_type_object->singular_label); 190 $post = get_post_to_edit($post_id); 191 192 include ('edit-form-advanced.php'); 193 194 break; 195 196 case 'editattachment': 197 check_admin_referer('update-attachment_' . $post_id); 198 199 // Don't let these be changed 200 unset($_POST['guid']); 201 $_POST['post_type'] = 'attachment'; 202 203 // Update the thumbnail filename 204 $newmeta = wp_get_attachment_metadata( $post_id, true ); 205 $newmeta['thumb'] = $_POST['thumb']; 206 207 wp_update_attachment_metadata( $post_id, $newmeta ); 208 209 case 'editpost': 210 check_admin_referer('update-' . $post_type . '_' . $post_id); 211 212 $post_id = edit_post(); 213 214 redirect_post($post_id); // Send user on their way while we keep working 215 216 exit(); 217 break; 218 219 case 'trash': 220 check_admin_referer('trash-' . $post_type . '_' . $post_id); 221 222 $post = & get_post($post_id); 223 224 if ( !current_user_can($post_type_object->delete_cap, $post_id) ) 225 wp_die( __('You are not allowed to move this item to the trash.') ); 226 227 if ( ! wp_trash_post($post_id) ) 228 wp_die( __('Error in moving to trash...') ); 229 230 wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) ); 231 exit(); 232 break; 233 234 case 'untrash': 235 check_admin_referer('untrash-' . $post_type . '_' . $post_id); 236 237 if ( !current_user_can($post_type_object->delete_cap, $post_id) ) 238 wp_die( __('You are not allowed to move this item out of the trash.') ); 239 240 if ( ! wp_untrash_post($post_id) ) 241 wp_die( __('Error in restoring from trash...') ); 242 243 wp_redirect( add_query_arg('untrashed', 1, $sendback) ); 244 exit(); 245 break; 246 247 case 'delete': 248 check_admin_referer('delete-' . $post_type . '_' . $post_id); 249 250 if ( !current_user_can($post_type_object->delete_cap, $post_id) ) 251 wp_die( __('You are not allowed to delete this item.') ); 252 253 $force = !EMPTY_TRASH_DAYS; 254 if ( $post->post_type == 'attachment' ) { 255 $force = ( $force || !MEDIA_TRASH ); 256 if ( ! wp_delete_attachment($post_id, $force) ) 257 wp_die( __('Error in deleting...') ); 258 } else { 259 if ( !wp_delete_post($post_id, $force) ) 260 wp_die( __('Error in deleting...') ); 261 } 262 263 wp_redirect( add_query_arg('deleted', 1, $sendback) ); 264 exit(); 265 break; 266 267 case 'preview': 268 check_admin_referer( 'autosave', 'autosavenonce' ); 269 270 $url = post_preview(); 271 272 wp_redirect($url); 273 exit(); 274 break; 275 276 default: 277 wp_redirect('edit.php'); 278 exit(); 279 break; 280 } // end switch 281 include ('admin-footer.php'); 282 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |