I would like to send data from one WP site to an other.
I have two plugins the sender ad the reciver.
In the sender side I used the init hook
add_action('init', array($this, 'say_hello') );
....
public function say_hello() {
$data = get_plugin_data( $this->pDIR.'/plugin.php', $markup = false, $translate = false );
$url = $_SERVER['HTTP_HOST'].'/wp-admin/admin-ajax.php';
$fields = array(
'action' => 'Hello_ajax',
'zpm_hello' => '1',
'zpm_plugin_version' => $data['Version'],
'zpm_host' => $_SERVER['HTTP_HOST']
);
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
var_dump($result);
//close connection
curl_close($ch);
}
The variables are fine the url is correct I printed out.
On the reciver side I registered the admin ajax
add_action('wp_ajax_Hello_ajax', array($this, 'zpm_api_hello'));
add_action('wp_ajax_nopriv_Hello_ajax', array($this, 'zpm_api_hello'));
public function zpm_api_hello() {
$response['success'] = false;
$response['response'] = "";
$error = false;
$hello = $_POST['zpm_hello'];
$plugin_version = $_POST['zpm_plugin_version'];
$plugin_host = $_POST['zpm_host'];
if(!isset($hello)) {
$error = true;
$response['response'] .= "Ello >> Auth ERROR - CODE - 01 ";
}
if(!isset($plugin_version)) {
$error = true;
$response['response'] .= "Ello >> Plugin Version error - CODE - 02 ";
}
if(!isset($plugin_host)) {
$error = true;
$response['response'] .= "Ello >> Plugin host error - CODE - 03 ";
}
if(!$error) {
$response['success'] = true;
$response['response'] .= "Ello >> Auth OK ";
}
echo json_encode($response);
die();
}
So the code is here.
My problem is when I try to load the sender site it is just loading and loading for ever and I doesn’t get back the result. Could you tell me what could be the problem with this method? Thanks all of your answers!
you might want to use this example to build your PHP request, if you send me the POST body, headers and url parameters I will even build it for you: