• This hook gives me some problems. Whatever I try to do with it for modifying the post data (I alter it before sending it to the database, or I would like to), it gives me a ‘headers already sent’ error.
    I just have a simple funtion, that I register using add_filter with format_to_post.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I use it and it works fine for me. Are you sure you don’t send any output from your plugin? Spaces at the beginning of your file etc.

    Thread Starter dissurion

    (@dissurion)

    Are you sure you don’t send any output from your plugin?

    Now I’m pretty sure I use it wrong.
    I thought I should output something, eg get the post data and echo what I want. But if this is a wrong usage, how do I get this result?
    ps: thanks for the reply

    format_to_post is meant for filtering the posted content before it is saved to the database. As soon as you echo something in this hook, this will go out way before anything else is sent to the browser, breaking the page.
    Note that this is basically the same with all filter hooks. Every function you hook in there is passed some variable and has to return it (maybe with altered content). Echo anything and it will happen at a point in the program flow that will quite surely break your site.
    Maybe you should explain a bit more clear what you want to do?

    Thread Starter dissurion

    (@dissurion)

    What I want to do is take the post input, intercept it, add/change something to it, let it go it’s normal flow. ?? So basically add/change something to it and get that in the database, or change it before it is send to the database.

    Then format_to_post is exactly what you need. When you get a ‘headers already sent’ error this means your function is echoing something. The function you hook into the filter shouldn’t echo anything, it should return the data as in return $content;, not echo $content;.
    Or you have whitespace before <?php or after the closing ?> in your plugin. Note that the plugins are loaded before anything is sent to the browser and if a plugin echoes data WP can’t sent HTTP-headers anymore.

    Thread Starter dissurion

    (@dissurion)

    Thanks for the help. Now I got it working. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘format_to_post’ is closed to new replies.