← All changes
|
classes/controllers/FrmOnboardingWizardController.php
+76
-9
6.25
→
6.23
View file →
| @@ -122,12 +122,12 @@ | ||
| 122 | 122 | * @since 6.9 |
| 123 | 123 | */ |
| 124 | 124 | public static function load_admin_hooks() { |
| 125 | 125 | self::set_page_url(); |
| 126 | - add_action( 'admin_init', self::class . '::do_admin_redirects' ); | |
| 126 | + add_action( 'admin_init', __CLASS__ . '::do_admin_redirects' ); | |
| 127 | 127 | |
| 128 | 128 | if ( self::has_onboarding_been_skipped() ) { |
| 129 | - add_filter( 'option_frm_inbox', self::class . '::add_wizard_to_floating_links' ); | |
| 129 | + add_filter( 'option_frm_inbox', __CLASS__ . '::add_wizard_to_floating_links' ); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Load page if admin page is Onboarding Wizard. |
| 133 | 133 | self::maybe_load_page(); |
| @@ -203,14 +203,14 @@ | ||
| 203 | 203 | // Dismiss the onboarding wizard message so it stops appearing after it is clicked. |
| 204 | 204 | $message = new FrmInbox(); |
| 205 | 205 | $message->dismiss( 'onboarding_wizard' ); |
| 206 | 206 | |
| 207 | - add_action( 'admin_menu', self::class . '::menu', 99 ); | |
| 208 | - add_action( 'admin_init', self::class . '::assign_properties' ); | |
| 209 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 210 | - add_action( 'admin_head', self::class . '::remove_menu' ); | |
| 207 | + add_action( 'admin_menu', __CLASS__ . '::menu', 99 ); | |
| 208 | + add_action( 'admin_init', __CLASS__ . '::assign_properties' ); | |
| 209 | + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 ); | |
| 210 | + add_action( 'admin_head', __CLASS__ . '::remove_menu' ); | |
| 211 | 211 | |
| 212 | - add_filter( 'admin_body_class', self::class . '::add_admin_body_classes', 999 ); | |
| 212 | + add_filter( 'admin_body_class', __CLASS__ . '::add_admin_body_classes', 999 ); | |
| 213 | 213 | add_filter( 'frm_show_footer_links', '__return_false' ); |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| @@ -253,9 +253,9 @@ | ||
| 253 | 253 | 'Formidable | ' . $label, |
| 254 | 254 | $label, |
| 255 | 255 | self::REQUIRED_CAPABILITY, |
| 256 | 256 | self::PAGE_SLUG, |
| 257 | - array( self::class, 'render' ) | |
| 257 | + array( __CLASS__, 'render' ) | |
| 258 | 258 | ); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
| @@ -311,14 +311,81 @@ | ||
| 311 | 311 | // Remove the 'FrmProSettingsController::store' action to avoid PHP errors during AJAX call. |
| 312 | 312 | remove_action( 'frm_store_settings', 'FrmProSettingsController::store' ); |
| 313 | 313 | $frm_settings->store(); |
| 314 | 314 | |
| 315 | - FrmEmailCollectionHelper::subscribe_to_active_campaign(); | |
| 315 | + self::subscribe_to_active_campaign(); | |
| 316 | 316 | |
| 317 | 317 | // Send response. |
| 318 | 318 | wp_send_json_success(); |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | + /** | |
| 322 | + * When the user consents to receiving news of updates, subscribe their email to ActiveCampaign. | |
| 323 | + * | |
| 324 | + * @since 6.16 | |
| 325 | + * | |
| 326 | + * @return void | |
| 327 | + */ | |
| 328 | + private static function subscribe_to_active_campaign() { | |
| 329 | + $user = wp_get_current_user(); | |
| 330 | + if ( empty( $user->user_email ) ) { | |
| 331 | + return; | |
| 332 | + } | |
| 333 | + | |
| 334 | + if ( ! self::should_send_email_to_active_campaign( $user->user_email ) ) { | |
| 335 | + return; | |
| 336 | + } | |
| 337 | + | |
| 338 | + $user_id = $user->ID; | |
| 339 | + $first_name = get_user_meta( $user_id, 'first_name', true ); | |
| 340 | + $last_name = get_user_meta( $user_id, 'last_name', true ); | |
| 341 | + | |
| 342 | + wp_remote_post( | |
| 343 | + 'https://sandbox.formidableforms.com/api/wp-admin/admin-ajax.php?action=frm_forms_preview&form=subscribe-onboarding', | |
| 344 | + array( | |
| 345 | + 'body' => http_build_query( | |
| 346 | + array( | |
| 347 | + 'form_key' => 'subscribe-onboarding', | |
| 348 | + 'frm_action' => 'create', | |
| 349 | + 'form_id' => 5, | |
| 350 | + 'item_key' => '', | |
| 351 | + 'item_meta[0]' => '', | |
| 352 | + 'item_meta[15]' => $user->user_email, | |
| 353 | + 'item_meta[17]' => 'Source - FF Lite Plugin Onboarding', | |
| 354 | + 'item_meta[18]' => is_string( $first_name ) ? $first_name : '', | |
| 355 | + 'item_meta[19]' => is_string( $last_name ) ? $last_name : '', | |
| 356 | + ) | |
| 357 | + ), | |
| 358 | + ) | |
| 359 | + ); | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * Try to skip any fake emails. | |
| 364 | + * | |
| 365 | + * @since 6.16 | |
| 366 | + * | |
| 367 | + * @param string $email | |
| 368 | + * @return bool | |
| 369 | + */ | |
| 370 | + private static function should_send_email_to_active_campaign( $email ) { | |
| 371 | + $substrings = array( | |
| 372 | + '@wpengine.local', | |
| 373 | + '@example.com', | |
| 374 | + '@localhost', | |
| 375 | + '@local.dev', | |
| 376 | + '@local.test', | |
| 377 | + 'test@gmail.com', | |
| 378 | + 'admin@gmail.com', | |
| 379 | + | |
| 380 | + ); | |
| 381 | + foreach ( $substrings as $substring ) { | |
| 382 | + if ( false !== strpos( $email, $substring ) ) { | |
| 383 | + return false; | |
| 384 | + } | |
| 385 | + } | |
| 386 | + return true; | |
| 387 | + } | |
| 321 | 388 | |
| 322 | 389 | /** |
| 323 | 390 | * Handle AJAX request to set up usage data for the Onboarding Wizard. |
| 324 | 391 | * |