|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BetterOptin Provider MailChimp |
|
4
|
|
|
* |
|
5
|
|
|
* @package BetterOptin/Provider/MailChimp |
|
6
|
|
|
* @author ThemeAvenue <[email protected]> |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link http://themeavenue.net |
|
9
|
|
|
* @copyright 2015 ThemeAvenue |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// If this file is called directly, abort. |
|
13
|
|
|
if ( ! defined( 'WPINC' ) ) { |
|
14
|
|
|
die; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
add_action( 'admin_notices', 'wpbo_mc_settings_warning' ); |
|
18
|
|
|
/** |
|
19
|
|
|
* Incomplete settings warning. |
|
20
|
|
|
* |
|
21
|
|
|
* Warn user if settings are not correct. |
|
22
|
|
|
* |
|
23
|
|
|
* @since 1.0.0 |
|
24
|
|
|
*/ |
|
25
|
|
View Code Duplication |
function wpbo_mc_settings_warning() { |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
if ( ! WPBO_MC()->is_mailchimp_ready() ): ?> |
|
28
|
|
|
|
|
29
|
|
|
<div class="error"> |
|
30
|
|
|
<p><?php printf( __( 'MailChimp integration is not correctly setup. Your popups won\'t send subscribers anywhere! <a href="%s">Click here to see the settings</a>.', 'betteroptin' ), esc_url( add_query_arg( array( |
|
31
|
|
|
'post_type' => 'wpbo-popup', |
|
32
|
|
|
'page' => 'edit.php?post_type=wpbo-popup-settings&tab=mailchimp' |
|
33
|
|
|
), admin_url( 'edit.php' ) ) ) ); ?></p> |
|
34
|
|
|
</div> |
|
35
|
|
|
|
|
36
|
|
|
<?php endif; |
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
add_filter( 'wpbo_checklist', 'wpbo_mc_add_step' ); |
|
41
|
|
|
/** |
|
42
|
|
|
* Add new step. |
|
43
|
|
|
* |
|
44
|
|
|
* Add a step in the checklist during popup creation process |
|
45
|
|
|
* in order to was the user if the settings are not correct. |
|
46
|
|
|
* |
|
47
|
|
|
* @since 1.0.0 |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $checklist Current checklist |
|
50
|
|
|
* |
|
51
|
|
|
* @return array Updated checklist |
|
52
|
|
|
*/ |
|
53
|
|
|
function wpbo_mc_add_step( $checklist ) { |
|
54
|
|
|
|
|
55
|
|
|
if ( ! wpbo_is_popup_edit_screen() ) { |
|
56
|
|
|
return $checklist; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$ready = WPBO_MC()->is_mailchimp_ready() ? true : false; |
|
60
|
|
|
$new = array(); |
|
61
|
|
|
$step = array( |
|
62
|
|
|
'label' => __( 'Setup MailChimp', 'betteroptin' ), |
|
63
|
|
|
'check' => $ready, |
|
64
|
|
|
'against' => true, |
|
65
|
|
|
'compare' => 'EQUAL' |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
foreach ( $checklist as $id => $check ) { |
|
69
|
|
|
|
|
70
|
|
|
if ( 'published' == $id ) { |
|
71
|
|
|
$new['mailchimp'] = $step; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$new[ $id ] = $check; |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $new; |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
add_filter( 'wpbo_publish_button_action', 'wpbo_mc_prevent_publishing', 10, 2 ); |
|
83
|
|
|
/** |
|
84
|
|
|
* Prevent from publishing popup if MailChimp is not ready. |
|
85
|
|
|
* |
|
86
|
|
|
* @since 1.0.0 |
|
87
|
|
|
* |
|
88
|
|
|
* @param array $data Sanitized data |
|
89
|
|
|
* @param array $postarr Raw data |
|
90
|
|
|
* |
|
91
|
|
|
* @return array Sanitized data with updated status |
|
92
|
|
|
*/ |
|
93
|
|
View Code Duplication |
function wpbo_mc_prevent_publishing( $data, $postarr ) { |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
if ( ! wpbo_is_popup_edit_screen() ) { |
|
96
|
|
|
return $data; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if ( 'wpbo-popup' == $postarr['post_type'] && 'publish' == $data['post_status'] ) { |
|
100
|
|
|
|
|
101
|
|
|
if ( ! $this->is_mailchimp_ready() ) { |
|
|
|
|
|
|
102
|
|
|
$data['post_status'] = 'draft'; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $data; |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
add_filter( 'wpbo_publish_button_label', 'wpbo_mc_publish_button_label', 10, 2 ); |
|
112
|
|
|
/** |
|
113
|
|
|
* Change the save button label if MailChimp integration is not yet ready |
|
114
|
|
|
* |
|
115
|
|
|
* @since 1.0 |
|
116
|
|
|
* |
|
117
|
|
|
* @param $translation |
|
118
|
|
|
* @param $text |
|
119
|
|
|
* |
|
120
|
|
|
* @return string|void |
|
121
|
|
|
*/ |
|
122
|
|
|
function wpbo_mc_publish_button_label( $translation, $text ) { |
|
123
|
|
|
|
|
124
|
|
|
if ( ! wpbo_is_popup_edit_screen() ) { |
|
125
|
|
|
return $translation; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
global $typenow; |
|
129
|
|
|
|
|
130
|
|
|
if ( 'wpbo-popup' == $typenow ) { |
|
131
|
|
|
|
|
132
|
|
|
if ( isset( $_GET['post'] ) && 'Publish' == $text && ! WPBO_MC()->is_mailchimp_ready() ) { |
|
133
|
|
|
$translation = __( 'Save', 'betteroptin' ); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return $translation; |
|
139
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.