Redirect on publish_post action hook (5 posts)

  1. twistedsymphony
    Posted 8 years ago #

    I'm writing a plugin that integrates WP with another application... it's nearly complete but I need one last little line of code worked out.

    I have an action hook on "publish_post" that runs some db lookups and some logic then it generates a url and I want it to open that url either in the current window or a new window (it doesn't matter).

    using wp_redirect($url); doesn't do anything

    neither does
    header("Location: $url");
    and neither does
    header("Refresh: 0;url=$url");

    the only thing that will open my url in a new window is this:

    echo '<script type="text/javascript">window.open(\''.$url.'\')</script>';

    doing that will open my page in a new window, but the current page (the WP post editor) will crash with the following message:

    Warning: Cannot modify header information - headers already sent by (output started at
    /serverurl/wp-content/plugins/wp_smf_commenter/wp_smf_commenter.php:73) in
    /serverurl/wp-includes/pluggable.php on line 275

    where serverurl is the complete path on my server and wp_smf_commenter is the name of my plugin.
    line 73 is the javascript line above.

    I really really really don't want to use javascript. Does anyone have any suggestions?

  2. golddave
    Posted 8 years ago #

    Did you ever get an answer to this question?

  3. twistedsymphony
    Posted 7 years ago #

    nope never...

  4. Do an exit() after you do the wp_redirect(). Otherwise your redirect will just get redirected again by the normal flow of things.

  5. twistedsymphony
    Posted 7 years ago #

    I'll give that a try, thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic