| [ Index ] |
PHP Cross Reference of Wordpress 2.7.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']) && 'bookmarklet' == $_POST['mode'] ) { 35 $location = $_POST['referredby']; 36 } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) { 37 if ( isset($_POST['saveasdraft']) ) 38 $location = 'sidebar.php?a=c'; 39 elseif ( isset($_POST['publish']) ) 40 $location = 'sidebar.php?a=b'; 41 } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) { 42 if ( isset($_POST['_wp_original_http_referer']) && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post-new.php') === false ) 43 $location = add_query_arg( array( 44 '_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), 45 'message' => 1 46 ), get_edit_post_link( $post_ID, 'url' ) ); 47 else { 48 if ( isset( $_POST['publish'] ) ) { 49 if ( 'pending' == get_post_status( $post_ID ) ) 50 $location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) ); 51 else 52 $location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) ); 53 } else { 54 $location = add_query_arg( 'message', 7, get_edit_post_link( $post_ID, 'url' ) ); 55 } 56 } 57 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) { 58 $location = add_query_arg( 'message', 2, wp_get_referer() ); 59 $location = explode('#', $location); 60 $location = $location[0] . '#postcustom'; 61 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) { 62 $location = add_query_arg( 'message', 3, wp_get_referer() ); 63 $location = explode('#', $location); 64 $location = $location[0] . '#postcustom'; 65 } elseif (!empty($referredby) && $referredby != $referer) { 66 $location = $_POST['referredby']; 67 $location = remove_query_arg('_wp_original_http_referer', $location); 68 if ( false !== strpos($location, 'edit.php') || false !== strpos($location, 'edit-post-drafts.php') ) 69 $location = add_query_arg('posted', $post_ID, $location); 70 elseif ( false !== strpos($location, 'wp-admin') ) 71 $location = "post-new.php?posted=$post_ID"; 72 } elseif ( isset($_POST['publish']) ) { 73 $location = "post-new.php?posted=$post_ID"; 74 } elseif ($action == 'editattachment') { 75 $location = 'attachments.php'; 76 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { 77 $location = "post.php?action=edit&post=$post_ID&message=7"; 78 } else { 79 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) ); 80 } 81 82 wp_redirect( $location ); 83 } 84 85 if ( isset( $_POST['deletepost'] ) ) 86 $action = 'delete'; 87 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) 88 $action = 'preview'; 89 90 switch($action) { 91 case 'postajaxpost': 92 case 'post': 93 case 'post-quickpress-publish': 94 case 'post-quickpress-save': 95 check_admin_referer('add-post'); 96 97 if ( 'post-quickpress-publish' == $action ) 98 $_POST['publish'] = 'publish'; // tell write_post() to publish 99 100 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) { 101 $_POST['comment_status'] = get_option('default_comment_status'); 102 $_POST['ping_status'] = get_option('default_ping_status'); 103 } 104 105 if ( !empty( $_POST['quickpress_post_ID'] ) ) { 106 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID']; 107 $post_ID = edit_post(); 108 } else { 109 $post_ID = 'postajaxpost' == $action ? edit_post() : write_post(); 110 } 111 112 if ( 0 === strpos( $action, 'post-quickpress' ) ) { 113 $_POST['post_ID'] = $post_ID; 114 // output the quickpress dashboard widget 115 require_once (ABSPATH . 'wp-admin/includes/dashboard.php'); 116 wp_dashboard_quick_press(); 117 exit; 118 } 119 120 redirect_post($post_ID); 121 exit(); 122 break; 123 124 case 'edit': 125 $editing = true; 126 127 if ( empty( $_GET['post'] ) ) { 128 wp_redirect("post.php"); 129 exit(); 130 } 131 $post_ID = $p = (int) $_GET['post']; 132 $post = get_post($post_ID); 133 134 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") ); 135 136 if ( 'post' != $post->post_type ) { 137 wp_redirect( get_edit_post_link( $post->ID, 'url' ) ); 138 exit(); 139 } 140 141 wp_enqueue_script('post'); 142 if ( user_can_richedit() ) 143 wp_enqueue_script('editor'); 144 add_thickbox(); 145 wp_enqueue_script('media-upload'); 146 wp_enqueue_script('word-count'); 147 wp_enqueue_script( 'admin-comments' ); 148 enqueue_comment_hotkeys_js(); 149 150 if ( current_user_can('edit_post', $post_ID) ) { 151 if ( $last = wp_check_post_lock( $post->ID ) ) { 152 $last_user = get_userdata( $last ); 153 $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); 154 $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) ); 155 $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" ); 156 add_action('admin_notices', create_function( '', "echo '$message';" ) ); 157 } else { 158 wp_set_post_lock( $post->ID ); 159 wp_enqueue_script('autosave'); 160 } 161 } 162 163 $title = __('Edit Post'); 164 165 if ( !current_user_can('edit_post', $post_ID) ) 166 die ( __('You are not allowed to edit this post.') ); 167 168 $post = get_post_to_edit($post_ID); 169 170 include ('edit-form-advanced.php'); 171 172 break; 173 174 case 'editattachment': 175 $post_id = (int) $_POST['post_ID']; 176 177 check_admin_referer('update-attachment_' . $post_id); 178 179 // Don't let these be changed 180 unset($_POST['guid']); 181 $_POST['post_type'] = 'attachment'; 182 183 // Update the thumbnail filename 184 $newmeta = wp_get_attachment_metadata( $post_id, true ); 185 $newmeta['thumb'] = $_POST['thumb']; 186 187 wp_update_attachment_metadata( $post_id, $newmeta ); 188 189 case 'editpost': 190 $post_ID = (int) $_POST['post_ID']; 191 check_admin_referer('update-post_' . $post_ID); 192 193 $post_ID = edit_post(); 194 195 redirect_post($post_ID); // Send user on their way while we keep working 196 197 exit(); 198 break; 199 200 case 'delete': 201 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']); 202 check_admin_referer('delete-post_' . $post_id); 203 204 $post = & get_post($post_id); 205 206 if ( !current_user_can('delete_post', $post_id) ) 207 wp_die( __('You are not allowed to delete this post.') ); 208 209 if ( $post->post_type == 'attachment' ) { 210 if ( ! wp_delete_attachment($post_id) ) 211 wp_die( __('Error in deleting...') ); 212 } else { 213 if ( !wp_delete_post($post_id) ) 214 wp_die( __('Error in deleting...') ); 215 } 216 217 $sendback = wp_get_referer(); 218 if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1'); 219 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php'); 220 else $sendback = add_query_arg('deleted', 1, $sendback); 221 wp_redirect($sendback); 222 exit(); 223 break; 224 225 case 'preview': 226 check_admin_referer( 'autosave', 'autosavenonce' ); 227 228 $url = post_preview(); 229 230 wp_redirect($url); 231 exit(); 232 break; 233 234 default: 235 wp_redirect('edit.php'); 236 exit(); 237 break; 238 } // end switch 239 include ('admin-footer.php'); 240 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Mar 23 16:23:02 2009 | Cross-referenced by PHPXref 0.7 |