diff --git a/ActionSubscriber.php b/ActionSubscriber.php index d2f7ef1..a62916e 100644 --- a/ActionSubscriber.php +++ b/ActionSubscriber.php @@ -1,22 +1,22 @@ get('form_settings'); - if (empty($settings['mailjet_list'])) + if (empty($settings['MJF_listID'])) { return; } @@ -29,27 +29,35 @@ public function run($record, $ajax_handler) $fields[$id] = $field['value']; } - $mailjet_data = ['Email' => $fields['email'], 'Name' => $fields['name'], ]; + $MJF_data = ['Email' => $fields['email']]; + $MJF_contactdata = [ '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', ]; - $mailjet_data_step2 = ['Email' => $fields['email'], 'Action' => 'addforce', ]; + $MJF_API = MAILJET_API; + $MJF_SECRET = MAILJET_SECRET; + $MJF_auth = base64_encode($MJF_API . ':' . $MJF_SECRET); - $mailjet_api = MAILJET_API; - $mailjet_secret = MAILJET_SECRET; - $auth = base64_encode($mailjet_api . ':' . $mailjet_secret); + $MJF_data_args = ['headers' => ['Authorization' => "Basic $MJF_auth"], 'body' => $MJF_data, ]; + $MJF_contactdata_args = ['headers' => ['Authorization' => "Basic $MJF_auth"], 'body' => $MJF_contactdata, ]; + $MJF_data_step2_args = ['headers' => ['Authorization' => "Basic $MJF_auth"], 'body' => $MJF_data_step2, ]; - $mailjet_data_args = ['headers' => ['Authorization' => "Basic $auth"], 'body' => $mailjet_data, ]; - $mailjet_data_step2_args = ['headers' => ['Authorization' => "Basic $auth"], 'body' => $mailjet_data_step2, ]; - - wp_remote_post('https://api.mailjet.com/v3/REST/contact', $mailjet_data_args); - wp_remote_post('https://api.mailjet.com/v3/REST/contactslist/' . $settings['mailjet_list'] . '/managecontact', $mailjet_data_step2_args); + $MJF_responsecontact = wp_remote_post('https://api.mailjet.com/v3/REST/contact', $MJF_data_args); + $MJF_responsecontactdata = wp_remote_post('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); } public function register_settings_section($widget) { - $widget->start_controls_section('section_mailjet', ['label' => __('Mailjet', 'text-domain') , 'condition' => ['submit_actions' => $this->get_name() , ], ]); + $widget->start_controls_section('section_MJF', ['label' => __('Mailjet', 'text-domain') , 'condition' => ['submit_actions' => $this->get_name() , ], ]); + + $widget->add_control('MJF_listID', ['label' => __('Mailjet List ID', 'text-domain') , 'type' => \Elementor\Controls_Manager::TEXT, 'separator' => 'before', 'description' => __('the list id you want to subscribe a user to.', 'text-domain') , ]); + + $widget->add_control('MJF_firstname_field', ['label' => __('Mailjet FirstName field', 'text-domain') , 'type' => \Elementor\Controls_Manager::TEXT, 'separator' => 'before', 'description' => __('Name your mailjet firstname contact field.', 'text-domain') , ]); + + $widget->add_control('MJF_name_field', ['label' => __('Mailjet LastName field', 'text-domain') , 'type' => \Elementor\Controls_Manager::TEXT, 'separator' => 'before', 'description' => __('Name your mailjet lastname contact field.', 'text-domain') , ]); - $widget->add_control('mailjet_list', ['label' => __('Mailjet List ID', 'text-domain') , 'type' => \Elementor\Controls_Manager::TEXT, 'separator' => 'before', 'description' => __('the list id you want to subscribe a user to.', 'text-domain') , ]); + $widget->add_control('MJF_phone_field', ['label' => __('Mailjet Phone field', 'text-domain') , 'type' => \Elementor\Controls_Manager::TEXT, 'separator' => 'before', 'description' => __('Name your mailjet contact phone field.', 'text-domain') , ]); $widget->end_controls_section(); @@ -57,6 +65,9 @@ public function register_settings_section($widget) public function on_export($element) { - unset($element['mailjet_list'],); + unset($element['MJF_listID'],); + unset($element['MJF_firstname_field'],); + unset($element['MJF_name_field'],); + unset($element['MJF_phone_field'],); } } \ No newline at end of file diff --git a/mjforms.php b/mjforms.php index 38a5138..4e80715 100644 --- a/mjforms.php +++ b/mjforms.php @@ -16,20 +16,20 @@ exit; // Exit if accessed directly } -define('MJ_FORM_PATH', plugin_dir_path(__FILE__)); +define('MJ_FORMS_PATH', plugin_dir_path(__FILE__)); add_action('elementor_pro/init', function () { // Here its safe to include our action class file - include_once (MJ_FORM_PATH . 'ActionSubscriber.php'); + include_once (MJ_FORMS_PATH . 'ActionSubscriber.php'); // Instantiate the action class - $mailjet_action = new Mailjet_Action_After_Submit(); + $MJF_action_subscribe = new MJF_Subscribe_Action_After_Submit(); // Register the action with form widget \ElementorPro\Plugin::instance() ->modules_manager ->get_modules('forms') - ->add_form_action($mailjet_action->get_name() , $mailjet_action); + ->add_form_action($MJF_action_subscribe->get_name() , $MJF_action_subscribe); });