在我的函数.php文件中,我有如下内容(来自重力形式):
add_action('gform_after_submission_500', 'post_to_third_party', 10, 2);
function post_to_third_party($entry, $form) {
$post_url = THEME_DIR . '/myscript/index.php';
$body = array(
'first_name' => $entry['1'],
'last_name' => $entry['2'],
'email' => $entry['3']
);
$request = new WP_Http();
$response = $request->post($post_url, array('body' => $body));
}
我应该在"myscript/index.php中有什么来接收帖子数据,以便我可以使用它?
试试这个:
$request->request( $post_url, array( 'method' => 'POST', 'body' => $body) );
/myscript/index.php
返回的数据只需要采用 PHP 在 $response
变量中返回时可以处理的格式。我不是这里的专家,但我的默认是通过/myscript/index.php
端的json_encode将数据输出为 JSON,然后在响应中返回时通过json_decode解析该数据。
$data = json_decode( wp_remote_retrieve_body( $response ) );