Skip to content

Commit

Permalink
Release v1.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan DAHAN <[email protected]>
  • Loading branch information
Jonathan DAHAN committed Oct 31, 2021
1 parent 6f205c0 commit ad9dbb7
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions ActionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,50 @@ public function run($record, $ajax_handler)
$fields[$id] = $field['value'];
}

$MJF_data = ['Email' => $fields['email'], 'Name' => $fields['name']];
$MJF_contactdata = [
'Data' => [
[
'Name' => $settings['MJF_name_field'],
'Value' => $fields['name'],
'Name' => $settings['MJF_firstname_field'],
'Value' => $fields['fname'],
'Name' => $settings['MJF_phone_field'],
'Value' => $fields['phone'],
]
]
];
$MJF_data_step2 = ['Email' => $fields['email'], 'Action' => 'addforce'];



if (empty($fields['email']))
{
return;
}

$MJF_data1 = ['Email' => $fields['email']];
$MJF_data2 = ['Email' => $fields['email'], 'Action' => 'addforce'];
$MJF_contactdata1 = ['Data' => [['Name' => $settings['MJF_name_field'], 'Value' => $fields['name'], ]]];
$MJF_contactdata2 = ['Data' => [['Name' => $settings['MJF_firstname_field'], 'Value' => $fields['firstname'], ]]];
$MJF_contactdata3 = ['Data' => [['Name' => $settings['MJF_phone_field'], 'Value' => $fields['phone'], ]]];

$MJF_API = MAILJET_API;
$MJF_SECRET = MAILJET_SECRET;
$auth = base64_encode($MJF_API . ':' . $MJF_SECRET);

$MJF_data_args = ['headers' => ['Authorization' => "Basic $auth"], 'body' => $MJF_data, ];
$MJF_contactdata_args = ['method' => 'PUT', 'headers' => ['Authorization' => "Basic $auth"], 'body' => $MJF_contactdata, ];
$MJF_data_step2_args = ['headers' => ['Authorization' => "Basic $auth"], 'body' => $MJF_data_step2, ];


$MJF_responsecontact = wp_remote_post('https://api.mailjet.com/v3/REST/contact', $MJF_data_args);
$MJF_responsecontactdata = wp_remote_request('https://api.mailjet.com/v3/REST/contactdata/' . $fields['email'], $MJF_contactdata_args);
$MJF_responsecontactslist = wp_remote_post('https://api.mailjet.com/v3/REST/contactslist/' . $settings['MJF_listID'] . '/managecontact', $MJF_data_step2_args);

$MJF_data1_args = ['headers' => ['Authorization' => "Basic $auth"], 'body' => $MJF_data1, ];
$MJF_data2_args = ['headers' => ['Authorization' => "Basic $auth"], 'body' => $MJF_data2, ];
$MJF_contactdata1_args = ['method' => 'PUT', 'headers' => array(
'Authorization' => "Basic $auth",
'Content-Type' => 'application/json'
) , 'body' => json_encode($MJF_contactdata1) , ];
$MJF_contactdata2_args = ['method' => 'PUT', 'headers' => array(
'Authorization' => "Basic $auth",
'Content-Type' => 'application/json'
) , 'body' => json_encode($MJF_contactdata2) , ];
$MJF_contactdata3_args = ['method' => 'PUT', 'headers' => array(
'Authorization' => "Basic $auth",
'Content-Type' => 'application/json'
) , 'body' => json_encode($MJF_contactdata3) , ];

$MJF_responsecontact = wp_remote_post('https://api.mailjet.com/v3/REST/contact', $MJF_data1_args);
$MJF_responsecontactslist = wp_remote_post('https://api.mailjet.com/v3/REST/contactslist/' . $settings['MJF_listID'] . '/managecontact', $MJF_data2_args);
if ($fields['name'])
{
$MJF_responsecontactdata = wp_remote_post('https://api.mailjet.com/v3/REST/contactdata/' . $fields['email'], $MJF_contactdata1_args);
}
if ($fields['firstname'])
{
$MJF_responsecontactdata = wp_remote_post('https://api.mailjet.com/v3/REST/contactdata/' . $fields['email'], $MJF_contactdata2_args);
}
if ($fields['phone'])
{
$MJF_responsecontactdata = wp_remote_post('https://api.mailjet.com/v3/REST/contactdata/' . $fields['email'], $MJF_contactdata3_args);
}
}

public function register_settings_section($widget)
Expand Down

0 comments on commit ad9dbb7

Please sign in to comment.