Skip to content

Commit

Permalink
Add prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan DAHAN committed Oct 30, 2021
1 parent d32a8f9 commit 1395f0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
45 changes: 28 additions & 17 deletions ActionSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php
class Mailjet_Action_After_Submit extends \ElementorPro\Modules\Forms\Classes\Action_Base
class MJF_Subscribe_Action_After_Submit extends \ElementorPro\Modules\Forms\Classes\Action_Base
{

public function get_name()
{
return 'mailjet';
return 'MJF_Subscribe';
}

public function get_label()
{
return __('Mailjet', 'text-domain');
return __('Mailjet Subscribe', 'text-domain');
}

public function run($record, $ajax_handler)
{
$settings = $record->get('form_settings');

if (empty($settings['mailjet_list']))
if (empty($settings['MJF_listID']))
{
return;
}
Expand All @@ -29,34 +29,45 @@ 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();

}

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'],);
}
}
8 changes: 4 additions & 4 deletions mjforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 1395f0c

Please sign in to comment.