-wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
+wp_reset_vars( array( 'action' ) );
+
+if ( isset( $_GET['post'] ) )
+ $post_id = $post_ID = (int) $_GET['post'];
+elseif ( isset( $_POST['post_ID'] ) )
+ $post_id = $post_ID = (int) $_POST['post_ID'];
+else
+ $post_id = $post_ID = 0;
+
+$post = $post_type = $post_type_object = null;
+
+if ( $post_id )
+ $post = get_post( $post_id );
+
+if ( $post ) {
+ $post_type = $post->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'] ) {
+ $location = add_query_arg( 'message', 3, wp_get_referer() );
+ $location = explode('#', $location);
+ $location = $location[0] . '#postcustom';
+ } else {
+ $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
+ }
+
+ /**
+ * 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;
+}