Christopher Shennan's Blog

A day in the life of…

Over the last few weeks I have been working on my first wordpress plugin and I am quickly getting to grips with how it all pieces together but I ran into a problem with a rather basic piece of functionality that pretty much rendered the plugin useless until I figured out the issue.

The section I was working on was a form submission (within the wordpress administation) which saved the form values into the database and then redirected the user upon success to another page (using wp_redirect) but this resulted in a blank content pane.

This seems very strange to me as it showed some of the page contents i.e. the header and left navigation but the content pane was completely blank.

I searched around for a few hours trying various suggestions to similar problems, downloading other wordpress plugins and examining how they used the wp_redirect function to see if the authors of these other wordpress plugins had done anything different, only to find that there was no difference.

I eventually managed to figure out the issue after I read a post regarding a problem another user was having where they were getting a completely blank screen and another member suggested the problem could be due to whitespace which was sent to the browser before the redirect was called resulting in a “headers already sent” problem.

This got me thinking that I did not have output buffering enabled which was strange as I usually have output buffering enabled to resolve this issue, however, in this case I did not have output buffering turned on and this turned out to be exactly the problem. I added the following line to my .htaccess file and the redirection now works perfectly.

php_flag output_buffering on

I was glad to get this one resolved as I had to spend far too much time on something that I have resolved time and time again. Certainly one I’ll be aware of should there be a next time!

About Christopher Shennan

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for Line Digital in Edinburgh, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Connect with me via Twitter, Google+ or LinkedIn

  • #1 | Written by Jeremy about 2 years ago.

    This absolutely did the trick for me. Same problem, same solution, now the wp_redirect works great for me. Thanks a lot for posting this.

  • #2 | Written by Martin Downton about 2 years ago.

    Thank you! I was having to fall back to js redirects which was far from ideal. This completely fixed the problem.

  • #3 | Written by Christopher Shennan about 2 years ago.

    I was originally doing exactly the same thing as a temporary work around until I found the solution. I’m glad I could help.

  • #4 | Written by tefdos about 2 years ago.

    May the force be with you… I was stuck for a couple of hours trying dozen of stuff, until I ran on your post… Thank you…

  • #5 | Written by __B__ about 1 year ago.

    HOLY SH*T, I CANT BELIEVE THIS SOLVED MY PROBLEM.

    Thanks for this posts. It really saved my life. Thanks for your time.

  • #6 | Written by Michael Bailey about 1 year ago.

    Thank you, thank you, thank you thank you, thank you..
    Michael Bailey´s last [type] ..Star Communities

  • #7 | Written by Eric Imthorn about 7 months ago.

    I had the same problem. I solved this by going to the index.php file in the root of the WordPress installation and removing all the white-spaces before ”

  • #8 | Written by durga about 7 months ago.

    thank a lot.. i tried 3 days for this.. thank you so much

  • #9 | Written by HwangC about 5 months ago.

    Thank you so much for the great tip :) I solved that problem finally!

Leave a Comment

Subscribe to comments

CommentLuv badge