0
votes

I'm trying to redirect the user after they've edited a post using the WordPress Front-end Editor plugin:

Plugin repository http://wordpress.org/plugins/wp-front-end-editor/

GitHub https://github.com/avryl/wp-front-end-editor

I thought about using the save_post hook: http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

function redirect_after_edit(){
    wp_redirect( home_url() );
    exit;
}
add_action( 'save_post', 'redirect_after_edit' );

Although this redirect works when editing a post via the back-end, it doesn't work when using WordPress Front-end Editor to edit a post.

Any idea how I can redirect the user after they've successfully edited a post using WordPress Front-end Editor?

1
save_post is called when editing from the front end editor. There's something else going on here. Are the headers already sent at this point? if so, then you can't perform a header() call in php. turn on the error reporting.Ohgodwhy
I notice there is no page refresh on submitting an edit. Could AJAX have some role in this?henrywright
No. because your plugin registered with WP AJAX and that data is sent to a controller function that then calls do_($action, $arg1, $arg2) and performs the get/save based on the data that that was received form the ajax object.Ohgodwhy
Right. In that case I can't understand why save_post isn't firing the redirect? Got Firebug on and no errors seem to be thrown.henrywright
As i advised you previously, you can't perform a header redirect if the headers have already been sent. Go to your wp-config file, then find WP_DEBUG and set it to true, then reload the page. If you get, "warning: headers already sent`, then you have identified your problem.Ohgodwhy

1 Answers

0
votes

… Since the plugin uses AJAX to update the post, redirecting the page on save_post will only alter the response. Take a look at the XHRs. It will have the page's HTML. Use redirect_post_location to redirect after saving.