+function redirect_post($post_ID = '') {
+ global $action;
+
+ $referredby = '';
+ if ( !empty($_POST['referredby']) ) {
+ $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
+ $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
+ }
+ $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
+
+ if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
+ $location = $_POST['referredby'];
+ } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
+ $location = 'sidebar.php?a=b';
+ } elseif ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
+ if ( $_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 )
+ $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "post.php?action=edit&post=$post_ID&message=1" );
+ else
+ $location = "post.php?action=edit&post=$post_ID&message=4";
+ } 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';
+ } elseif (!empty($referredby) && $referredby != $referer) {
+ $location = $_POST['referredby'];
+ $location = remove_query_arg('_wp_original_http_referer', $location);
+ if ( $_POST['referredby'] == 'redo' )
+ $location = get_permalink( $post_ID );
+ elseif ( 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";
+ }
+
+ wp_redirect( $location );
+}
+