PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.6
JetFormBuilder — Dynamic Blocks Form Builder v3.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
getresponse-handler.php 2 years ago integration-base.php 2 years ago mailchimp-handler.php 2 years ago
mailchimp-handler.php
117 lines
1 <?php
2
3 namespace Jet_Form_Builder\Integrations;
4
5 // If this file is called directly, abort.
6 if ( ! defined( 'WPINC' ) ) {
7 die;
8 }
9
10 /**
11 * Define MailChimp_Handler class
12 */
13 class MailChimp_Handler extends Integration_Base {
14
15 public $success_statuses = array( 'subscribed', 'pending' );
16
17 /**
18 * Constructor for the class
19 *
20 * @param $api_key
21 */
22 public function __construct( $api_key ) {
23 parent::__construct( $api_key );
24
25 $api_key_data = explode( '-', $api_key );
26
27 if ( empty( $api_key_data[1] ) || 0 !== strpos( $api_key_data[1], 'us' ) ) {
28 // phpcs:ignore Universal.CodeAnalysis.ConstructorDestructorReturn.ReturnValueFound
29 return new \WP_Error( 'invalid_api_key' );
30 }
31
32 $this->api_base_url = sprintf( 'https://%s.api.mailchimp.com/3.0/', $api_key_data[1] );
33 $this->api_request_args = array(
34 'headers' => array(
35 // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions
36 'Authorization' => 'Basic ' . base64_encode( 'user:' . $this->api_key ),
37 ),
38 );
39 }
40
41 public function get_all_data() {
42 $lists = $this->get_lists();
43 $groups = array();
44 $fields = array();
45
46 if ( ! $lists ) {
47 return array();
48 }
49
50 foreach ( $lists as $list_id => $list_name ) {
51 $groups[ $list_id ] = $this->get_groups( $list_id );
52 $fields[ $list_id ] = $this->get_fields( $list_id );
53 }
54
55 return array(
56 'lists' => $lists,
57 'groups' => $groups,
58 'fields' => $fields,
59 );
60 }
61
62 public function get_lists() {
63 $result = array();
64 $lists = $this->request( 'lists?count=999' );
65
66 if ( ! empty( $lists['lists'] ) ) {
67 foreach ( $lists['lists'] as $list ) {
68 $result[ $list['id'] ] = $list['name'];
69 }
70 }
71
72 return $result;
73 }
74
75 public function get_groups( $list_id ) {
76 $groups = array();
77 $categories = $this->request( 'lists/' . $list_id . '/interest-categories?count=999' );
78
79 if ( ! empty( $categories['categories'] ) ) {
80 foreach ( $categories['categories'] as $category ) {
81 $interests = $this->request( 'lists/' . $list_id . '/interest-categories/' . $category['id'] . '/interests?count=999' );
82
83 foreach ( $interests['interests'] as $interest ) {
84 $groups[] = array(
85 'value' => $interest['id'],
86 'label' => $category['title'] . ' - ' . $interest['name'],
87 );
88 }
89 }
90 }
91
92 return $groups;
93 }
94
95 public function get_fields( $list_id ) {
96 $result = array(
97 'email' => array(
98 'label' => esc_html__( 'Email', 'jet-form-builder' ),
99 'required' => true,
100 ),
101 );
102
103 $merge_fields = $this->request( 'lists/' . $list_id . '/merge-fields?count=999' );
104
105 if ( ! empty( $merge_fields['merge_fields'] ) ) {
106 foreach ( $merge_fields['merge_fields'] as $field ) {
107 $result[ $field['tag'] ] = array(
108 'label' => $field['name'],
109 'required' => $field['required'],
110 );
111 }
112 }
113
114 return $result;
115 }
116 }
117