X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/76aea3697c6043c1613370f172395b4f65ee71f0..256a3b381f63716209b3527d0a14442ae570c283:/wp-admin/post.php diff --git a/wp-admin/post.php b/wp-admin/post.php index 0dfb8212..09a31ae4 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -1,123 +1,213 @@ post_type; + $post_type_object = get_post_type_object( $post_type ); +} + +/** + * Redirect to previous page. + * + * @param int $post_id Optional. Post ID. + */ +function redirect_post($post_id = '') { + if ( isset($_POST['save']) || isset($_POST['publish']) ) { + $status = get_post_status( $post_id ); + + if ( isset( $_POST['publish'] ) ) { + switch ( $status ) { + case 'pending': + $message = 8; + break; + case 'future': + $message = 9; + break; + default: + $message = 6; + } + } else { + $message = 'draft' == $status ? 10 : 1; + } + + $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); + } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { $location = add_query_arg( 'message', 2, wp_get_referer() ); $location = explode('#', $location); $location = $location[0] . '#postcustom'; - } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) { + } elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) { $location = add_query_arg( 'message', 3, wp_get_referer() ); $location = explode('#', $location); $location = $location[0] . '#postcustom'; - } elseif (!empty($referredby) && $referredby != $referer) { - $location = $_POST['referredby']; - $location = remove_query_arg('_wp_original_http_referer', $location); - if ( false !== strpos($location, 'edit.php') ) - $location = add_query_arg('posted', $post_ID, $location); - elseif ( false !== strpos($location, 'wp-admin') ) - $location = "post-new.php?posted=$post_ID"; - } elseif ( isset($_POST['publish']) ) { - $location = "post-new.php?posted=$post_ID"; - } elseif ($action == 'editattachment') { - $location = 'attachments.php'; } else { - $location = "post.php?action=edit&post=$post_ID&message=4"; + $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); } - wp_redirect( $location ); + /** + * Filter the post redirect destination URL. + * + * @since 2.9.0 + * + * @param string $location The destination URL. + * @param int $post_id The post ID. + */ + wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); + exit; } if ( isset( $_POST['deletepost'] ) ) $action = 'delete'; +elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) + $action = 'preview'; + +$sendback = wp_get_referer(); +if ( ! $sendback || + strpos( $sendback, 'post.php' ) !== false || + strpos( $sendback, 'post-new.php' ) !== false ) { + if ( 'attachment' == $post_type ) { + $sendback = admin_url( 'upload.php' ); + } else { + $sendback = admin_url( 'edit.php' ); + $sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : ''; + } +} else { + $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); +} switch($action) { +case 'post-quickdraft-save': + // Check nonce and capabilities + $nonce = $_REQUEST['_wpnonce']; + $error_msg = false; + if ( ! wp_verify_nonce( $nonce, 'add-post' ) ) + $error_msg = __( 'Unable to submit this form, please refresh and try again.' ); + + if ( ! current_user_can( 'edit_posts' ) ) + $error_msg = __( 'Oops, you don’t have access to add new drafts.' ); + + if ( $error_msg ) + return wp_dashboard_quick_press( $error_msg ); + + $post = get_post( $_REQUEST['post_ID'] ); + check_admin_referer( 'add-' . $post->post_type ); + edit_post(); + // output the quickdraft dashboard widget + require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); + wp_dashboard_quick_press(); + exit; + break; + case 'postajaxpost': case 'post': - check_admin_referer('add-post'); - - $post_ID = 'post' == $action ? write_post() : edit_post(); - - redirect_post($post_ID); + check_admin_referer( 'add-' . $post_type ); + $post_id = 'postajaxpost' == $action ? edit_post() : write_post(); + redirect_post( $post_id ); exit(); break; case 'edit': - $title = __('Edit'); $editing = true; - if ( empty( $_GET['post'] ) ) { - wp_redirect("post.php"); + if ( empty( $post_id ) ) { + wp_redirect( admin_url('post.php') ); exit(); } - $post_ID = $p = (int) $_GET['post']; - $post = get_post($post_ID); - if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") ); + if ( ! $post ) + wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); + + if ( ! $post_type_object ) + wp_die( __( 'Unknown post type.' ) ); + + if ( ! current_user_can( 'edit_post', $post_id ) ) + wp_die( __( 'You are not allowed to edit this item.' ) ); + + if ( 'trash' == $post->post_status ) + wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) ); - if ( 'post' != $post->post_type ) { - wp_redirect( get_edit_post_link( $post->ID, 'url' ) ); + if ( ! empty( $_GET['get-post-lock'] ) ) { + wp_set_post_lock( $post_id ); + wp_redirect( get_edit_post_link( $post_id, 'url' ) ); exit(); } - wp_enqueue_script('post'); - if ( user_can_richedit() ) - wp_enqueue_script('editor'); - add_thickbox(); - wp_enqueue_script('media-upload'); - wp_enqueue_script('word-count'); - - if ( current_user_can('edit_post', $post_ID) ) { - if ( $last = wp_check_post_lock( $post->ID ) ) { - $last_user = get_userdata( $last ); - $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); - $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) ); - $message = str_replace( "'", "\'", "
$message