Skip to content

Commit dc6f7a5

Browse files
bootstrap integrations at plugins_loaded:8 since that is required for ninja forms now
1 parent e6987da commit dc6f7a5

File tree

7 files changed

+163
-170
lines changed

7 files changed

+163
-170
lines changed

integrations/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ function mc4wp_admin_after_integration_settings(MC4WP_Integration $integration,
4444
mc4wp_register_integration('affiliatewp', 'MC4WP_AffiliateWP_Integration');
4545
mc4wp_register_integration('give', 'MC4WP_Give_Integration');
4646
mc4wp_register_integration('custom', 'MC4WP_Custom_Integration', true);
47+
mc4wp_register_integration('woocommerce', 'MC4WP_WooCommerce_Integration');
4748

48-
require __DIR__ . '/woocommerce/woocommerce.php';
4949
require __DIR__ . '/prosopo-procaptcha/bootstrap.php';
50-
require __DIR__ . '/ninja-forms/bootstrap.php';
5150
require __DIR__ . '/wpforms/bootstrap.php';
5251
require __DIR__ . '/gravity-forms/bootstrap.php';
52+
require __DIR__ . '/ninja-forms/bootstrap.php';

integrations/gravity-forms/bootstrap.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
mc4wp_register_integration('gravity-forms', 'MC4WP_Gravity_Forms_Integration', true);
66

7-
if (class_exists('GF_Fields')) {
8-
GF_Fields::register(new MC4WP_Gravity_Forms_Field());
9-
}
7+
add_action('plugins_loaded', function() {
8+
if (class_exists('GF_Fields')) {
9+
GF_Fields::register(new MC4WP_Gravity_Forms_Field());
10+
}
11+
});

integrations/ninja-forms/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
return $fields;
88
});
99

