PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.6
JetFormBuilder — Dynamic Blocks Form Builder v2.1.6
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / integrations / mailchimp-handler.php
jetformbuilder / includes / integrations Last commit date
active-campaign 3 years ago active-campaign-handler.php 3 years ago forms-captcha.php 3 years ago getresponse-handler.php 3 years ago integration-base.php 3 years ago mailchimp-handler.php 3 years ago
mailchimp-handler.php
122 lines
1 <?php
2
3 namespace Jet_Form_Builder\Integrations;
4
5 /**
6 * MailChimp Handler
7 */
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 /**
15 * Define MailChimp_Handler class
16 */
17 class MailChimp_Handler extends Integration_Base {
18
19 public $success_statuses = array( 'subscribed', 'pending' );
20
21 /**
22 * Constructor for the class
23 *
24 * @param $api_key
25 */
26 public function __construct( $api_key ) {
27 parent::__construct( $api_key );
28
29 $api_key_data = explode( '-', $api_key );
30
31 if ( empty( $api_key_data[1] ) || 0 !== strpos( $api_key_data[1], 'us' ) ) {
32 return new \WP_Error( 'invalid_api_key' );
33 }
34
35 $this->api_base_url = sprintf( 'https://%s.api.mailchimp.com/3.0/', $api_key_data[1] );
36 $this->api_request_args = array(
37 'headers' => array(
38 'Authorization' => 'Basic ' . base64_encode( 'user:' . $this->api_key ),
39 ),
40 );
41
42 }
43
44 public function get_all_data() {
45 $lists = $this->get_lists();
46 $groups = array();
47 $fields = array();
48
49 if ( ! $lists ) {
50 return array();
51 }
52
53 foreach ( $lists as $list_id => $list_name ) {
54 $groups[ $list_id ] = $this->get_groups( $list_id );
55 $fields[ $list_id ] = $this->get_fields( $list_id );
56 }
57
58 return array(
59 'lists' => $lists,
60 'groups' => $groups,
61 'fields' => $fields,
62 );
63 }
64
65 public function get_lists() {
66 $result = array();
67 $lists = $this->request( 'lists?count=999' );
68
69 if ( ! empty( $lists['lists'] ) ) {
70 foreach ( $lists['lists'] as $list ) {
71 $result[ $list['id'] ] = $list['name'];
72 }
73 }
74
75 return $result;
76 }
77
78 public function get_groups( $list_id ) {
79 $groups = array();
80 $categories = $this->request( 'lists/' . $list_id . '/interest-categories?count=999' );
81
82 if ( ! empty( $categories['categories'] ) ) {
83 foreach ( $categories['categories'] as $category ) {
84 $interests = $this->request( 'lists/' . $list_id . '/interest-categories/' . $category['id'] . '/interests?count=999' );
85
86 foreach ( $interests['interests'] as $interest ) {
87 $groups[] = array(
88 'value' => $interest['id'],
89 'label' => $category['title'] . ' - ' . $interest['name'],
90 );
91 }
92 }
93 }
94
95 return $groups;
96 }
97
98 public function get_fields( $list_id ) {
99 $result = array(
100 'email' => array(
101 'label' => esc_html__( 'Email', 'jet-form-builder' ),
102 'required' => true,
103 ),
104 );
105
106 $merge_fields = $this->request( 'lists/' . $list_id . '/merge-fields?count=999' );
107
108 if ( ! empty( $merge_fields['merge_fields'] ) ) {
109 foreach ( $merge_fields['merge_fields'] as $field ) {
110 $result[ $field['tag'] ] = array(
111 'label' => $field['name'],
112 'required' => $field['required'],
113 );
114 }
115 }
116
117 return $result;
118 }
119 }
120
121
122