wp/wp-admin/post.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    21 elseif ( isset( $_POST['post_ID'] ) )
    21 elseif ( isset( $_POST['post_ID'] ) )
    22  	$post_id = $post_ID = (int) $_POST['post_ID'];
    22  	$post_id = $post_ID = (int) $_POST['post_ID'];
    23 else
    23 else
    24  	$post_id = $post_ID = 0;
    24  	$post_id = $post_ID = 0;
    25 
    25 
    26 $post = $post_type = $post_type_object = null;
    26 global $post_type, $post_type_object, $post;
    27 
    27 
    28 if ( $post_id )
    28 if ( $post_id )
    29 	$post = get_post( $post_id );
    29 	$post = get_post( $post_id );
    30 
    30 
    31 if ( $post ) {
    31 if ( $post ) {
    64 		$location = $location[0] . '#postcustom';
    64 		$location = $location[0] . '#postcustom';
    65 	} elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
    65 	} elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
    66 		$location = add_query_arg( 'message', 3, wp_get_referer() );
    66 		$location = add_query_arg( 'message', 3, wp_get_referer() );
    67 		$location = explode('#', $location);
    67 		$location = explode('#', $location);
    68 		$location = $location[0] . '#postcustom';
    68 		$location = $location[0] . '#postcustom';
    69 	} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
       
    70 		$location = "post.php?action=edit&post=$post_id&message=7";
       
    71 	} else {
    69 	} else {
    72 		$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
    70 		$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
    73 	}
    71 	}
    74 
    72 
       
    73 	/**
       
    74 	 * Filter the post redirect destination URL.
       
    75 	 *
       
    76 	 * @since 2.9.0
       
    77 	 *
       
    78 	 * @param string $location The destination URL.
       
    79 	 * @param int    $post_id  The post ID.
       
    80 	 */
    75 	wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
    81 	wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
    76 	exit;
    82 	exit;
    77 }
    83 }
    78 
    84 
    79 if ( isset( $_POST['deletepost'] ) )
    85 if ( isset( $_POST['deletepost'] ) )
    87      strpos( $sendback, 'post-new.php' ) !== false ) {
    93      strpos( $sendback, 'post-new.php' ) !== false ) {
    88 	if ( 'attachment' == $post_type ) {
    94 	if ( 'attachment' == $post_type ) {
    89 		$sendback = admin_url( 'upload.php' );
    95 		$sendback = admin_url( 'upload.php' );
    90 	} else {
    96 	} else {
    91 		$sendback = admin_url( 'edit.php' );
    97 		$sendback = admin_url( 'edit.php' );
    92 		$sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : '';
    98 		if ( ! empty( $post_type ) ) {
       
    99 			$sendback = add_query_arg( 'post_type', $post_type, $sendback );
       
   100 		}
    93 	}
   101 	}
    94 } else {
   102 } else {
    95 	$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
   103 	$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
    96 }
   104 }
    97 
   105 
    98 switch($action) {
   106 switch($action) {
       
   107 case 'post-quickdraft-save':
       
   108 	// Check nonce and capabilities
       
   109 	$nonce = $_REQUEST['_wpnonce'];
       
   110 	$error_msg = false;
       
   111 
       
   112 	// For output of the quickdraft dashboard widget
       
   113 	require_once ABSPATH . 'wp-admin/includes/dashboard.php';
       
   114 
       
   115 	if ( ! wp_verify_nonce( $nonce, 'add-post' ) )
       
   116 		$error_msg = __( 'Unable to submit this form, please refresh and try again.' );
       
   117 
       
   118 	if ( ! current_user_can( 'edit_posts' ) )
       
   119 		$error_msg = __( 'Oops, you don’t have access to add new drafts.' );
       
   120 
       
   121 	if ( $error_msg )
       
   122 		return wp_dashboard_quick_press( $error_msg );
       
   123 
       
   124 	$post = get_post( $_REQUEST['post_ID'] );
       
   125 	check_admin_referer( 'add-' . $post->post_type );
       
   126 
       
   127 	$_POST['comment_status'] = get_option( 'default_comment_status' );
       
   128 	$_POST['ping_status'] = get_option( 'default_ping_status' );
       
   129 
       
   130 	edit_post();
       
   131 	wp_dashboard_quick_press();
       
   132 	exit;
       
   133 
    99 case 'postajaxpost':
   134 case 'postajaxpost':
   100 case 'post':
   135 case 'post':
   101 case 'post-quickpress-publish':
   136 	check_admin_referer( 'add-' . $post_type );
   102 case 'post-quickpress-save':
   137 	$post_id = 'postajaxpost' == $action ? edit_post() : write_post();
   103 	check_admin_referer('add-' . $post_type);
   138 	redirect_post( $post_id );
   104 
   139 	exit();
   105 	if ( 'post-quickpress-publish' == $action )
       
   106 		$_POST['publish'] = 'publish'; // tell write_post() to publish
       
   107 
       
   108 	if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
       
   109 		$_POST['comment_status'] = get_option('default_comment_status');
       
   110 		$_POST['ping_status'] = get_option('default_ping_status');
       
   111 		$post_id = edit_post();
       
   112 	} else {
       
   113 		$post_id = 'postajaxpost' == $action ? edit_post() : write_post();
       
   114 	}
       
   115 
       
   116 	if ( 0 === strpos( $action, 'post-quickpress' ) ) {
       
   117 		$_POST['post_ID'] = $post_id;
       
   118 		// output the quickpress dashboard widget
       
   119 		require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
       
   120 		wp_dashboard_quick_press();
       
   121 		exit;
       
   122 	}
       
   123 
       
   124 	redirect_post($post_id);
       
   125 	exit();
       
   126 	break;
       
   127 
   140 
   128 case 'edit':
   141 case 'edit':
   129 	$editing = true;
   142 	$editing = true;
   130 
   143 
   131 	if ( empty( $post_id ) ) {
   144 	if ( empty( $post_id ) ) {
   216 	check_admin_referer('update-post_' . $post_id);
   229 	check_admin_referer('update-post_' . $post_id);
   217 
   230 
   218 	$post_id = edit_post();
   231 	$post_id = edit_post();
   219 
   232 
   220 	// Session cookie flag that the post was saved
   233 	// Session cookie flag that the post was saved
   221 	if ( isset( $_COOKIE['wp-saving-post-' . $post_id] ) )
   234 	if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
   222 		setcookie( 'wp-saving-post-' . $post_id, 'saved' );
   235 		setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS );
       
   236 	}
   223 
   237 
   224 	redirect_post($post_id); // Send user on their way while we keep working
   238 	redirect_post($post_id); // Send user on their way while we keep working
   225 
   239 
   226 	exit();
   240 	exit();
   227 	break;
       
   228 
   241 
   229 case 'trash':
   242 case 'trash':
   230 	check_admin_referer('trash-post_' . $post_id);
   243 	check_admin_referer('trash-post_' . $post_id);
   231 
   244 
   232 	if ( ! $post )
   245 	if ( ! $post )
   246 	if ( ! wp_trash_post( $post_id ) )
   259 	if ( ! wp_trash_post( $post_id ) )
   247 		wp_die( __( 'Error in moving to Trash.' ) );
   260 		wp_die( __( 'Error in moving to Trash.' ) );
   248 
   261 
   249 	wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
   262 	wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
   250 	exit();
   263 	exit();
   251 	break;
       
   252 
   264 
   253 case 'untrash':
   265 case 'untrash':
   254 	check_admin_referer('untrash-post_' . $post_id);
   266 	check_admin_referer('untrash-post_' . $post_id);
   255 
   267 
   256 	if ( ! $post )
   268 	if ( ! $post )
   265 	if ( ! wp_untrash_post( $post_id ) )
   277 	if ( ! wp_untrash_post( $post_id ) )
   266 		wp_die( __( 'Error in restoring from Trash.' ) );
   278 		wp_die( __( 'Error in restoring from Trash.' ) );
   267 
   279 
   268 	wp_redirect( add_query_arg('untrashed', 1, $sendback) );
   280 	wp_redirect( add_query_arg('untrashed', 1, $sendback) );
   269 	exit();
   281 	exit();
   270 	break;
       
   271 
   282 
   272 case 'delete':
   283 case 'delete':
   273 	check_admin_referer('delete-post_' . $post_id);
   284 	check_admin_referer('delete-post_' . $post_id);
   274 
   285 
   275 	if ( ! $post )
   286 	if ( ! $post )
   291 			wp_die( __( 'Error in deleting.' ) );
   302 			wp_die( __( 'Error in deleting.' ) );
   292 	}
   303 	}
   293 
   304 
   294 	wp_redirect( add_query_arg('deleted', 1, $sendback) );
   305 	wp_redirect( add_query_arg('deleted', 1, $sendback) );
   295 	exit();
   306 	exit();
   296 	break;
       
   297 
   307 
   298 case 'preview':
   308 case 'preview':
   299 	check_admin_referer( 'autosave', 'autosavenonce' );
   309 	check_admin_referer( 'update-post_' . $post_id );
   300 
   310 
   301 	$url = post_preview();
   311 	$url = post_preview();
   302 
   312 
   303 	wp_redirect($url);
   313 	wp_redirect($url);
   304 	exit();
   314 	exit();
   305 	break;
       
   306 
   315 
   307 default:
   316 default:
   308 	wp_redirect( admin_url('edit.php') );
   317 	wp_redirect( admin_url('edit.php') );
   309 	exit();
   318 	exit();
   310 	break;
       
   311 } // end switch
   319 } // end switch
   312 include( ABSPATH . 'wp-admin/admin-footer.php' );
   320 include( ABSPATH . 'wp-admin/admin-footer.php' );