10-
add_action('ninja_forms_register_actions', function($actions) {
10+
add_filter('ninja_forms_register_actions', function($actions) {
1111
$actions['mc4wp_subscribe'] = new MC4WP_Ninja_Forms_Action();
1212
return $actions;
1313
});
Lines changed: 145 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,155 @@
11
<?php
22

33
if (! defined('ABSPATH')) {
4-
exit;
4+
exit;
55
}
66

77
/**
88
* Class MC4WP_Ninja_Forms_Action
99
*/
10-
final class MC4WP_Ninja_Forms_Action extends NF_Abstracts_ActionNewsletter
10+
class MC4WP_Ninja_Forms_Action extends NF_Abstracts_ActionNewsletter
1111
{
12-
/**
13-
* @var string
14-
*/
15-
protected $_name = 'mc4wp_subscribe';
16-
17-
/**
18-
* Constructor
19-
*/
20-
public function __construct()
21-
{
22-
parent::__construct();
23-
24-
$this->_nicename = __('Mailchimp', 'mailchimp-for-wp');
25-
$prefix = $this->get_name();
26-
27-
unset($this->_settings[ $prefix . 'newsletter_list_groups' ]);
28-
29-
$this->_settings['double_optin'] = array(
30-
'name' => 'double_optin',
31-
'type' => 'select',
32-
'label' => __('Use double opt-in?', 'mailchimp-for-wp'),
33-
'width' => 'full',
34-
'group' => 'primary',
35-
'value' => 1,
36-
'options' => array(
37-
array(
38-
'value' => 1,
39-
'label' => 'Yes',
40-
),
41-
array(
42-
'value' => 0,
43-
'label' => 'No',
44-
),
45-
),
46-
);
47-
48-
$this->_settings['update_existing'] = array(
49-
'name' => 'update_existing',
50-
'type' => 'select',
51-
'label' => __('Update existing subscribers?', 'mailchimp-for-wp'),
52-
'width' => 'full',
53-
'group' => 'primary',
54-
'value' => 0,
55-
'options' => array(
56-
array(
57-
'value' => 1,
58-
'label' => 'Yes',
59-
),
60-
array(
61-
'value' => 0,
62-
'label' => 'No',
63-
),
64-
),
65-
);
66-
67-
// $this->_settings[ 'replace_interests' ] = array(
68-
// 'name' => 'replace_interests',
69-
// 'type' => 'select',
70-
// 'label' => __( 'Replace existing interest groups?', 'mailchimp-for-wp'),
71-
// 'width' => 'full',
72-
// 'group' => 'primary',
73-
// 'value' => 0,
74-
// 'options' => array(
75-
// array(
76-
// 'value' => 1,
77-
// 'label' => 'Yes',
78-
// ),
79-
// array(
80-
// 'value' => 0,
81-
// 'label' => 'No',
82-
// ),
83-
// ),
84-
// );
85-
}
86-
87-
/*
88-
* PUBLIC METHODS
89-
*/
90-
91-
public function save($action_settings)
92-
{
93-
}
94-
95-
public function process($action_settings, $form_id, $data)
96-
{
97-
if (empty($action_settings['newsletter_list']) || empty($action_settings['EMAIL'])) {
98-
return;
99-
}
100-
101-
// find "mc4wp_optin" type field, bail if not checked.
102-
foreach ($data['fields'] as $field_data) {
103-
if ($field_data['type'] === 'mc4wp_optin' && empty($field_data['value'])) {
104-
return;
105-
}
106-
}
107-
108-
$list_id = $action_settings['newsletter_list'];
109-
$email_address = $action_settings['EMAIL'];
110-
$mailchimp = new MC4WP_MailChimp();
111-
112-
$merge_fields = $mailchimp->get_list_merge_fields($list_id);
113-
foreach ($merge_fields as $merge_field) {
114-
if (! empty($action_settings[ $merge_field->tag ])) {
115-
$merge_fields[ $merge_field->tag ] = $action_settings[ $merge_field->tag ];
116-
}
117-
}
118-
119-
$double_optin = (int) $action_settings['double_optin'] !== 0;
120-
$update_existing = (int) $action_settings['update_existing'] === 1;
121-
$replace_interests = isset($action_settings['replace_interests']) && (int) $action_settings['replace_interests'] === 1;
122-
123-
do_action('mc4wp_integration_ninja_forms_subscribe', $email_address, $merge_fields, $list_id, $double_optin, $update_existing, $replace_interests, $form_id);
124-
}
125-
126-
protected function get_lists()
127-
{
128-
$mailchimp = new MC4WP_MailChimp();
129-
130-
/** @var array $lists */
131-
$lists = $mailchimp->get_lists();
132-
$return = array();
133-
134-
foreach ($lists as $list) {
135-
$list_fields = array();
136-
137-
foreach ($mailchimp->get_list_merge_fields($list->id) as $merge_field) {
138-
$list_fields[] = array(
139-
'value' => $merge_field->tag,
140-
'label' => $merge_field->name,
141-
);
142-
}
143-
144-
// TODO: Add support for groups once base class supports this.
145-
146-
$return[] = array(
147-
'value' => $list->id,
148-
'label' => $list->name,
149-
'fields' => $list_fields,
150-
);
151-
}
152-
153-
return $return;
154-
}
12+
/**
13+
* @var string
14+
*/
15+
protected $_name = 'mc4wp_subscribe';
16+
17+
/**
18+
* Constructor
19+
*/
20+
public function __construct()
21+
{
22+
parent::__construct();
23+
24+
$this->_nicename = __('Mailchimp', 'mailchimp-for-wp');
25+
$prefix = $this->get_name();
26+
27+
unset($this->_settings[ $prefix . 'newsletter_list_groups' ]);
28+
29+
$this->_settings['double_optin'] = array(
30+
'name' => 'double_optin',
31+
'type' => 'select',
32+
'label' => __('Use double opt-in?', 'mailchimp-for-wp'),
33+
'width' => 'full',
34+
'group' => 'primary',
35+
'value' => 1,
36+
'options' => array(
37+
array(
38+
'value' => 1,
39+
'label' => 'Yes',
40+
),
41+
array(
42+
'value' => 0,
43+
'label' => 'No',
44+
),
45+
),
46+
);
47+
48+
$this->_settings['update_existing'] = array(
49+
'name' => 'update_existing',
50+
'type' => 'select',
51+
'label' => __('Update existing subscribers?', 'mailchimp-for-wp'),
52+
'width' => 'full',
53+
'group' => 'primary',
54+
'value' => 0,
55+
'options' => array(
56+
array(
57+
'value' => 1,
58+
'label' => 'Yes',
59+
),
60+
array(
61+
'value' => 0,
62+
'label' => 'No',
63+
),
64+
),
65+
);
66+
67+
// $this->_settings[ 'replace_interests' ] = array(
68+
// 'name' => 'replace_interests',
69+
// 'type' => 'select',
70+
// 'label' => __( 'Replace existing interest groups?', 'mailchimp-for-wp'),
71+
// 'width' => 'full',
72+
// 'group' => 'primary',
73+
// 'value' => 0,
74+
// 'options' => array(
75+
// array(
76+
// 'value' => 1,
77+
// 'label' => 'Yes',
78+
// ),
79+
// array(
80+
// 'value' => 0,
81+
// 'label' => 'No',
82+
// ),
83+
// ),
84+
// );
85+
}
86+
87+
/*
88+
* PUBLIC METHODS
89+
*/
90+
91+
public function save($action_settings)
92+
{
93+
}
94+
95+
public function process($action_settings, $form_id, $data)
96+
{
97+
if (empty($action_settings['newsletter_list']) || empty($action_settings['EMAIL'])) {
98+
return;
99+
}
100+
101+
// find "mc4wp_optin" type field, bail if not checked.
102+
foreach ($data['fields'] as $field_data) {
103+
if ($field_data['type'] === 'mc4wp_optin' && empty($field_data['value'])) {
104+
return;
105+
}
106+
}
107+
108+
$list_id = $action_settings['newsletter_list'];
109+
$email_address = $action_settings['EMAIL'];
110+
$mailchimp = new MC4WP_MailChimp();
111+
112+
$merge_fields = $mailchimp->get_list_merge_fields($list_id);
113+
foreach ($merge_fields as $merge_field) {
114+
if (! empty($action_settings[ $merge_field->tag ])) {
115+
$merge_fields[ $merge_field->tag ] = $action_settings[ $merge_field->tag ];
116+
}
117+
}
118+
119+
$double_optin = (int) $action_settings['double_optin'] !== 0;
120+
$update_existing = (int) $action_settings['update_existing'] === 1;
121+
$replace_interests = isset($action_settings['replace_interests']) && (int) $action_settings['replace_interests'] === 1;
122+
123+
do_action('mc4wp_integration_ninja_forms_subscribe', $email_address, $merge_fields, $list_id, $double_optin, $update_existing, $replace_interests, $form_id);
124+
}
125+
126+
protected function get_lists()
127+
{
128+
$mailchimp = new MC4WP_MailChimp();
129+
130+
/** @var array $lists */
131+
$lists = $mailchimp->get_lists();
132+
$return = array();
133+
134+
foreach ($lists as $list) {
135+
$list_fields = array();
136+
137+
foreach ($mailchimp->get_list_merge_fields($list->id) as $merge_field) {
138+
$list_fields[] = array(
139+
'value' => $merge_field->tag,
140+
'label' => $merge_field->name,
141+
);
142+
}
143+
144+
// TODO: Add support for groups once base class supports this.
145+
146+
$return[] = array(
147+
'value' => $list->id,
148+
'label' => $list->name,
149+
'fields' => $list_fields,
150+
);
151+
}
152+
153+
return $return;
154+
}
155155
}

integrations/woocommerce/woocommerce.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

integrations/wpforms/bootstrap.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
mc4wp_register_integration('wpforms', 'MC4WP_WPForms_Integration', true);
44

5-
function _mc4wp_wpforms_register_field()
6-
{
7-
if (! class_exists('WPForms_Field')) {
8-
return;
9-
}
10-
11-
new MC4WP_WPForms_Field();
12-
}
13-
14-
add_action('init', '_mc4wp_wpforms_register_field');
5+
add_action('plugins_loaded', function() {
6+
if (class_exists('WPForms_Field')) {
7+
new MC4WP_WPForms_Field();
8+
}
9+
});

mailchimp-for-wp.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ function _mc4wp_load_plugin()
9595
$integrations_admin->add_hooks();
9696
}
9797
}
98+
99+
// bootstrap integrations
100+
require __DIR__ . '/integrations/bootstrap.php';
98101
}
99102

100103
function _mc4wp_on_plugin_activation()
@@ -104,12 +107,8 @@ function _mc4wp_on_plugin_activation()
104107
wp_schedule_event(strtotime($time_string), 'daily', 'mc4wp_refresh_mailchimp_lists');
105108
}
106109

107-
// bootstrap custom integrations
108-
function _mc4wp_bootstrap_integrations()
109-
{
110-
require MC4WP_PLUGIN_DIR . '/integrations/bootstrap.php';
111-
}
112110

111+
// bootstrap main plugin
113112
add_action('plugins_loaded', '_mc4wp_load_plugin', 8);
114-
add_action('plugins_loaded', '_mc4wp_bootstrap_integrations', 90);
113+
115114
register_activation_hook(__FILE__, '_mc4wp_on_plugin_activation');

0 commit comments

Comments
 (0)