Last active
October 7, 2015 16:13
-
-
Save EvanHerman/d2b9beb5cfd95cbf586b to your computer and use it in GitHub Desktop.
Easy Forms for MailChimp - Alter URL user is redirected too using the yikes-mailchimp-redirect-url filter
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 | |
/* | |
* Alter the URL the user is redirected to after a successfull submission of form #3 | |
* - Add a custom URL, or add query args to the page URL selected on the edit forms page | |
* @parameters | |
* $url - the original URL set on the edit forms page | |
* $form_id - the ID of the form that was submitted | |
* $page_data - the global $post data - contains all sorts of info about the current page (including ID, title etc.) | |
*/ | |
function yikes_mailchimp_alter_redirect_url( $url, $form_id, $page_data ) { | |
// confirm this is form #3 | |
if( $form_id == '3' ) { | |
// setup our switch statement | |
switch( $page_data->ID ) { | |
default: | |
return $url; // return defualt URL selected on edit form page | |
break; | |
case '3822': // targets forms submitted on page with ID 3822 | |
$url = esc_url( 'https://www.google.com/search?q=search+1&oq=custom_page' ); // redirect to a google search of term "custom_page" | |
break; | |
case '3824': // targets page with ID #3824 | |
// add custom query arguments (param_1="parameter-1" etc) to the redirect page | |
$url = add_query_arg( | |
array( | |
'param_1' => 'parameter-1', | |
'param_2' => 'parameter-2' | |
), | |
$url | |
); | |
break; | |
} | |
} | |
// return the altered URL | |
return $url; | |
} | |
add_filter( 'yikes-mailchimp-redirect-url', 'yikes_mailchimp_alter_redirect_url', 10, 3 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment