Skip to content

Instantly share code, notes, and snippets.

@EvanHerman
Last active October 7, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanHerman/d2b9beb5cfd95cbf586b to your computer and use it in GitHub Desktop.
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
<?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