-
Notifications
You must be signed in to change notification settings - Fork 5
/
noptin.php
524 lines (439 loc) · 10.8 KB
/
noptin.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<?php
/**
* Noptin
*
* Simple WordPress optin form
*
*
* Plugin Name: Noptin - WordPress Newsletter Plugin
* Plugin URI: https://noptin.com
* Description: A very fast and lightweight WordPress newsletter plugin
* Author: Noptin Newsletter
* Author URI: https://github.com/picocodes
* Version: 3.6.7
* Text Domain: newsletter-optin-box
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
*
* @since 1.0.0
* @author Picocodes
* @author Kaz
* @license GNU General Public License, version 3
* @copyright Picocodes
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! defined( 'NOPTIN_VERIFY_NONCE' ) ) {
define( 'NOPTIN_VERIFY_NONCE', false );
}
define( 'MINIMUM_SUPPORTED_NOPTIN_ADDONS_PACK_VERSION', '3.0.0' );
/**
* Plugin main class
*
* @since 1.0.0
*/
class Noptin {
/**
* The current plugin version.
*
* @var string Plugin version
* @since 1.0.0
*/
public $version = '3.6.7';
/**
* The current database version.
*
* @var int Plugin db version
* @since 1.0.0
*/
public $db_version = 6;
/**
* Stores the main Noptin instance.
*
* @access private
* @var Noptin $instance The one true noptin
* @since 1.0.0
*/
private static $instance = null;
/**
* The main plugin file.
*
* @access public
* @var string Main plugin file;
* @since 1.0.0
*/
public static $file = __FILE__;
/**
* Local path to this plugins root directory
*
* @access public
* @var string|null the local plugin path.
* @since 1.0.0
*/
public $plugin_path = null;
/**
* Web path to this plugins root directory.
*
* @var string|null the plugin url path.
* @access public
* @since 1.0.0
*/
public $plugin_url = null;
/**
* If this is a test site.
*/
public $is_test = false;
/**
* White Label
*
* @var Noptin_White_Label
* @access public
* @since 1.7.7
*/
public $white_label = null;
/**
* New post notifications.
*
* @var Noptin_New_Post_Notify
* @access public
* @since 1.2.3
*/
public $post_notifications = null;
/**
* A state of the art email sender.
*
* @var Noptin_Mailer
* @since 1.2.8
*/
public $mailer = null;
/**
* Automation Rules.
*
* @var Noptin_Automation_Rules
* @since 1.2.8
*/
public $automation_rules;
/**
* The class responsible for registering various hooks and filters.
*
* @var Noptin_Hooks
* @since 1.2.9
*/
public $hooks;
/**
* The main admin class..
*
* @var Noptin_Admin
* @since 1.2.9
*/
public $admin;
/**
* The main custom fields class.
*
* @var Noptin_Custom_Fields
* @since 1.5.5
*/
public $custom_fields;
/**
* The main forms class.
*
* @var Noptin_Form_Manager
* @since 1.6.2
*/
public $forms;
/**
* The main emails class.
*
* @var Noptin_Email_Manager
* @since 1.7.0
*/
public $emails;
/**
* The main integrations class.
*
* @var Noptin_Integrations
* @since 1.7.0
*/
public $integrations;
/**
* New integrations class.
*
* @var \Hizzle\Noptin\Integrations\Main
*/
public $integrations_new;
/**
* Actions page.
*
* @var Noptin_Page
* @since 1.7.0
*/
public $actions_page;
/**
* Post types.
*
* @var Noptin_Post_Types
*/
public $post_types;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return Noptin The one true Noptin
*/
public static function instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Class Constructor.
*
* @since 1.0.0
*/
private function __construct() {
// Prevent double initialization.
if ( function_exists( 'noptin' ) ) {
return;
}
// Load files / register the autoloader.
$this->load_files();
// If autoloading failed.
if ( ! class_exists( 'Noptin_Hooks' ) ) {
return;
}
// Set up globals.
$this->setup_globals();
// Set up hooks.
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 5 );
}
/**
* Includes files.
*
* @access public
* @since 1.2.3
* @return void
*/
private function load_files() {
$plugin_path = plugin_dir_path( __FILE__ );
// Non-class files.
require_once $plugin_path . 'vendor/autoload.php';
require_once $plugin_path . 'includes/functions.php';
require_once $plugin_path . 'includes/subscriber.php';
require_once $plugin_path . 'includes/forms/forms.php';
require_once $plugin_path . 'includes/forms/class-form-manager.php';
require_once $plugin_path . 'includes/emails/class-manager.php';
require_once $plugin_path . 'includes/libraries/noptin-com/class-noptin-com.php';
// Register autoloader.
try {
spl_autoload_register( array( $this, 'autoload' ), true );
} catch ( Exception $e ) {
log_noptin_message( $e->getMessage() );
}
}
/**
* Sets up globals.
*
* @access public
* @since 1.2.3
* @return void
*/
private function setup_globals() {
// Set up globals;
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugins_url( '/', __FILE__ );
$this->is_test = 'production' !== wp_get_environment_type();
// Form manager.
$this->forms = new Noptin_Form_Manager();
// Email manager.
$this->emails = new Noptin_Email_Manager();
// Hooks class.
$this->hooks = new Noptin_Hooks();
}
/**
* Load integrations after plugins are loaded.
*
* @access public
* @since 1.3.3
*/
public function plugins_loaded() {
// Remove addons pack if version is less than 2.0.0
if ( defined( 'NOPTIN_ADDONS_PACK_VERSION' ) && version_compare( NOPTIN_ADDONS_PACK_VERSION, MINIMUM_SUPPORTED_NOPTIN_ADDONS_PACK_VERSION, '<' ) ) {
remove_action( 'noptin_integrations_load', 'noptin_addons_pack_load' );
}
do_action( 'before_noptin_load', $this );
// Integrations.
$this->integrations_new = new \Hizzle\Noptin\Integrations\Main();
$this->integrations = new Noptin_Integrations();
\Hizzle\Noptin\Objects\Users::add_default();
// Custom fields.
$this->custom_fields = new Noptin_Custom_Fields();
// DB.
$this->db();
// REST.
$this->api();
// Bulk email sender.
$this->bulk_emails();
if ( empty( $this->white_label ) ) {
$this->white_label = new Noptin_White_Label();
}
// Init scripts.
Noptin_Scripts::init();
// Init the plugin after WP inits
add_action( 'init', array( $this, 'init' ), 5 );
// Set up localisation.
add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
// (Maybe) upgrade the database;
add_action( 'init', array( $this, 'maybe_upgrade_db' ), 0 );
// css body class.
add_filter( 'body_class', array( $this, 'body_class' ) );
// Post types.
add_action( 'init', '\Hizzle\Noptin\Objects\Generic_Post_Type::register', 999 );
/**
* Fires after Noptin loads.
*
* @param Noptin $noptin The Noptin instance.
* @since 1.0.7
*/
do_action( 'noptin_load', $this );
}
/**
* Init the plugin after WordPress inits.
*
* @access public
* @since 1.0.5
* @return void
*/
public function init() {
/**
* Fires after WordPress inits but before Noptin inits
*
* @param Noptin $noptin The Noptin instance.
* @since 1.0.0
*/
do_action( 'before_noptin_init', $this );
// Init the admin.
$this->admin = Noptin_Admin::instance();
$this->admin->init();
// Actions page controller.
$this->actions_page = new Noptin_Page();
// Post types controller.
$this->post_types = new Noptin_Post_Types();
// Automation tasks.
$this->automation_rules = new Noptin_Automation_Rules();
/**
* Fires after Noptin inits
*
* @param Noptin $noptin The Noptin instance.
* @since 1.0.0
*/
do_action( 'noptin_init', $this );
}
/**
* Class autoloader
*
* @param string $class_name The name of the class to load.
* @access public
* @since 1.2.3
* @return void
*/
public function autoload( $class_name ) {
// Normalize the class name...
$class_name = strtolower( $class_name );
// ... and make sure it is our class.
if ( false === strpos( $class_name, 'noptin' ) ) {
return;
}
// Next, prepare the file name from the class.
$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
// Base path of the classes.
$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
// And an array of possible locations in order of importance;
$locations = array(
"$plugin_path/includes",
"$plugin_path/includes/admin",
"$plugin_path/includes/integrations",
"$plugin_path/includes/automation-rules",
"$plugin_path/includes/automation-rules/actions",
"$plugin_path/includes/automation-rules/triggers",
);
foreach ( apply_filters( 'noptin_autoload_locations', $locations ) as $location ) {
if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
include trailingslashit( $location ) . $file_name;
break;
}
}
}
/**
* Filters the body classes
*
* @access public
* @param array $classes Array of existing class names.
* @since 1.1.1
* @return array
*/
public function body_class( $classes ) {
$classes['noptin'] = 'noptin';
return $classes;
}
/**
* Runs installation
*
* @since 1.0.5
* @access public
*/
public function maybe_upgrade_db() {
$installed_version = absint( get_option( 'noptin_db_version', 0 ) );
// Upgrade db if installed version of noptin is lower than current version
if ( $installed_version < $this->db_version ) {
new Noptin_Install( $installed_version, $this->db_version );
do_action( 'noptin_upgrade_db', $installed_version, $this->db_version );
}
}
/**
* Returns the new DB manager.
*
* @return \Hizzle\Noptin\DB\Main
*/
public function db() {
return \Hizzle\Noptin\DB\Main::instance();
}
/**
* Returns the new REST API manager.
*
* @return \Hizzle\Noptin\REST\Main
*/
public function api() {
return \Hizzle\Noptin\REST\Main::instance();
}
/**
* Bulk email sender.
*
* @return \Hizzle\Noptin\Bulk_Emails\Main
*/
public function bulk_emails() {
return \Hizzle\Noptin\Bulk_Emails\Main::instance();
}
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
*
* Locales found in:
* - WP_LANG_DIR/plugins/newsletter-optin-box-LOCALE.mo
* - WP_PLUGIN_DIR/newsletter-optin-box/languages/newsletter-optin-box-LOCALE.mo
*
* @since 1.1.9
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'newsletter-optin-box',
false,
plugin_basename( __DIR__ ) . '/languages/'
);
}
}
// Kickstart everything.
Noptin::instance();