|
1
|
|
|
<?php |
|
2
|
|
|
if ( ! class_exists( 'WPBO_Provider_MailPoet' ) ) { |
|
3
|
|
|
|
|
4
|
|
|
class WPBO_Provider_MailPoet { |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Trigger form submission. |
|
8
|
|
|
* |
|
9
|
|
|
* Add a last couple of checks, set the redirects and |
|
10
|
|
|
* finally subscribe the visitor to the MailChimp list. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 1.0.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @param array $data Form data |
|
15
|
|
|
* |
|
16
|
|
|
* @return bool |
|
17
|
|
|
*/ |
|
18
|
|
|
public static function submit( $data ) { |
|
19
|
|
|
|
|
20
|
|
|
$user_id = self::subscribe( $data ); |
|
21
|
|
|
|
|
22
|
|
|
if ( ! is_int( $user_id ) ) { |
|
23
|
|
|
return false; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
return true; |
|
27
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Subscribe the visitor to a list. |
|
32
|
|
|
* |
|
33
|
|
|
* @since 1.0.0 |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $data Form data |
|
36
|
|
|
* |
|
37
|
|
|
* @return array Result |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function subscribe( $data ) { |
|
40
|
|
|
|
|
41
|
|
|
$email = sanitize_email( $data['email'] ); |
|
42
|
|
|
$list_id = wpbo_get_option( 'mp_list_id', '' ); |
|
43
|
|
|
$popup_id = (int) $data['wpbo_id']; |
|
44
|
|
|
$custom_list = get_post_meta( $popup_id, 'wpbo_mp_list', true ); |
|
45
|
|
|
$list_id = '' != $custom_list ? $custom_list : $list_id; |
|
46
|
|
|
|
|
47
|
|
|
// Possibly get additional fields |
|
48
|
|
|
$first_name = isset( $data['first_name'] ) ? sanitize_text_field( $data['first_name'] ) : sanitize_key( $data['name'] ); |
|
49
|
|
|
$last_name = isset( $data['last_name'] ) ? sanitize_text_field( $data['last_name'] ) : ''; |
|
50
|
|
|
|
|
51
|
|
|
$user_data = array( |
|
52
|
|
|
'email' => $email, |
|
53
|
|
|
'firstname' => apply_filters( 'bomp_subscriber_first_name', $first_name ), |
|
54
|
|
|
'lastname' => apply_filters( 'bomp_subscriber_last_name', $last_name ) |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
$data_subscriber = array( |
|
58
|
|
|
'user' => $user_data, |
|
59
|
|
|
'user_list' => array( 'list_ids' => array( $list_id ) ) |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$helper_user = WYSIJA::get( 'user', 'helper' ); |
|
63
|
|
|
$add = $helper_user->addSubscriber( $data_subscriber ); |
|
64
|
|
|
|
|
65
|
|
|
return $add; |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
} |