Last active
November 30, 2017 04:47
-
-
Save zackkatz/cf062dcdb164a9f38f54 to your computer and use it in GitHub Desktop.
Redirect after a GravityView entry is edited if the form ID matches defined cases
This file contains 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 | |
/** | |
* Add the following code to the end of your theme's functions.php file. | |
* | |
* Make sure it's inside the ?> if ?> is at the end of the file!!! | |
* | |
*/ | |
add_action( 'plugins_loaded', 'my_gv_redirect_after_updating_entry', 10 ); | |
/** | |
* Redirect after a GravityView entry is edited if the form ID matches defined cases | |
* | |
* @return void | |
*/ | |
function my_gv_redirect_after_updating_entry() { | |
// Make sure the request is valid | |
if( | |
// Plugin isn't active | |
!class_exists('GravityView_Edit_Entry') || | |
// GravityView Edit Entry $_POST data isn't set | |
empty( $_POST['is_gv_edit_entry'] ) || | |
// Failed security check | |
( false === wp_verify_nonce( $_POST['is_gv_edit_entry'], 'is_gv_edit_entry' ) ) | |
) { | |
// If invalid, get out of here! | |
return; | |
} | |
// Get the entry ID | |
$entry_id = intval( $_POST['lid'] ); | |
// Get Gravity Forms form array | |
$form = gravityview_get_form_from_entry_id( $entry_id ); | |
// Don't redirect by default | |
$redirect_url = false; | |
switch( $form['id'] ) { | |
// Use your own form IDs, these are placeholders | |
case 17: | |
$redirect_url = 'http://example.com'; | |
break; | |
// Use your own form IDs, these are placeholders | |
case 20: | |
$redirect_url = 'http://google.com'; | |
break; | |
// You can add more "cases" below using the same format. | |
} | |
// If defined, redirect after submission | |
if( $redirect_url ) { | |
wp_redirect( $redirect_url ); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to work. I added this in the index.php of the client's custom plugin and it redirects before the data is saved. So, no update is saved. How can I ensure that this runs after the save?