-
Notifications
You must be signed in to change notification settings - Fork 1
/
better-optin.php
368 lines (303 loc) · 9.47 KB
/
better-optin.php
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
/**
* Better Optin.
*
* @package BetterOptin
* @author ThemeAvenue <web@themeavenue.net>
* @license GPL-2.0+
* @link http://themeavenue.net
* @copyright 2014 ThemeAvenue
*
* @wordpress-plugin
* Plugin Name: BetterOptin
* Plugin URI: https://betteropt.in/
* Description: BetterOptin helps you convert your visitors in subscribers and fill up your mailing lists.
* Version: 2.0.2
* Author: ThemeAvenue
* Author URI: https://themeavenue.net
* Text Domain: betteroptin
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'BetterOptin' ) ):
/**
* Main BetterOptin class
*
* This class is the one and only instance of the plugin. It is used
* to load the core and all its components.
*
* @since 2.0
*/
final class BetterOptin {
/**
* @var BetterOptin Holds the unique instance of BetterOptin
* @since 2.0
*/
private static $instance;
/**
* Possible error message.
*
* @since 2.0
* @var null|WP_Error
*/
protected $error = null;
/**
* Instantiate and return the unique BetterOptin object
*
* @since 2.0
* @return object BetterOptin Unique instance of BetterOptin
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof BetterOptin ) ) {
// Instantiate
self::$instance = new BetterOptin;
self::$instance->init();
}
return self::$instance;
}
/**
* Instantiate the plugin
*
* @since 2.0
* @return void
*/
private function init() {
self::$instance->setup_constants();
// Make sure the WordPress version is recent enough
if ( ! self::$instance->are_dependencies_loaded() ) {
self::$instance->add_error( wp_kses_post( sprintf( __( 'BetterOptin cannot load because its dependencies are missing. If you don't know what this means, please purchase the pro version on %s', 'betteroptin' ), '<a href="https://betteropt.in/?utm_source=plugin&utm_medium=dependencies_nag&utm_campaign=upsell" target="_blank">https://betteropt.in</a>' ) ) );
}
// If we have any error, don't load the plugin
if ( is_a( self::$instance->error, 'WP_Error' ) ) {
add_action( 'admin_notices', array( self::$instance, 'display_error' ), 10, 0 );
return;
}
self::$instance->setup_database_constants();
self::$instance->includes();
self::$instance->load_providers();
if ( is_admin() ) {
self::$instance->includes_admin();
}
add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
add_action( 'init', array( self::$instance, 'license_notification' ) );
add_action( 'init', array( self::$instance, 'check_provider_ready' ) );
}
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 2.0
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'betteroptin' ), '2.0' );
}
/**
* Disable unserializing of the class
*
* @since 2.0
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'betteroptin' ), '2.0' );
}
/**
* Setup all plugin constants
*
* @since 2.0
* @return void
*/
private function setup_constants() {
define( 'WPBO_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
define( 'WPBO_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'WPBO_BASENAME', plugin_basename( __FILE__ ) );
define( 'WPBO_PLUGIN_FILE', __FILE__ );
define( 'WPBO_VERSION', '2.0.2' );
define( 'WPBO_DB_VERSION', '1' );
}
private function are_dependencies_loaded() {
return is_dir( WPBO_PATH . 'vendor' );
}
/**
* Add error.
*
* Add a new error to the WP_Error object
* and create the object if it doesn't exist yet.
*
* @since 2.0
*
* @param string $message Error message to add
*
* @return void
*/
private function add_error( $message ) {
if ( ! is_object( $this->error ) || ! is_a( $this->error, 'WP_Error' ) ) {
$this->error = new WP_Error();
}
$this->error->add( 'addon_error', $message );
}
/**
* Display error.
*
* Get all the error messages and display them
* in the admin notices.
*
* @since 2.0
* @return void
*/
public function display_error() {
if ( ! is_a( $this->error, 'WP_Error' ) ) {
return;
}
$message = self::$instance->error->get_error_messages(); ?>
<div class="error">
<p>
<?php
if ( count( $message ) > 1 ) {
echo '<ul>';
foreach ( $message as $msg ) {
echo "<li>$msg</li>";
}
echo '</li>';
} else {
echo $message[0];
}
?>
</p>
</div>
<?php
}
/**
* Setup the custom database table constants
*
* @since 2.0
* @return void
*/
private function setup_database_constants() {
global $wpdb;
define( 'wpbo_analytics_table_name', 'wpbo_analytics' );
define( 'wpbo_failsafe_table_name', 'wpbo_failsafe' );
define( 'wpbo_analytics_table', $wpdb->prefix . wpbo_analytics_table_name );
define( 'wpbo_failsafe_table', $wpdb->prefix . wpbo_failsafe_table_name );
}
/**
* Include all files used sitewide
*
* @since 2.0
* @return void
*/
private function includes() {
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
require( WPBO_PATH . 'includes/scripts.php' );
require( WPBO_PATH . 'includes/shortcode.php' );
require( WPBO_PATH . 'includes/functions-templating.php' );
require( WPBO_PATH . 'includes/functions-dummy.php' );
}
require( WPBO_PATH . 'includes/class-popup.php' );
require( WPBO_PATH . 'includes/functions-post-type.php' );
require( WPBO_PATH . 'includes/functions-analytics.php' );
require( WPBO_PATH . 'includes/functions-failsafe.php' );
require( WPBO_PATH . 'includes/functions-popup.php' );
require( WPBO_PATH . 'includes/functions-misc.php' );
require( WPBO_PATH . 'includes/functions-ajax.php' );
}
/**
* Include all files used in admin only
*
* @since 2.0
* @return void
*/
private function includes_admin() {
require( WPBO_PATH . 'includes/admin/functions-misc.php' );
require( WPBO_PATH . 'vendor/julien731/wp-dismissible-notices-handler/handler.php' );
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
require( WPBO_PATH . 'includes/admin/class-titan-framework.php' );
require( WPBO_PATH . 'includes/admin/settings/settings-general.php' );
require( WPBO_PATH . 'includes/admin/functions-menu.php' );
require( WPBO_PATH . 'includes/admin/functions-metabox.php' );
require( WPBO_PATH . 'includes/admin/functions-list-table.php' );
require( WPBO_PATH . 'includes/install.php' );
}
}
/**
* Load all the providers from the providers directory
*
* @since 2.0
* @return void
*/
private function load_providers() {
require( WPBO_PATH . 'includes/providers/wordpress/load.php' );
require( WPBO_PATH . 'includes/providers/mailchimp/load.php' );
require( WPBO_PATH . 'includes/providers/mailpoet/load.php' );
require( WPBO_PATH . 'includes/providers/aweber/load.php' );
}
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
apply_filters( 'plugin_locale', get_locale(), 'betteroptin' );
load_plugin_textdomain( 'betteroptin', false, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' );
}
/**
* Display an admin notice if license key is missing
*
* @since 2.0
* @return void
*/
public function license_notification() {
if ( ! function_exists( 'DNH' ) ) {
return;
}
$license = wpbo_get_option( 'license_key', '' );
/**
* Do not show the notice if the license key has already been entered.
*/
if ( ! empty( $license ) ) {
return;
}
$license_page = wpbo_get_settings_page_link();
dnh_register_notice( 'wpbo_no_license', 'error', sprintf( __( 'You haven't entered your BetterOptin license key. This means that you will not get automatic updates and you will not get technical support. <a %s>Click here to enter your license key</a>.', 'betteroptin' ), "href='$license_page'" ), array( 'cap' => 'administrator' ) );
}
/**
* Make sure a provider is selected for the lead collection
*
* @since 2.0
* @return void
*/
public function check_provider_ready() {
if ( ! function_exists( 'DNH' ) ) {
return;
}
if ( false !== wpbo_is_provider_ready() ) {
return;
}
$license_page = wpbo_get_settings_page_link();
dnh_register_notice( 'wpbo_no_provider', 'error', sprintf( __( 'You haven't selected your provider for catching leads. <strong>BetterOptin will not work until you do so!</strong> <a %s>Click here to select your provider</a>.', 'betteroptin' ), "href='$license_page'" ) );
}
}
endif;
/**
* The main function responsible for returning the unique BetterOptin instance
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* @since 2.0
* @return object BetterOptin
*/
function BO() {
return BetterOptin::instance();
}
// Get BetterOptin Running
BO();