PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / WpInit / ElementorForm.php

ElementorForm.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.11.1, at WpInit/ElementorForm.php

123 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\WpInit;
4
5 use AcyMailing\Classes\UserClass;
6 use AcyMailing\Classes\ListClass;
7
8 class ElementorForm extends \ElementorPro\Modules\Forms\Classes\Action_Base
9 {
10 public function get_name()
11 {
12 return 'acymailing';
13 }
14
15 public function get_label()
16 {
17 return 'AcyMailing';
18 }
19
20 public function register_settings_section($widget)
21 {
22 if ($widget->get_id()) {
23 $fields = ['' => ''];
24 foreach ($widget->get_data('settings')['form_fields'] as $field) {
25 if (!isset($field['custom_id']) || !isset($field['field_label'])) {
26 continue;
27 }
28 $fields[$field['custom_id']] = $field['field_label'];
29 }
30
31 $widget->start_controls_section('section_acymailing', [
32 'label' => 'AcyMailing',
33 'condition' => [
34 'submit_actions' => $this->get_name(),
35 ],
36 ]);
37
38 $listsClass = new ListClass();
39 $lists = $listsClass->getAllWithIdName();
40
41 $widget->add_control('acym_selectLists', [
42 'label' => acym_translation('ACYM_LISTS_SUMMARY'),
43 'label_block' => true,
44 'description' => acym_translation('ACYM_SELECT_LISTS_USERS_SUBSCRIBE'),
45 'type' => \Elementor\Controls_Manager::SELECT2,
46 'options' => $lists,
47 'multiple' => true,
48 'default' => '',
49 ]);
50
51 $widget->add_control('acym_nameField', [
52 'label' => acym_translation('ACYM_NAME_SUMMARY'),
53 'type' => \Elementor\Controls_Manager::SELECT,
54 'default' => '',
55 'options' => $fields,
56 ]);
57
58 $widget->add_control('acym_emailField', [
59 'label' => acym_translation('ACYM_EMAIL'),
60 'type' => \Elementor\Controls_Manager::SELECT,
61 'default' => '',
62 'options' => $fields,
63 'description' => acym_translation('ACYM_RELOAD_PAGE_TO_SEE_NEW_FIELDS'),
64 ]);
65
66 $widget->add_control('acym_confirmUsers', [
67 'label' => acym_translation('ACYM_IMPORT_USERS_AS_CONFIRMED'),
68 'type' => \Elementor\Controls_Manager::SWITCHER,
69 'label_on' => acym_translation('ACYM_YES'),
70 'label_off' => acym_translation('ACYM_NO'),
71 'default' => true,
72 ]);
73
74 $widget->end_controls_section();
75 }
76 }
77
78 public function on_export($element)
79 {
80 unset($element['acym_confirmUsers']);
81 unset($element['acym_selectLists']);
82 unset($element['acym_nameField']);
83 unset($element['acym_emailField']);
84 }
85
86 public function run($record, $ajax_handler)
87 {
88 $settings = $record->get('form_settings');
89 $data = $record->get('sent_data');
90
91 if (empty($data[$settings['acym_emailField']])) {
92 return;
93 }
94
95 $userClass = new UserClass();
96 $newUser = new \stdClass();
97
98 $newUser->name = $data[$settings['acym_nameField']];
99 $newUser->email = $data[$settings['acym_emailField']];
100 $newUser->creation_date = date('Y-m-d H:i:s');
101 $newUser->confirmed = $settings['acym_confirmUsers'] === 'yes';
102
103 $user = $userClass->getOneByEmail($newUser->email);
104 if (!empty($user)) {
105 $newUser->id = $user->id;
106 }
107
108 $config = acym_config();
109 if ($config->get('require_confirmation', 1) == 1) {
110 $userClass->forceConfAdmin = true;
111 }
112
113 $userId = $userClass->save($newUser);
114
115 if (!empty($settings['acym_selectLists'])) {
116 if (!is_array($settings['acym_selectLists'])) {
117 $settings['acym_selectLists'] = [$settings['acym_selectLists']];
118 }
119 $userClass->subscribe([$userId], $settings['acym_selectLists'], true, true);
120 }
121 }
122 }
123