PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.3.1
JetFormBuilder — Dynamic Blocks Form Builder v1.3.1
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-handler.php 4 years ago forms-captcha.php 4 years ago getresponse-handler.php 4 years ago integration-base.php 4 years ago mailchimp-handler.php 4 years ago
mailchimp-handler.php
118 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 foreach ( $lists as $list_id => $list_name ) {
50 $groups[ $list_id ] = $this->get_groups( $list_id );
51 $fields[ $list_id ] = $this->get_fields( $list_id );
52 }
53
54 return array(
55 'lists' => $lists,
56 'groups' => $groups,
57 'fields' => $fields,
58 );
59 }
60
61 public function get_lists() {
62 $result = array();
63 $lists = $this->request( 'lists?count=999' );
64
65 if ( ! empty( $lists['lists'] ) ) {
66 foreach ( $lists['lists'] as $list ) {
67 $result[ $list['id'] ] = $list['name'];
68 }
69 }
70
71 return $result;
72 }
73
74 public function get_groups( $list_id ) {
75 $groups = array();
76 $categories = $this->request( 'lists/' . $list_id . '/interest-categories?count=999' );
77
78 if ( ! empty( $categories['categories'] ) ) {
79 foreach ( $categories['categories'] as $category ) {
80 $interests = $this->request( 'lists/' . $list_id . '/interest-categories/' . $category['id'] . '/interests?count=999' );
81
82 foreach ( $interests['interests'] as $interest ) {
83 $groups[] = array(
84 'value' => $interest['id'],
85 'label' => $category['title'] . ' - ' . $interest['name'],
86 );
87 }
88 }
89 }
90
91 return $groups;
92 }
93
94 public function get_fields( $list_id ) {
95 $result = array(
96 'email' => array(
97 'label' => esc_html__( 'Email', 'jet-form-builder' ),
98 'required' => true,
99 )
100 );
101
102 $merge_fields = $this->request( 'lists/' . $list_id . '/merge-fields?count=999' );
103
104 if ( ! empty( $merge_fields['merge_fields'] ) ) {
105 foreach ( $merge_fields['merge_fields'] as $field ) {
106 $result[ $field['tag'] ] = array(
107 'label' => $field['name'],
108 'required' => $field['required'],
109 );
110 }
111 }
112
113 return $result;
114 }
115 }
116
117
118