Php 在Wordpress上进行后期保存后更改重定向url
我有个问题,希望这里有一些好人能帮助我。我准备了一份前端表格。这是一个捐赠表单,我在表单提交后向支付网关api添加了一个cURL调用。这里的问题是,我希望表单页面重定向到支付网关api返回的url,以便用户在异地使用银行支付 我的想法是在帖子保存后,但在用户被重定向之前,更改帖子永久链接,这样他们将被重定向到正确的url(由支付网关api提供),而不是原始永久链接 有没有办法执行这个 以下是我目前的代码:Php 在Wordpress上进行后期保存后更改重定向url,php,wordpress,redirect,curl,advanced-custom-fields,Php,Wordpress,Redirect,Curl,Advanced Custom Fields,我有个问题,希望这里有一些好人能帮助我。我准备了一份前端表格。这是一个捐赠表单,我在表单提交后向支付网关api添加了一个cURL调用。这里的问题是,我希望表单页面重定向到支付网关api返回的url,以便用户在异地使用银行支付 我的想法是在帖子保存后,但在用户被重定向之前,更改帖子永久链接,这样他们将被重定向到正确的url(由支付网关api提供),而不是原始永久链接 有没有办法执行这个 以下是我目前的代码: <?php add_action('acf/save_post', 'my_sav
<?php
add_action('acf/save_post', 'my_save_post', 10, 1);
function my_save_post( $post_id ) {
$billplzApi = get_field('billplz_secret_key', 'option');
$billplzId = get_field('billplz_collection_id', 'option');
// bail early if not a donation post
if( get_post_type($post_id) !== 'donation' ) {
return;
}
// bail early if editing in admin
if( is_admin() ) {
return;
}
$post = get_post( $post_id);
$amount = '';
$donationGroup = get_field('donation_amount', $post);
$selectedAmount = $donationGroup['select_donation_amount'];
$customAmount = $donationGroup['specify_any_amount'];
if(!$customAmount){
$amount = $selectedAmount;
} else {
$amount = $customAmount;
}
$name = get_field('name', $post);
$email = get_field('email', $post);
$unmobile = get_field('mobile', $post);
$mobile = "+6" . $unmobile;
$billplz_data = array(
'amount' => $amount * 100,
'name' => $name,
'mobile' => $mobile,
'email' => $email,
'collection_id' => $billplzId,
'deliver' => false,
'description' => 'a test for payment gateway',
'redirect_url' => home_url('donation-redirect'),
'callback_url' => home_url('donation-callback')
);
$process = curl_init('https://www.billplz.com/api/v3/bills/');
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERPWD, $billplzApi . ":");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS,http_build_query($billplz_data));
$return = curl_exec($process);
curl_close($process);
$arr = json_decode($return, true);
//this is the url to replace the original post permalink
$billplz_url = $arr['url'];
}
acf_form_head();
get_header();
?>
<div class="row">
<div class="col-sm-12 col-md-8 col-md-offset-2 col-xs-12">
<?php
while (have_posts()) : the_post();
acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'donation',
'post_status' => 'publish'
),
'submit_value' => 'Donate',
'html_submit_button' => '<input type="submit" class="acf-button btn btn-success btn-lg pull-right" value="%s" />',
'return' => '%post_url%'
));
endwhile;
?>
</div>
</div>
<?php
get_footer();
?>
在此处找到此问题的解决方案:
因此,基本上我需要补充:
header('Location:'.$billplz_url);
exit();
并删除:
'return' => '%post_url%'