-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.settings.php
More file actions
executable file
·233 lines (205 loc) · 8.12 KB
/
class.settings.php
File metadata and controls
executable file
·233 lines (205 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
// Exit If Accessed Directly
if( ! defined( 'ABSPATH' ) ) { exit; }
// Setings Class
class wpbme_settings {
// Renders WP Settings API Forms
static function page_settings() {
wpbme_api::tracker( 'Settings' );
// Security
if( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.', 'benchmark-email-lite' ) );
}
// Apply Updates
$updated = false;
// Auth Keys Update
if( isset( $_POST[ 'wpbme_ap_token' ] ) ) {
update_option( 'wpbme_ap_token', esc_attr( $_POST[ 'wpbme_ap_token' ] ) );
$updated = true;
}
if( isset( $_POST[ 'wpbme_key' ] ) ) {
update_option( 'wpbme_key', esc_attr( $_POST[ 'wpbme_key' ] ) );
$updated = true;
}
if( isset( $_POST[ 'wpbme_temp_token' ] ) ) {
update_option( 'wpbme_temp_token', esc_attr( $_POST[ 'wpbme_temp_token' ] ) );
$updated = true;
}
// Tracker Disablement Update
if( isset( $_POST[ 'wpbme_tracking_disable' ] ) && $_POST[ 'wpbme_tracking_disable' ] == 'yes' ) {
update_option( 'wpbme_tracking_disable', 'yes' );
$updated = true;
} elseif( isset( $_POST[ 'wpbme_key' ] ) ) {
delete_option( 'wpbme_tracking_disable' );
$updated = true;
}
// Usage Disablement Update
if( isset( $_POST[ 'wpbme_usage_disable' ] ) && $_POST[ 'wpbme_usage_disable' ] == 'yes' ) {
update_option( 'wpbme_usage_disable', 'yes' );
$updated = true;
} elseif( isset( $_POST[ 'wpbme_key' ] ) ) {
delete_option( 'wpbme_usage_disable' );
$updated = true;
}
// Debug Update
if( isset( $_POST[ 'wpbme_debug' ] ) && $_POST[ 'wpbme_debug' ] == 'yes' ) {
update_option( 'wpbme_debug', 'yes' );
$updated = true;
} elseif( isset( $_POST[ 'wpbme_key' ] ) ) {
delete_option( 'wpbme_debug' );
$updated = true;
}
?>
<div class="wrap">
<h1><?php _e( 'Benchmark settings', 'benchmark-email-lite' ); ?></h1>
<br />
<form name="wbme_settings_form" method="post" action="">
<h2><?php _e( 'Benchmark connection', 'benchmark-email-lite' ); ?></h2>
<p>
<a href="https://ui.benchmarkemail.com/register?p=68907" target="_blank">
<?php _e( 'Get a FREE Benchmark Email account!', 'benchmark-email-lite' ); ?>
</a>
</p>
<?php
// Maybe Run Authentication
$auth_update = null;
if( isset( $_POST['BME_USERNAME'] ) && isset( $_POST['BME_PASSWORD'] ) ) {
$response = wpbme_api::authenticate(
esc_attr( $_POST['BME_USERNAME'] ),
esc_attr( $_POST['BME_PASSWORD'] )
);
if( $response && isset( $response['wpbme_key'] ) ) {
update_option( 'wpbme_ap_token', $response['wpbme_ap_token'] );
update_option( 'wpbme_key', $response['wpbme_key'] );
update_option( 'wpbme_temp_token', $response['wpbme_temp_token'] );
$updated = true;
$auth_update = true;
} else {
$auth_update = false;
}
}
if( ! get_option( 'wpbme_key' ) && empty( $_GET['wpbme_override'] ) ) {
?>
<?php if( $auth_update === false ) { ?>
<div class="notice notice-error is-dismissible">
<p><?php _e( 'The credential failed to authenticate.', 'benchmark-email-lite' ); ?></p>
</div>
<?php } elseif( $auth_update === true ) { ?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Your login was successful and access keys have been saved.', 'benchmark-email-lite' ); ?></p>
</div>
<?php } ?>
<p>
<label style="display: block;">
<?php _e( 'Benchmark Username', 'benchmark-email-lite' ); ?><br />
<input type="text" name="BME_USERNAME" />
</label>
</p>
<p>
<label style="display: block;">
<?php _e( 'Benchmark Password', 'benchmark-email-lite' ); ?><br />
<input type="password" name="BME_PASSWORD" />
</label>
</p>
<p class="submit">
<input type="submit" name="Submit" class="button-primary"
value="<?php esc_attr_e( 'Connect to Benchmark', 'benchmark-email-lite' ) ?>" />
</p>
<p>
<a href="admin.php?page=wpbme_settings&wpbme_override=1">
<?php _e( 'Or, click to enter keys manually', 'benchmark-email-lite' ); ?>
</a>
</p>
<?php
} else {
// Display Update Made
if( $updated ) {
wpbme_api::update_partner();
?>
<div class="updated">
<p><strong><?php _e( 'Settings saved.', 'benchmark-email-lite' ); ?></strong></p>
</div>
<?php
}
// Load Settings
$wpbme_ap_token = get_option( 'wpbme_ap_token' );
$wpbme_debug = get_option( 'wpbme_debug' );
$wpbme_key = get_option( 'wpbme_key' );
$wpbme_temp_token = get_option( 'wpbme_temp_token' );
$wpbme_tracking_disable = get_option( 'wpbme_tracking_disable' );
$wpbme_usage_disable = get_option( 'wpbme_usage_disable' );
?>
<?php if( ! get_option( 'wpbme_key' ) ) { ?>
<p>
<a href="admin.php?page=wpbme_settings">
<?php _e( 'Authenticate with username and password', 'benchmark-email-lite' ); ?>
</a>
</p>
<?php } ?>
<p>
<label style="display: block;">
<?php _e( 'API Key', 'benchmark-email-lite' ); ?><br />
<input type="text" size="36" id="wpbme_key" name="wpbme_key" value="<?php echo $wpbme_key; ?>" /><br />
<em><?php _e( 'Authenticates communications with the Benchmark REST API.', 'benchmark-email-lite' ); ?></em>
</label>
</p>
<p>
<label style="display: block;">
<?php _e( 'Authentication Token', 'benchmark-email-lite' ); ?><br />
<input type="text" size="36" id="wpbme_temp_token" name="wpbme_temp_token" value="<?php echo $wpbme_temp_token; ?>" /><br />
<em><?php _e( 'Authenticates your Benchmark Interface browser session.', 'benchmark-email-lite' ); ?></em>
</label>
</p>
<p>
<label style="display: block;">
<?php _e( 'Automation Pro Token', 'benchmark-email-lite' ); ?><br />
<input type="text" size="36" id="wpbme_ap_token" name="wpbme_ap_token" value="<?php echo $wpbme_ap_token; ?>" /><br />
<em><?php _e( 'Authenticates front-end visitor tracker used by Automation Pro.', 'benchmark-email-lite' ); ?></em>
</label>
</p>
<br />
<hr />
<h3><?php _e( 'Less common settings', 'benchmark-email-lite' ); ?></h3>
<p>
<label>
<?php $wpbme_tracking_disable = $wpbme_tracking_disable == 'yes' ? 'checked="checked"' : ''; ?>
<input type="checkbox" id="wpbme_tracking_disable" name="wpbme_tracking_disable" value="yes" <?php echo $wpbme_tracking_disable; ?> />
<?php _e( 'Disable visitor tracking?', 'benchmark-email-lite' ); ?><br />
<em><?php _e( 'Optionally disable the front-end visitor tracker used by Automation Pro conversion tracking.', 'benchmark-email-lite' ); ?></em>
</label>
</p>
<p>
<label>
<?php $wpbme_usage_disable = $wpbme_usage_disable == 'yes' ? 'checked="checked"' : ''; ?>
<input type="checkbox" id="wpbme_usage_disable" name="wpbme_usage_disable" value="yes" <?php echo $wpbme_usage_disable; ?> />
<?php _e( 'Disable admin usage tracking?', 'benchmark-email-lite' ); ?><br />
<em><?php _e( 'Optionally disable aggregate usage statistics for the developer of this plugin.', 'benchmark-email-lite' ); ?></em>
</label>
</p>
<?php if( class_exists( 'WooCommerce' ) ) { ?>
<p>
<label>
<?php $wpbme_debug = $wpbme_debug == 'yes' ? 'checked="checked"' : ''; ?>
<input type="checkbox" id="wpbme_debug" name="wpbme_debug" value="yes" <?php echo $wpbme_debug; ?> />
<?php _e( 'Enable debugging?', 'benchmark-email-lite' ); ?><br />
<em><?php _e( 'Optionally enable logging of all API communications into WooCommerce, as available.', 'benchmark-email-lite' ); ?></em>
<p>
<a href="<?php echo admin_url( 'admin.php?page=wc-status&tab=logs' ); ?>">
<?php _e( 'Logs are stored in WooCommerce', 'benchmark-email-lite' ); ?>
</a>
</p>
</label>
</p>
<?php } ?>
<br />
<hr />
<p class="submit">
<input type="submit" name="Submit" class="button-primary"
value="<?php esc_attr_e( 'Save Changes', 'benchmark-email-lite' ) ?>" />
</p>
<?php } ?>
</form>
</div>
<?php
}
}