|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BetterOptin Provider Aweber |
|
4
|
|
|
* |
|
5
|
|
|
* @package BetterOptin/Provider/Aweber |
|
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_filter( 'wpbo_checklist', 'wpbo_aw_add_step' ); |
|
18
|
|
|
/** |
|
19
|
|
|
* Add new step. |
|
20
|
|
|
* |
|
21
|
|
|
* Add a step in the checklist during popup creation process |
|
22
|
|
|
* in order to was the user if the settings are not correct. |
|
23
|
|
|
* |
|
24
|
|
|
* @since 1.0.0 |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $checklist Current checklist |
|
27
|
|
|
* |
|
28
|
|
|
* @return array Updated checklist |
|
29
|
|
|
*/ |
|
30
|
|
|
function wpbo_aw_add_step( $checklist ) { |
|
31
|
|
|
|
|
32
|
|
|
$new = array(); |
|
33
|
|
|
$step = array( |
|
34
|
|
|
'label' => __( 'Setup Aweber', 'wpbo' ), |
|
35
|
|
|
'check' => wpbo_is_aweber_ready(), |
|
36
|
|
|
'against' => true, |
|
37
|
|
|
'compare' => 'EQUAL' |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
foreach ( $checklist as $id => $check ) { |
|
41
|
|
|
|
|
42
|
|
|
if ( 'published' == $id ) { |
|
43
|
|
|
$new['aweber'] = $step; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$new[ $id ] = $check; |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $new; |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
add_filter( 'wpbo_publish_button_action', 'wpbo_aw_prevent_publishing', 10, 2 ); |
|
55
|
|
|
/** |
|
56
|
|
|
* Prevent from publishing popup if Aweber is not ready. |
|
57
|
|
|
* |
|
58
|
|
|
* @since 1.0.0 |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $data Sanitized data |
|
61
|
|
|
* @param array $postarr Raw data |
|
62
|
|
|
* |
|
63
|
|
|
* @return array Sanitized data with updated status |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
function wpbo_aw_prevent_publishing( $data, $postarr ) { |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
if ( 'wpbo-popup' == $postarr['post_type'] && 'publish' == $data['post_status'] ) { |
|
68
|
|
|
|
|
69
|
|
|
if ( ! wpbo_is_aweber_ready() ) { |
|
70
|
|
|
$data['post_status'] = 'draft'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $data; |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
add_filter( 'wpbo_publish_button_label', 'wpbo_publish_button_label', 10, 2 ); |
|
80
|
|
|
/** |
|
81
|
|
|
* Change publish button label |
|
82
|
|
|
* |
|
83
|
|
|
* @since 1.0 |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $translation |
|
86
|
|
|
* @param string $text |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
View Code Duplication |
function wpbo_publish_button_label( $translation, $text ) { |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
global $typenow; |
|
93
|
|
|
|
|
94
|
|
|
if ( 'wpbo-popup' == $typenow ) { |
|
95
|
|
|
|
|
96
|
|
|
if ( isset( $_GET['post'] ) && 'Publish' == $text && ! wpbo_is_aweber_ready() ) { |
|
97
|
|
|
$translation = __( 'Save', 'wpbo' ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $translation; |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
add_action( 'admin_notices', 'wpbo_aw_settings_warning' ); |
|
107
|
|
|
/** |
|
108
|
|
|
* User warning. |
|
109
|
|
|
* |
|
110
|
|
|
* Warn user if settings are not correct. |
|
111
|
|
|
* |
|
112
|
|
|
* @since 1.0.0 |
|
113
|
|
|
*/ |
|
114
|
|
View Code Duplication |
function wpbo_aw_settings_warning() { |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
if ( ! wpbo_is_aweber_ready() ): ?> |
|
117
|
|
|
|
|
118
|
|
|
<div class="error"> |
|
119
|
|
|
<p><?php printf( __( 'Aweber integration is not correctly setup. Your popups won\'t send subscribers anywhere! <a href="%s">Click here to see the settings</a>.', 'wpbo' ), esc_url( add_query_arg( array( |
|
120
|
|
|
'post_type' => 'wpbo-popup', |
|
121
|
|
|
'page' => 'edit.php?post_type=wpbo-popup-settings&tab=aweber' |
|
122
|
|
|
), admin_url( 'edit.php' ) ) ) ); ?></p> |
|
123
|
|
|
</div> |
|
124
|
|
|
|
|
125
|
|
|
<?php endif; |
|
126
|
|
|
|
|
127
|
|
|
} |
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.