Thursday, March 22, 2007

Fix for WordPress blank screen on submit of new post!

I finally took some time to fix this problem on my sites. I am running the newest version of WordPress (2.1.2) but have had this problem forever. Upon a submission of a new post I would get a blank screen. The URL was referring me to wp-admin/post.php so I started looking there for the answer.

This problem has been reported in diverse blogs in one form or another but without a fix that I could apply, such as this WordPress Support Forums entry. I hope this clarifies at least a fix that will get you past the blank screen effect when posting! ;-)

Here is a display of the diff you need to apply:
+++ post.php    2007-03-22 14:57:54.000000000 +0100
@@ -168,6 +168,50 @@
break; default:
+       // 22 March 2007 - Eric D. Schabell 
+       //
+       // fix for blank screen posting of content, after submit now
+       // checking if coming from a new-post screen, if so then we
+       // just submit the post.
+       //
+       $sendback = wp_get_referer();
+       if (strstr($sendback, 'post-new.php'))
+       {
+               $parent_file = 'post-new.php';
+               $submenu_file = 'post-new.php';
+               check_admin_referer('add-post');
+
+               $post_ID = 'post' == $action ? write_post() : edit_post();
+
+               // Redirect.
+               if (!empty($_POST['mode']))
+               {
+                       switch($_POST['mode']) {
+                               case 'bookmarklet':
+                                       $location = $_POST['referredby'];
+                                       break;
+                               case 'sidebar':
+                                       $location = 'sidebar.php?a=b';
+                                       break;
+                               default:
+                                       $location = 'post-new.php';
+                                       break;
+                       }
+               }
+               else
+               {
+                       $location = "post-new.php?posted=$post_ID";
+               }
+
+               if ( isset($_POST['save']) )
+               {
+                       $location = "post.php?action=edit&post=$post_ID";
+               }
+
+               wp_redirect($location);
+       }
+       // end fix.
+
wp_redirect('edit.php');
exit();
break;
For those that do not understand how to apply such a patch, you can edit your wp-admin/post.php file and add all the lines you see above with a plus (+) in front of them. They need to go at the front of the 'default' section of the 'switch' statement, starting at line 171 in my post.php file.

PS. Since upgrading to Wordpress 2.2 and thereby having to upgrade all my plugins, this problem vanished for me. You might want to consider upgrading your plugins to solve this for your installation, that is most likey the problem.