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