| @@ -18,9 +18,9 @@ | ||
| 18 | 18 | public function __construct() |
| 19 | 19 | { |
| 20 | 20 | parent::__construct( |
| 21 | 21 | null, |
| 22 | - 'Fluent Community', | |
| 22 | + 'FluentCommunity', | |
| 23 | 23 | 'fluent_community', |
| 24 | 24 | '_fluentform_fluent_community_settings', |
| 25 | 25 | 'fluent_community_feeds', |
| 26 | 26 | 10 |
| @@ -27,12 +27,13 @@ | ||
| 27 | 27 | ); |
| 28 | 28 | |
| 29 | 29 | $this->logo = FLUENT_COMMUNITY_PLUGIN_URL . 'assets/images/logo.png'; |
| 30 | 30 | |
| 31 | - $this->description = __('Connect Fluent Forms with Fluent Community', 'fluent-community'); | |
| 31 | + $this->description = __('Connect Fluent Forms with FluentCommunity', 'fluent-community'); | |
| 32 | 32 | |
| 33 | 33 | $this->registerAdminHooks(); |
| 34 | - | |
| 34 | + add_filter("fluentform/save_integration_value_{$this->integrationKey}", array($this, 'validateSettings'), 10, 2); | |
| 35 | + | |
| 35 | 36 | add_filter('fluentform/notifying_async_fluent_community', '__return_false'); |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | |
| @@ -94,9 +95,9 @@ | ||
| 94 | 95 | ], |
| 95 | 96 | [ |
| 96 | 97 | 'require_list' => false, |
| 97 | 98 | 'title' => __('For new users', 'fluent-community'), |
| 98 | - 'html_info' => '<h4 style="font-size: 16px;">' . __('For New Users - Data mapping') . '</h4><p>' . __('These settings will apply only if the provided email address is not a registered WordPress user', 'fluent-community') . '</p>', | |
| 99 | + 'html_info' => '<h4 style="font-size: 16px;">' . __('For New Users - Data mapping', 'fluent-community') . '</h4><p>' . __('These settings will apply only if the provided email address is not a registered WordPress user', 'fluent-community') . '</p>', | |
| 99 | 100 | 'component' => 'html_info', |
| 100 | 101 | ], |
| 101 | 102 | [ |
| 102 | 103 | 'require_list' => false, |
| @@ -101,16 +102,16 @@ | ||
| 101 | 102 | [ |
| 102 | 103 | 'require_list' => false, |
| 103 | 104 | 'key' => 'full_name', |
| 104 | 105 | 'component' => 'value_text', |
| 105 | - 'label' => __('Full Name (Only for new users)', 'fluent_community') | |
| 106 | + 'label' => __('Full Name (Only for new users)', 'fluent-community') | |
| 106 | 107 | ], |
| 107 | 108 | [ |
| 108 | 109 | 'require_list' => false, |
| 109 | 110 | 'key' => 'password', |
| 110 | 111 | 'component' => 'value_text', |
| 111 | - 'label' => __('Password (Only for new users)', 'fluent_community'), | |
| 112 | - 'inline_tip' => __('Keep empty to auto generated password', 'fluent_community') | |
| 112 | + 'label' => __('Password (Only for new users)', 'fluent-community'), | |
| 113 | + 'inline_tip' => __('Keep empty to auto generated password', 'fluent-community') | |
| 113 | 114 | ], |
| 114 | 115 | [ |
| 115 | 116 | 'require_list' => false, |
| 116 | 117 | 'key' => 'enableAutoLogin', |
| @@ -129,9 +130,9 @@ | ||
| 129 | 130 | 'require_list' => false, |
| 130 | 131 | 'key' => 'conditionals', |
| 131 | 132 | 'label' => __('Conditional Logics', 'fluent-community'), |
| 132 | 133 | 'tips' => __('Allow this integration conditionally based on your submission values', |
| 133 | - 'fluentformpro'), | |
| 134 | + 'fluent-community'), | |
| 134 | 135 | 'component' => 'conditional_block' |
| 135 | 136 | ], |
| 136 | 137 | ], |
| 137 | 138 | 'button_require_list' => false, |
| @@ -140,8 +141,29 @@ | ||
| 140 | 141 | |
| 141 | 142 | |
| 142 | 143 | return $fieldSettings; |
| 143 | 144 | } |
| 145 | + | |
| 146 | + public function validateSettings($settings) | |
| 147 | + { | |
| 148 | + $message = __('Validation Failed', 'fluent-community'); | |
| 149 | + $errors = []; | |
| 150 | + if (empty($settings['space_ids'])) { | |
| 151 | + $errors['space_ids'] = [__('Please Select Space or Course', 'fluent-community')]; | |
| 152 | + } | |
| 153 | + if (empty($settings['email'])) { | |
| 154 | + $errors['custom_fields'] = [__('Please Select a Email', 'fluent-community')]; | |
| 155 | + } | |
| 156 | + | |
| 157 | + if ($errors) { | |
| 158 | + wp_send_json_error([ | |
| 159 | + 'message' => $message, | |
| 160 | + 'errors' => $errors | |
| 161 | + ], 423); | |
| 162 | + } | |
| 163 | + | |
| 164 | + return $settings; | |
| 165 | + } | |
| 144 | 166 | |
| 145 | 167 | public function getAllSpacesCourses() |
| 146 | 168 | { |
| 147 | 169 | $allSpaces = \FluentCommunity\App\Models\BaseSpace::query()->withoutGlobalScopes() |
| @@ -151,9 +173,9 @@ | ||
| 151 | 173 | ->get(); |
| 152 | 174 | |
| 153 | 175 | $formattedSpaces = []; |
| 154 | 176 | foreach ($allSpaces as $space) { |
| 155 | - $type = $space->type == 'course' ? __('Course', 'fluent-comunity') : __('Space', 'fluent-community'); | |
| 177 | + $type = $space->type == 'course' ? __('Course', 'fluent-community') : __('Space', 'fluent-community'); | |
| 156 | 178 | $formattedSpaces[$space->id] = "{$space->title} ({$type})"; |
| 157 | 179 | } |
| 158 | 180 | return $formattedSpaces; |
| 159 | 181 | } |
| @@ -162,15 +184,15 @@ | ||
| 162 | 184 | { |
| 163 | 185 | $fields = [ |
| 164 | 186 | [ |
| 165 | 187 | 'key' => 'email', |
| 166 | - 'label' => __('Email Address', 'fluent_community'), | |
| 188 | + 'label' => __('Email Address', 'fluent-community'), | |
| 167 | 189 | 'input_options' => 'emails', |
| 168 | 190 | 'required' => true, |
| 169 | 191 | ] |
| 170 | 192 | ]; |
| 171 | 193 | |
| 172 | - return apply_filters('fluentform/user_registration_map_fields', $fields); | |
| 194 | + return apply_filters('fluent-community/fluentform_map_fields', $fields); | |
| 173 | 195 | } |
| 174 | 196 | |
| 175 | 197 | public function pushIntegration($integrations, $formId) |
| 176 | 198 | { |
| @@ -177,9 +199,10 @@ | ||
| 177 | 199 | $integrations[$this->integrationKey] = [ |
| 178 | 200 | 'category' => 'wp_core', |
| 179 | 201 | 'disable_global_settings' => 'yes', |
| 180 | 202 | 'logo' => '', |
| 181 | - 'title' => sprintf(__(' %s Integration', 'fluent-community'), 'Fluent Community'), | |
| 203 | + /* translators: %s is replaced by the title of the integration */ | |
| 204 | + 'title' => sprintf(__(' %s Integration', 'fluent-community'), 'FluentCommunity'), | |
| 182 | 205 | 'is_active' => $this->isConfigured() |
| 183 | 206 | ]; |
| 184 | 207 | |
| 185 | 208 | return $integrations; |
| @@ -203,9 +226,9 @@ | ||
| 203 | 226 | if (!$spaceIds) { |
| 204 | 227 | return $this->addLog( |
| 205 | 228 | $feed['settings']['name'], |
| 206 | 229 | 'failed', |
| 207 | - 'No Course/Space selected', | |
| 230 | + __('No Course/Space selected', 'fluent-community'), | |
| 208 | 231 | $form->id, |
| 209 | 232 | $entry->id, |
| 210 | 233 | $this->integrationKey |
| 211 | 234 | ); |
| @@ -210,15 +233,14 @@ | ||
| 210 | 233 | $this->integrationKey |
| 211 | 234 | ); |
| 212 | 235 | } |
| 213 | 236 | |
| 214 | - $spaces = BaseSpace::query()->whereIn('id', $spaceIds)->get(); | |
| 215 | - | |
| 237 | + $spaces = BaseSpace::query()->onlyMain()->whereIn('id', $spaceIds)->get(); | |
| 216 | 238 | if ($spaces->isEmpty()) { |
| 217 | 239 | return $this->addLog( |
| 218 | 240 | $feed['settings']['name'], |
| 219 | 241 | 'failed', |
| 220 | - 'No Course/Space found', | |
| 242 | + __('No Course/Space found', 'fluent-community'), | |
| 221 | 243 | $form->id, |
| 222 | 244 | $entry->id, |
| 223 | 245 | $this->integrationKey |
| 224 | 246 | ); |
| @@ -233,9 +255,9 @@ | ||
| 233 | 255 | if ($entry->user_id) { |
| 234 | 256 | $userId = $entry->user_id; |
| 235 | 257 | } else { |
| 236 | 258 | $emailAddress = Arr::get($formData, $emailKey); |
| 237 | - $existingUser = get_user_by('ID', $emailAddress); | |
| 259 | + $existingUser = get_user_by('email', $emailAddress); | |
| 238 | 260 | |
| 239 | 261 | if ($existingUser) { |
| 240 | 262 | $userId = $existingUser->ID; |
| 241 | 263 | } else { |
| @@ -247,9 +269,10 @@ | ||
| 247 | 269 | if (is_wp_error($userId)) { |
| 248 | 270 | return $this->addLog( |
| 249 | 271 | $feed['settings']['name'], |
| 250 | 272 | 'failed', |
| 251 | - 'Failed to create user. Reason: ' . $userId->get_error_message(), | |
| 273 | + /* translators: %s is replaced by the error message */ | |
| 274 | + __('Failed to create user. Reason: %s', 'fluent-community'), $userId->get_error_message(), | |
| 252 | 275 | $form->id, |
| 253 | 276 | $entry->id, |
| 254 | 277 | $this->integrationKey |
| 255 | 278 | ); |
| @@ -299,44 +322,13 @@ | ||
| 299 | 322 | * @return int|\WP_Error |
| 300 | 323 | */ |
| 301 | 324 | protected function registerUser($userData) |
| 302 | 325 | { |
| 303 | - $email = Arr::get($userData, 'email'); | |
| 304 | - if (!is_email($email)) { | |
| 305 | - return new \WP_Error('invalid_email', 'Invalid email address'); | |
| 306 | - } | |
| 307 | - | |
| 308 | - $password = trim(Arr::get($userData, 'password')); | |
| 309 | - if (!$password) { | |
| 310 | - $password = wp_generate_password(8); | |
| 311 | - } | |
| 312 | - | |
| 313 | - $nameArray = explode(' ', (string)Arr::get($userData, 'full_name')); | |
| 314 | - | |
| 315 | - $firstName = array_shift($nameArray); | |
| 316 | - $lastName = implode(' ', $nameArray); | |
| 317 | - | |
| 318 | - $userName = ProfileHelper::createUserNameFromStrings($email, array_filter([ | |
| 319 | - $firstName, | |
| 320 | - $lastName | |
| 321 | - ])); | |
| 322 | - | |
| 323 | - $userData = [ | |
| 324 | - 'role' => get_option('default_role', 'subscriber'), | |
| 325 | - 'user_email' => $email, | |
| 326 | - 'user_login' => $userName, | |
| 327 | - 'user_pass' => $password, | |
| 328 | - 'first_name' => $firstName, | |
| 329 | - 'last_name' => $lastName | |
| 330 | - ]; | |
| 331 | - | |
| 332 | - $userId = wp_insert_user($userData); | |
| 333 | - | |
| 334 | - if (is_wp_error($userId)) { | |
| 335 | - return $userId; | |
| 336 | - } | |
| 337 | - | |
| 338 | - return $userId; | |
| 326 | + return ProfileHelper::createWpUser([ | |
| 327 | + 'email' => Arr::get($userData, 'email', ''), | |
| 328 | + 'full_name' => Arr::get($userData, 'full_name', ''), | |
| 329 | + 'password' => Arr::get($userData, 'password', ''), | |
| 330 | + ]); | |
| 339 | 331 | } |
| 340 | 332 | |
| 341 | 333 | protected function addLog($title, $status, $description, $formId, $entryId, $integrationKey) |
| 342 | 334 | { |
| @@ -354,13 +346,13 @@ | ||
| 354 | 346 | |
| 355 | 347 | return true; |
| 356 | 348 | } |
| 357 | 349 | |
| 358 | - protected function maybeLogin($userId, $entry = false) | |
| 350 | + protected function maybeLogin($userId, $entry = null) | |
| 359 | 351 | { |
| 360 | 352 | // check if it's payment success page |
| 361 | 353 | // or direct url |
| 362 | - if (isset($_REQUEST['fluentform_payment_api_notify']) && $entry) { | |
| 354 | + if (isset($_REQUEST['fluentform_payment_api_notify']) && $entry) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 363 | 355 | // This payment IPN request so let's keep a reference for real request |
| 364 | 356 | Helper::setSubmissionMeta($entry->id, '_make_auto_login', $userId, $entry->form_id); |
| 365 | 357 | return; |
| 366 | 358 | } |