Created
May 26, 2021 09:10
-
-
Save girafffee/2f92821c00ec0f1c2d68e3eda71bf07f to your computer and use it in GitHub Desktop.
How to redirect to a created or updated post in JetFormBuilder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for that.