Using ob_get_content to get_search_form puts into infinite loop

I am trying to change the look of my searchform. It basically needs to have two text fields. I want this to be in form of a plugin, which anyone can activate. SO obviously I do not have any control over searchform.php. And I also read that if searchform.php is present, then echo parameter is ignored (http://codex.wordpress.org/Function_Reference/get_search_form#Notes)

This made me look at the code snippet under the heading “MOAR OBJECT BUFFERZ!!!” at:

Read More

http://shinraholdings.com/363/3-wordpress-hacks-to-unlock-some-much-needed-features/4/

I copied the code as it is and added a filter like:
add_filter('get_search_form','shinra_searchform');

However, the code seems to go in an infinite loop. I put an echo statement after lines 11 and 12. The one after 12 never gets printed while the one after line 11 keeps on getting printed continously.

I tried changing the filter to pass the argument to:

  1. add_filter('get_search_form',shinra_searchform(true),1);

  2. add_filter('get_search_form',shinra_searchform(false),1);

  3. add_filter('get_search_form',shinra_searchform($echo),1);

But none of these work.

Can someone please help me out?

Related posts

Leave a Reply

1 comment

  1. There is no safe way to catch the content of a searchform.php in this case. You could run output buffering on the complete page, but then you would probably run into conflicts with other plugins doing the same.

    Alternative solution: Add a widget to your plugin that offers another search form. Ask your users to use that instead of the built-in widget or theme search form.

    Some themes use a hard coded call to get_search_form() – there is nothing you can do.