PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.34
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.34
6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 6.5.4 All 140 releases
formidable / classes / helpers / FrmEmailCollectionHelper.php

FrmEmailCollectionHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.34, at classes/helpers/FrmEmailCollectionHelper.php

96 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Email Collection Helper class.
4 *
5 * @package Formidable
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die( 'You are not allowed to call this page directly.' );
10 }
11
12 /**
13 * Provides helper functions for email collection and subscription.
14 *
15 * @since 6.25
16 */
17 class FrmEmailCollectionHelper {
18
19 /**
20 * When the user consents to receiving news of updates, subscribe their email to ActiveCampaign.
21 *
22 * @since 6.25
23 *
24 * @param string $email The email address to subscribe to ActiveCampaign.
25 *
26 * @return void
27 */
28 public static function subscribe_to_active_campaign( $email = '' ) {
29 $user = wp_get_current_user();
30
31 if ( ! $email ) {
32 $email = $user->user_email;
33 }
34
35 if ( self::is_fake_email( $email ) ) {
36 return;
37 }
38
39 $user_id = $user->ID;
40 $first_name = get_user_meta( $user_id, 'first_name', true );
41 $last_name = get_user_meta( $user_id, 'last_name', true );
42
43 wp_remote_post(
44 'https://sandbox.formidableforms.com/api/wp-admin/admin-ajax.php?action=frm_forms_preview&form=subscribe-onboarding',
45 array(
46 'body' => http_build_query(
47 array(
48 'form_key' => 'subscribe-onboarding',
49 'frm_action' => 'create',
50 'form_id' => 5,
51 'item_key' => '',
52 'item_meta[0]' => '',
53 'item_meta[15]' => $email,
54 'item_meta[17]' => 'Source - FF Lite Plugin Onboarding',
55 'item_meta[18]' => is_string( $first_name ) ? $first_name : '',
56 'item_meta[19]' => is_string( $last_name ) ? $last_name : '',
57 )
58 ),
59 )
60 );
61 }
62
63 /**
64 * Check if an email is fake, test, or local development email.
65 *
66 * @since 6.25
67 *
68 * @param string $email The email address to check.
69 *
70 * @return bool True if the email is fake/test, false if valid.
71 */
72 public static function is_fake_email( $email ) {
73 if ( ! is_email( $email ) ) {
74 return true;
75 }
76
77 $substrings = array(
78 '@wpengine.local',
79 '@example.com',
80 '@localhost',
81 '@local.dev',
82 '@local.test',
83 'test@gmail.com',
84 'admin@gmail.com',
85 );
86
87 foreach ( $substrings as $substring ) {
88 if ( str_contains( $email, $substring ) ) {
89 return true;
90 }
91 }
92
93 return false;
94 }
95 }
96