Created
August 5, 2019 15:16
-
-
Save Shelob9/49fcaea38f7efd7f617e4919f3c346a8 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* On form submit, do a redirect to a diffrent site, then complete submission | |
*/ | |
add_action('caldera_forms_submit_process_start', function ( | |
$form, | |
$referrer, | |
$process_id | |
) { | |
//If we have a already done redirect, do nothing | |
if (isset($_GET['cf_tp'])) { | |
return; | |
} | |
//Get current URL | |
$url = caldera_forms_build_url($referrer); | |
//Append transient ID | |
$url = add_query_arg('cf_tp', $process_id, $url); | |
//Set CF to redirect to other site | |
add_filter('caldera_forms_redirect_url_complete', function () use ($url, $process_id) { | |
//Save transdata | |
//This should be automatic. See: https://github.com/CalderaWP/Caldera-Forms/issues/3312 | |
global $transdata; | |
Caldera_Forms_Transient::set_transient($process_id, $transdata, 5 * 60); | |
//create redirect URL. | |
return 'http://localhost:8080/?redirect=' . urlencode($url); | |
}, 9999); | |
}, 10, 3); | |
//@see https://github.com/CalderaWP/Caldera-Forms/issues/3313 | |
if (!function_exists('caldera_forms_build_url')) { | |
function caldera_forms_build_url(array $parts) | |
{ | |
if (function_exists('http_build_url')) { | |
return http_build_url($parts); | |
} | |
return add_query_arg( | |
$parts['query'], | |
(isset($parts['scheme']) ? "{$parts['scheme']}:" : '') | |
. ((isset($parts['user']) || isset($parts['host'])) ? '//' : '') | |
. (isset($parts['user']) ? "{$parts['user']}" : '') | |
. (isset($parts['pass']) ? ":{$parts['pass']}" : '') | |
. (isset($parts['user']) ? '@' : '') | |
. (isset($parts['host']) ? "{$parts['host']}" : '') | |
. (isset($parts['port']) ? ":{$parts['port']}" : '') | |
. (isset($parts['path']) ? "{$parts['path']}" : '') | |
. (isset($parts['fragment']) ? "#{$parts['fragment']}" : '') | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment