web/wp-admin/post.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    29 		$referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
    29 		$referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
    30 		$referredby = remove_query_arg('_wp_original_http_referer', $referredby);
    30 		$referredby = remove_query_arg('_wp_original_http_referer', $referredby);
    31 	}
    31 	}
    32 	$referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
    32 	$referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
    33 
    33 
    34 	if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
    34 	if ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
    35 		$location = $_POST['referredby'];
       
    36 	} elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
       
    37 		if ( isset($_POST['saveasdraft']) )
    35 		if ( isset($_POST['saveasdraft']) )
    38 			$location = 'sidebar.php?a=c';
    36 			$location = 'sidebar.php?a=c';
    39 		elseif ( isset($_POST['publish']) )
    37 		elseif ( isset($_POST['publish']) )
    40 			$location = 'sidebar.php?a=b';
    38 			$location = 'sidebar.php?a=b';
    41 	} elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) {
    39 	} elseif ( isset($_POST['save']) || isset($_POST['publish']) ) {
       
    40 		$status = get_post_status( $post_ID );
       
    41 
    42 		if ( isset( $_POST['publish'] ) ) {
    42 		if ( isset( $_POST['publish'] ) ) {
    43 			if ( 'pending' == get_post_status( $post_ID ) )
    43 			switch ( $status ) {
    44 				$location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) );
    44 				case 'pending':
    45 			else
    45 					$message = 8;
    46 				$location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) );
    46 					break;
       
    47 				case 'future':
       
    48 					$message = 9;
       
    49 					break;
       
    50 				default:
       
    51 					$message = 6;
       
    52 			}
    47 		} else {
    53 		} else {
    48 			$location = add_query_arg( 'message', 1, get_edit_post_link( $post_ID, 'url' ) );
    54 				$message = 'draft' == $status ? 10 : 1;
    49 		}
    55 		}
    50 	} elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
    56 
       
    57 		$location = add_query_arg( 'message', $message, get_edit_post_link( $post_ID, 'url' ) );
       
    58 	} elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
    51 		$location = add_query_arg( 'message', 2, wp_get_referer() );
    59 		$location = add_query_arg( 'message', 2, wp_get_referer() );
    52 		$location = explode('#', $location);
    60 		$location = explode('#', $location);
    53 		$location = $location[0] . '#postcustom';
    61 		$location = $location[0] . '#postcustom';
    54 	} elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
    62 	} elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
    55 		$location = add_query_arg( 'message', 3, wp_get_referer() );
    63 		$location = add_query_arg( 'message', 3, wp_get_referer() );
    56 		$location = explode('#', $location);
    64 		$location = explode('#', $location);
    57 		$location = $location[0] . '#postcustom';
    65 		$location = $location[0] . '#postcustom';
    58 	} elseif ($action == 'editattachment') {
       
    59 		$location = 'attachments.php';
       
    60 	} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
    66 	} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
    61 		$location = "post.php?action=edit&post=$post_ID&message=7";
    67 		$location = "post.php?action=edit&post=$post_ID&message=7";
    62 	} else {
    68 	} else {
    63 		$location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
    69 		$location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
    64 	}
    70 	}
    65 
    71 
    66 	wp_redirect( $location );
    72 	wp_redirect( apply_filters( 'redirect_post_location', $location, $post_ID ) );
    67 }
    73 }
    68 
    74 
    69 if ( isset( $_POST['deletepost'] ) )
    75 if ( isset( $_POST['deletepost'] ) )
    70 	$action = 'delete';
    76 	$action = 'delete';
    71 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
    77 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
    72 	$action = '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 );
    73 
    85 
    74 switch($action) {
    86 switch($action) {
    75 case 'postajaxpost':
    87 case 'postajaxpost':
    76 case 'post':
    88 case 'post':
    77 case 'post-quickpress-publish':
    89 case 'post-quickpress-publish':
   113 		exit();
   125 		exit();
   114 	}
   126 	}
   115 	$post_ID = $p = (int) $_GET['post'];
   127 	$post_ID = $p = (int) $_GET['post'];
   116 	$post = get_post($post_ID);
   128 	$post = get_post($post_ID);
   117 
   129 
   118 	if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') );
   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.') );
   119 
   138 
   120 	if ( 'post' != $post->post_type ) {
   139 	if ( 'post' != $post->post_type ) {
   121 		wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
   140 		wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
   122 		exit();
   141 		exit();
   123 	}
   142 	}
   129 	wp_enqueue_script('media-upload');
   148 	wp_enqueue_script('media-upload');
   130 	wp_enqueue_script('word-count');
   149 	wp_enqueue_script('word-count');
   131 	wp_enqueue_script( 'admin-comments' );
   150 	wp_enqueue_script( 'admin-comments' );
   132 	enqueue_comment_hotkeys_js();
   151 	enqueue_comment_hotkeys_js();
   133 
   152 
   134 	if ( current_user_can('edit_post', $post_ID) ) {
   153 	if ( $last = wp_check_post_lock( $post->ID ) ) {
   135 		if ( $last = wp_check_post_lock( $post->ID ) ) {
   154 		add_action('admin_notices', '_admin_notice_post_locked' );
   136 			add_action('admin_notices', '_admin_notice_post_locked' );
   155 	} else {
   137 		} else {
   156 		wp_set_post_lock( $post->ID );
   138 			wp_set_post_lock( $post->ID );
   157 		wp_enqueue_script('autosave');
   139 			wp_enqueue_script('autosave');
       
   140 		}
       
   141 	}
   158 	}
   142 
   159 
   143 	$title = __('Edit Post');
   160 	$title = __('Edit Post');
   144 
       
   145 	if ( !current_user_can('edit_post', $post_ID) )
       
   146 		die ( __('You are not allowed to edit this post.') );
       
   147 
       
   148 	$post = get_post_to_edit($post_ID);
   161 	$post = get_post_to_edit($post_ID);
   149 
   162 
   150 	include('edit-form-advanced.php');
   163 	include('edit-form-advanced.php');
   151 
   164 
   152 	break;
   165 	break;
   175 	redirect_post($post_ID); // Send user on their way while we keep working
   188 	redirect_post($post_ID); // Send user on their way while we keep working
   176 
   189 
   177 	exit();
   190 	exit();
   178 	break;
   191 	break;
   179 
   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 
   180 case 'delete':
   225 case 'delete':
   181 	$post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
   226 	$post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
   182 	check_admin_referer('delete-post_' . $post_id);
   227 	check_admin_referer('delete-post_' . $post_id);
   183 
   228 
   184 	$post = & get_post($post_id);
   229 	$post = & get_post($post_id);
   185 
   230 
   186 	if ( !current_user_can('delete_post', $post_id) )
   231 	if ( !current_user_can('delete_post', $post_id) )
   187 		wp_die( __('You are not allowed to delete this post.') );
   232 		wp_die( __('You are not allowed to delete this post.') );
   188 
   233 
       
   234 	$force = !EMPTY_TRASH_DAYS;
   189 	if ( $post->post_type == 'attachment' ) {
   235 	if ( $post->post_type == 'attachment' ) {
   190 		if ( ! wp_delete_attachment($post_id) )
   236 		$force = ( $force || !MEDIA_TRASH );
       
   237 		if ( ! wp_delete_attachment($post_id, $force) )
   191 			wp_die( __('Error in deleting...') );
   238 			wp_die( __('Error in deleting...') );
   192 	} else {
   239 	} else {
   193 		if ( !wp_delete_post($post_id) )
   240 		if ( !wp_delete_post($post_id, $force) )
   194 			wp_die( __('Error in deleting...') );
   241 			wp_die( __('Error in deleting...') );
   195 	}
   242 	}
   196 
   243 
   197 	$sendback = wp_get_referer();
   244 	wp_redirect( add_query_arg('deleted', 1, $sendback) );
   198 	if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1');
       
   199 	elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
       
   200 	else $sendback = add_query_arg('deleted', 1, $sendback);
       
   201 	wp_redirect($sendback);
       
   202 	exit();
   245 	exit();
   203 	break;
   246 	break;
   204 
   247 
   205 case 'preview':
   248 case 'preview':
   206 	check_admin_referer( 'autosave', 'autosavenonce' );
   249 	check_admin_referer( 'autosave', 'autosavenonce' );