| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AcyMailing\WpInit; |
| 4 | 4 | |
| 5 | +defined('ABSPATH') || die('Restricted Access'); | |
| 6 | + | |
| 5 | 7 | use AcyMailing\Classes\UserClass; |
| 6 | 8 | use AcyMailing\Classes\ListClass; |
| 7 | 9 | |
| 8 | 10 | class ElementorForm extends \ElementorPro\Modules\Forms\Classes\Action_Base |
| @@ -18,8 +20,10 @@ | ||
| 18 | 20 | } |
| 19 | 21 | |
| 20 | 22 | public function register_settings_section($widget) |
| 21 | 23 | { |
| 24 | + // Check if an id is provided because this function is called many times sometimes there is no id (and not the rest: settings, form_fields,...) | |
| 25 | + // So when we try to access fields data that is not currently existing a fatal error appears | |
| 22 | 26 | if ($widget->get_id()) { |
| 23 | 27 | $fields = ['' => '']; |
| 24 | 28 | foreach ($widget->get_data('settings')['form_fields'] as $field) { |
| 25 | 29 | if (!isset($field['custom_id']) || !isset($field['field_label'])) { |
| @@ -76,11 +80,12 @@ | ||
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | public function on_export($element) |
| 79 | 83 | { |
| 80 | - unset( | |
| 81 | - $element['acym_confirmUsers'], $element['acym_selectLists'], $element['acym_nameField'], $element['acym_emailField'] | |
| 82 | - ); | |
| 84 | + unset($element['acym_confirmUsers']); | |
| 85 | + unset($element['acym_selectLists']); | |
| 86 | + unset($element['acym_nameField']); | |
| 87 | + unset($element['acym_emailField']); | |
| 83 | 88 | } |
| 84 | 89 | |
| 85 | 90 | public function run($record, $ajax_handler) |
| 86 | 91 | { |
| @@ -95,9 +100,9 @@ | ||
| 95 | 100 | $newUser = new \stdClass(); |
| 96 | 101 | |
| 97 | 102 | $newUser->name = $data[$settings['acym_nameField']]; |
| 98 | 103 | $newUser->email = $data[$settings['acym_emailField']]; |
| 99 | - $newUser->creation_date = date('Y-m-d H:i:s'); | |
| 104 | + $newUser->creation_date = gmdate('Y-m-d H:i:s'); | |
| 100 | 105 | $newUser->confirmed = $settings['acym_confirmUsers'] === 'yes'; |
| 101 | 106 | |
| 102 | 107 | $user = $userClass->getOneByEmail($newUser->email); |
| 103 | 108 | if (!empty($user)) { |
| @@ -103,8 +108,9 @@ | ||
| 103 | 108 | if (!empty($user)) { |
| 104 | 109 | $newUser->id = $user->id; |
| 105 | 110 | } |
| 106 | 111 | |
| 112 | + // We do that because Elementor submit the form via ajax and in ajax mode WordPress always return true to the function is_admin() | |
| 107 | 113 | $config = acym_config(); |
| 108 | 114 | if ($config->get('require_confirmation', 1) == 1) { |
| 109 | 115 | $userClass->forceConfAdmin = true; |
| 110 | 116 | } |
| @@ -111,8 +117,11 @@ | ||
| 111 | 117 | |
| 112 | 118 | $userId = $userClass->save($newUser); |
| 113 | 119 | |
| 114 | 120 | if (!empty($settings['acym_selectLists'])) { |
| 115 | - $userClass->subscribe($userId, $settings['acym_selectLists'], true, true); | |
| 121 | + if (!is_array($settings['acym_selectLists'])) { | |
| 122 | + $settings['acym_selectLists'] = [$settings['acym_selectLists']]; | |
| 123 | + } | |
| 124 | + $userClass->subscribe([$userId], $settings['acym_selectLists'], true, true); | |
| 116 | 125 | } |
| 117 | 126 | } |
| 118 | 127 | } |