Skip to content

Instantly share code, notes, and snippets.

@girafffee
Created May 26, 2021 09:10
Show Gist options
  • Save girafffee/2f92821c00ec0f1c2d68e3eda71bf07f to your computer and use it in GitHub Desktop.
Save girafffee/2f92821c00ec0f1c2d68e3eda71bf07f to your computer and use it in GitHub Desktop.
How to redirect to a created or updated post in JetFormBuilder
<?php
/**
* @param \Jet_Form_Builder\Actions\Types\Base $action_instance
* @param \Jet_Form_Builder\Actions\Action_Handler $action_handler
*/
$onInsertPost = function ( $action_instance, $action_handler ) {
$inserted_id = $action_handler->response_data['inserted_post_id'];
$url = get_permalink( $inserted_id );
if ( ! $action_handler->request_data['__is_ajax'] ) {
wp_safe_redirect( $url );
die();
} else {
$action_handler->add_response( array(
'redirect' => $url
) );
}
};
/**
* on update post use this action:
* jet-form-builder/action/after-post-update
*/
add_action( 'jet-form-builder/action/after-post-insert', $onInsertPost, 10, 2 );
@ChristophGeier
Copy link

Thanks for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment