-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.e20r-payment-warning-pmpro.php
executable file
·1220 lines (972 loc) · 37.9 KB
/
class.e20r-payment-warning-pmpro.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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Custom Payment Reminders for Paid Memberships Pro
Description: Send Email information to members about their payment status (Credit Card & Membership Expiration warnings + Upcoming recurring membership payment notices)
Plugin URI: https://eighty20results.com/wordpress-plugins/e20r-payment-warning-pmpro
Author: Eighty / 20 Results by Wicked Strong Chicks, LLC <thomas@eighty20results.com>
Author URI: https://eighty20results.com/thomas-sjolshagen/
Developer: Thomas Sjolshagen <thomas@eighty20results.com>
Developer URI: https://eighty20results.com/thomas-sjolshagen/
PHP Version: 7.0
Version: 5.1
License: GPL2
Text Domain: e20r-payment-warning-pmpro
Domain Path: /languages
* Copyright (c) 2017-2019 - Eighty / 20 Results by Wicked Strong Chicks.
* ALL RIGHTS RESERVED
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace E20R\Payment_Warning;
use E20R\Payment_Warning\Editor\Reminder_Editor;
use E20R\Payment_Warning\Tools\Membership_Settings;
use E20R\Payment_Warning\Upgrades;
use E20R\Utilities\Cache;
use E20R\Payment_Warning\Tools\Cron_Handler;
use E20R\Utilities\Utilities;
use E20R\Utilities\Licensing\Licensing;
use E20R\Payment_Warning\Tools\Global_Settings;
if ( ! defined( 'ABSPATH' ) ) {
wp_die( __( "Cannot access", Payment_Warning::plugin_slug ) );
}
if ( ! defined( 'E20R_PW_VERSION' ) ) {
define( 'E20R_PW_VERSION', '5.1' );
}
if ( ! defined( 'E20R_PW_DIR' ) ) {
define( 'E20R_PW_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'E20R_WP_TEMPLATES' ) ) {
define( 'E20R_WP_TEMPLATES', plugin_dir_path( __FILE__ ) . 'templates' );
}
if ( ! defined( 'E20R_LICENSE_SERVER_URL' ) ) {
define( 'E20R_LICENSE_SERVER_URL', 'https://eighty20results.com/' );
}
if ( ! class_exists( 'E20R\Payment_Warning\Payment_Warning' ) ) {
global $e20r_pw_addons;
$e20r_pw_addons = array();
global $e20rpw_db_version;
$e20rpw_db_version = 4; // The current version of the DB schema
class Payment_Warning {
/**
* Various constants for the class/plugin
*/
const plugin_prefix = 'e20r_payment_warning_';
const plugin_slug = 'e20r-payment-warning-pmpro';
/**
* Constants used for Caching variables/info
*/
const cache_group = 'e20r_pw';
const option_group = 'e20r_pw_options';
/**
* Version of the plugin
*/
const version = E20R_PW_VERSION;
/**
* Instance of this class (Payment_Warning)
*
* @var Payment_Warning|null $instance
*
* @access private
* @since 1.0
*/
static private $instance = null;
/**
* Background handler for Subscriptions
*
* @var array|null $process_subscriptions
*/
protected $process_subscriptions = null;
/**
* Background handler for one-time payments (expiring memberships)
*
* @var array|null $process_payments
*/
protected $process_payments = null;
/**
* Background handler that queues large number of subscription plans to process
*
* @var Large_Request_Handler|null $lsubscription_requests
*/
protected $lsubscription_requests = null;
/**
* Background handler that queues large number of one-time payments to process (expiring memberships)
*
* @var Large_Request_Handler|null $lpayment_requests
*/
protected $lpayment_requests = null;
/**
* Payment_Warning constructor.
*
* @access private
* @since 1.0
*
* @since 2.1 - ENHANCEMENT: Subscription & Payment data collection didn't work when having multiple active gateways!
*/
private function __construct() {
add_filter( 'e20r-licensing-text-domain', array( $this, 'set_translation_domain' ) );
$utils = Utilities::get_instance();
$this->lsubscription_requests = new Large_Request_Handler( 'subscriptions' );
$this->lpayment_requests = new Large_Request_Handler( 'payments' );
$this->process_payments = array();
$this->process_subscriptions = array();
$addon_options = $this->get_addons();
foreach ( $addon_options as $addon ) {
$utils->log( "Loading subscription and payment handling class for the {$addon} module" );
$this->process_subscriptions[ $addon ] = new Handle_Subscriptions( $addon );
$this->process_payments[ $addon ] = new Handle_Payments( $addon );
}
$message_types = apply_filters( 'e20rpw_warning_message_types', array(
'recurring',
'expiring',
'ccexpiring',
) );
// Loop for the available Payment Warning message types to process (create handler processes)
foreach ( $message_types as $type ) {
$utils->log( "Loading messsage handling class for {$type} messages" );
$handler_name = "process_{$type}";
$this->{$handler_name} = new Handle_Messages( $type );
}
// First thing to do on activation (Required for this plugin)
add_action( 'e20r_pw_addon_activating_core', '\E20R\Payment_Warning\Tools\DB_Tables::create', - 1 );
add_action( 'e20r_pw_addon_activating_core', array(
Cron_Handler::get_instance(),
'configure_cron_schedules',
), 10 );
// Add Plugin deactivation actions
add_action( 'e20r_pw_addon_deactivating_core', array(
Cron_Handler::get_instance(),
'remove_cron_jobs',
), 10 );
}
/**
* Can the add-on be upgraded (does it have a license for the module being attempted upgraded)
*
* @param \stdClass $plugin_info - Array of plugin data for the update(s)
*
* @return \stdClass
*/
public function is_upgradable( $plugin_info ) {
global $e20r_pw_addons;
$utils = Utilities::get_instance();
$utils->log( "Check whether we're allowed to update licensed add-ons" );
foreach ( $e20r_pw_addons as $stub => $settings ) {
$plugin_name = strtolower( $settings['label'] );
$plugin_class_name = strtolower(
preg_replace(
'/_/',
'-',
$settings['class_name']
)
);
$plugin_file_name = sprintf(
'e20r-pw-%1$s-addon/class.%2$s.php',
$plugin_name,
$plugin_class_name
);
if ( ! in_array( $plugin_file_name, array_keys( $plugin_info->response ) ) ) {
continue;
}
if ( false === Licensing::is_licensed( $stub ) ) {
$utils->log( "Cannot update {$plugin_name} -> Removing it from the list of plugins to update!" );
unset( $plugin_info->response[ $plugin_file_name ] );
}
}
return $plugin_info;
}
/**
* Returns the handler for the request type
*
* @param string $type
* @param string $addon
*
* @return Handle_Messages|Handle_Payments|Handle_Subscriptions|Large_Request_Handler|null
*
* @since 2.1 - ENHANCEMENT: Subscription & Payment data collection didn't work when having multiple active gateways!
*/
public function get_handler( $type, $addon = null ) {
$handler = null;
$utils = Utilities::get_instance();
$utils->log( "Fetch handler for {$type}" );
switch ( $type ) {
case "lhr_subscriptions":
$handler = $this->lsubscription_requests;
break;
case 'lhr_payments':
$handler = $this->lpayment_requests;
break;
case "subscription":
$handler = $this->process_subscriptions[ $addon ];
break;
case "payment":
$handler = $this->process_payments[ $addon ];
break;
default:
$handler_name = "process_{$type}";
$handler = ! empty( $this->{$handler_name} ) ? $this->{$handler_name} : null;
}
if ( empty( $handler ) ) {
$utils = Utilities::get_instance();
$utils->log( "Error: Unable to assign handler for type {$type}!!!" );
}
return $handler;
}
/**
* Returns the instance of this class (singleton pattern)
*
* @return Payment_Warning
*
* @access public
* @since 1.0
*/
static public function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Disable actions/jobs for PMPro if equivalent service is enabled in this plugin
*/
public function disable_pmpro_actions() {
$util = Utilities::get_instance();
// Disable Recurring payment warnings if enabled in plugin
if ( true == Global_Settings::load_options( 'enable_payment_warnings' ) ) {
// Disable default PMPro (addon) recurring payment notice;
$util->log( "Disable recurring payment emails action if present" );
add_filter( 'pmprorm_send_reminder_to_user', '__return_false', 999 );
remove_action( "pmpro_cron_expiration_warnings", "pmpror_recurring_emails", 30 );
}
// Disable expiration warnings if enabled in plugin
if ( true == Global_Settings::load_options( 'enable_expiration_warnings' ) ) {
// Disable default PMPro expiration warnings;
$util->log( "Disable membership expiration warning emails, if present" );
add_filter( "pmpro_send_expiration_warning_email", "__return_false", 999 );
remove_action( "pmpro_cron_expiration_warnings", "pmproeewe_extra_emails", 30 );
remove_action( "pmpro_cron_expiration_warnings", "pmpro_cron_expiration_warnings", 10 );
}
// Disable Credit Card Expiration warnings if enabled in plugin
if ( true == Global_Settings::load_options( 'enable_cc_expiration_warnings' ) ) {
// Disable PMPro Credit Card Expiration warning messages
$util->log( "Disable credit card expiration warning emails action if present" );
remove_action( 'pmpro_cron_credit_card_expiring_warnings', 'pmpro_cron_credit_card_expiring_warnings', 10 );
}
}
/**
* Configure actions & filters for this plugin
*
* @access public
* @since 1.0
* @since 1.9.9 - ENHANCEMENT: Add 30 minute Cron schedule
* @since 3.8 - ENHANCEMENT: Be more discerning about the hooks/filters being when not doing a CRON job or the user isn't logged in
*/
public function plugins_loaded() {
$utils = Utilities::get_instance();
$utils->log( "Checking that we're not working on a license check (loopback)" );
$server_url = defined( 'E20R_LICENSE_SERVER_URL' ) ? E20R_LICENSE_SERVER_URL : null;
preg_match( "/eighty20results\.com/i", $server_url, $is_licensing_server );
if ( empty( $server_url ) ) {
$utils->log( "Error: Need to define the LICENSE URL constant in wp-admin.php!!!" );
return;
}
if ( ! Licensing::is_new_version() &&
'slm_check' == $utils->get_variable( 'slm_action', false ) &&
! empty( $is_licensing_server )
) {
$utils->log( "Processing license server operation (self referential check). Bailing!" );
return;
} else {
add_action( 'plugins_loaded', array( Licensing::get_instance(), 'load_hooks' ), 11 );
}
add_filter( 'e20r-licensing-text-domain', array( $this, 'set_translation_domain' ), 10, 1 );
add_action( 'init', array( $this, 'load_translation' ) );
/**
* @since v4.3 - BUG FIX: Load the payment reminder message filters on init (decides whether to send the message, etc)
*/
add_filter( 'init', array( Payment_Reminder::get_instance(), 'load_hooks' ) );
// Configure E20R_DEBUG_OVERRIDE constant in wp-config.php during testing
if ( defined( 'E20R_DEBUG_OVERRIDE' ) && true === E20R_DEBUG_OVERRIDE ) {
$utils->log( "Admin requested that we ignore the schedule delays/settings for testing purposes" );
add_filter( 'e20r_payment_warning_schedule_override', '__return_true' );
add_filter( 'e20r-email-notice-send-override', '__return_true' );
add_filter( 'e20r-payment-warning-send-email', array(
Payment_Reminder::get_instance(),
'send_reminder_override',
), 9999, 4 );
if ( defined( 'E20R_DEBUG_TIMEOUT' ) && true === E20R_DEBUG_TIMEOUT ) {
add_filter( 'e20r-payment-warning-fetch-timeout', array( $this, 'debug_timeout_value' ), 10, 1 );
}
}
$this->load_addon_settings();
/**
* Limit activity when not logged in or executing the CRON jobs
*
* @since v3.8 - ENHANCEMENT: Limit activity when not logged in or executing the CRON jobs
*/
if ( is_user_logged_in() || true === wp_doing_cron() ) {
// Maybe upgrade the DB
add_action( 'init', array( Payment_Warning::get_instance(), 'trigger_db_upgrade' ), - 1 );
// Add any licensing warnings
add_action( 'init', array( self::get_instance(), 'check_license_warnings' ), 10 );
// Deactivate PMPro actions
add_action( 'init', array( self::get_instance(), 'disable_pmpro_actions' ), 999 );
add_action( 'current_screen', array( $this, 'check_admin_screen' ), 10 );
/**
* Add 30 minute cron job schedule
*
* @since v1.9.9 - ENHANCEMENT: Add 30 minute Cron schedule
*/
add_filter( 'cron_schedules', array( Cron_Handler::get_instance(), 'cron_schedules' ), 10, 1 );
/**
* @since 3.8 - ENHANCEMENT: Only load certain actions if we're exclusively executing a CRON job
*/
if ( true === wp_doing_cron() || Utilities::is_admin() ) {
add_action( 'e20r_run_remote_data_update', array(
Cron_Handler::get_instance(),
'fetch_gateway_payment_info',
) );
add_action( 'e20r_send_payment_warning_emails', array(
Cron_Handler::get_instance(),
'send_reminder_messages',
) );
add_action( 'e20r_send_expiration_warning_emails', array(
Cron_Handler::get_instance(),
'send_expiration_messages',
) );
add_action( 'e20r_send_creditcard_warning_emails', array(
Cron_Handler::get_instance(),
'send_cc_warning_messages',
) );
/**
* Add hook to monitor background job mutext settings
*
* @since v1.9.9 - ENHANCEMENT: WP_Cron hook that monitors background data collection jobs
*/
add_action( 'e20r_check_job_status', array( Cron_Handler::get_instance(), 'clear_mutexes' ) );
add_action( 'e20r_pw_cron_trigger_capture_data', array(
self::$instance,
'load_active_subscriptions',
), 10, 2 );
add_action( 'e20r_pw_cron_trigger_send_messages', array(
self::$instance,
'send_recurring_payment_warnings',
), 10 );
}
/**
* @since 3.8 - ENHANCEMENT - Only load certain actions if we're exclusively loading the WP backend
*/
if ( Utilities::is_admin() ) {
// Load the admin & settings menu
add_action( 'admin_menu', array(
Global_Settings::get_instance(),
'load_admin_settings_page',
), 10 );
add_action( 'admin_menu', array( Reminder_Editor::get_instance(), 'load_tools_menu_item' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_register_scripts' ), 9 );
// add_action( 'admin_enqueue_scripts', array( $this, 'admin_register_scripts' ), 9 );
// add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 20 );
if ( ! empty ( $GLOBALS['pagenow'] )
&& ( 'options-general.php' === $GLOBALS['pagenow']
|| 'options.php' === $GLOBALS['pagenow']
)
) {
add_action( 'admin_init', array(
Global_Settings::get_instance(),
'register_settings_page',
), 10 );
}
add_action( 'pmpro_save_discount_code_level', array(
Membership_Settings::get_instance(),
'updated_discount_codes',
), 10, 2 );
add_action( 'pmpro_save_membership_level', array(
Membership_Settings::get_instance(),
'updated_membership_level',
), 10, 1 );
add_action( 'wp_ajax_e20rpw_save_template', array(
Reminder_Editor::get_instance(),
'save_template',
) );
add_action( 'wp_ajax_e20rpw_reset_template', array(
Reminder_Editor::get_instance(),
'reset_template',
) );
add_filter( 'site_transient_update_plugins', array( $this, 'is_upgradable' ), 9999, 1 );
/**
* Enable sending Payment Warning test email notices to specified user(s)
*/
add_action( 'e20r-email-notice-send-test-message', array(
Payment_Reminder::get_instance(),
'send_test_notice',
), 10, 3 );
// add_filter( 'e20r_pw_message_substitution_variables', 'E20R\Payment_Warning\Tools\Email_Message::replace_variable_text', 10, 3 );
if ( Utilities::is_admin() || true === wp_doing_cron() ) {
$this->load_licensed_modules();
add_filter( 'e20r-email-notice-footer-company-name', array(
$this,
'get_company_name',
), 10, 2 );
add_filter( 'e20r-email-notice-footer-company-address', array(
$this,
'get_company_address',
), 10, 2 );
add_filter( 'e20r-email-notice-footer-text', array( $this, 'load_unsubscribe_notice' ), 10, 2 );
if ( true === (bool) Global_Settings::load_options( 'enable_clear_old_data' ) ) {
$utils->log( "Enable deletion of old/stale records in local DB when cron job(s) complete" );
add_filter( 'e20r-payment-warning-clear-old-records', '__return_true' );
}
}
// Only load if both DEBUG and TEST_HOOKS is enabled
if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG &&
defined( 'E20R_PW_TEST_HOOKS' ) && true === E20R_PW_TEST_HOOKS
) {
$utils->log( "Loading test hooks for E20R Custom Payment Reminders" );
add_action( 'wp_ajax_test_get_remote_fetch', array(
Fetch_User_Data::get_instance(),
'configure_remote_subscription_data_fetch',
) );
add_action( 'wp_ajax_test_get_remote_payment', array(
Fetch_User_Data::get_instance(),
'configure_remote_payment_data_fetch',
) );
add_action( 'wp_ajax_test_fetch_remote_info', array(
Cron_Handler::get_instance(),
'fetch_gateway_payment_info',
) );
add_action( 'wp_ajax_test_run_record_check', array(
Payment_Reminder::get_instance(),
'process_reminders',
) );
add_action( 'wp_ajax_test_clear_cache', array(
Fetch_User_Data::get_instance(),
'clear_member_cache',
) );
add_action( 'wp_ajax_test_update_period', array(
Cron_Handler::get_instance(),
'find_shortest_recurring_period',
) );
add_action( 'wp_ajax_test_send_reminder', array(
Cron_Handler::get_instance(),
'send_reminder_messages',
) );
add_action( 'wp_ajax_test_send_ccexpiration', array(
Cron_Handler::get_instance(),
'send_cc_warning_messages',
)
);
}
}
}
// Last thing to do on deactivation (Required for this plugin)
add_action( 'e20r_pw_addon_deactivating_core', '\E20R\Payment_Warning\Tools\DB_Tables::remove', 9999, 1 );
add_action( 'e20r_pw_addon_deactivating_core', array(
Reminder_Editor::get_instance(),
'deactivate_plugin',
), 10, 1 );
// add_action( 'e20r_pw_addon_deactivating_core', array( Handle_Subscriptions::get_instance(), 'deactivate' ), 10, 1);
// add_action( 'e20r_pw_addon_activating_core', array( Cron_Handler::get_instance(), 'configure_cron_schedules'), 10, 0);
$utils->log( "Loading any/all remote IPN/Webhook/SilentPost/etc handlers for add-ons" );
/**
* Add all module remote AJAX call actions
*
* @since v3.8 - ENHANCEMENT: Always load the remote webhook/silent post/IPN handler functions for the plugin
*/
do_action( 'e20r_pw_addon_remote_call_handler' );
}
/**
* Override the timeout value for queue based processing during debug
*
* @param int $value
*
* @return int
*/
public function debug_timeout_value( $value ) {
return - 2;
}
/**
* Filter handler to add a footer text (unubscribe link, etc)
*
* @filter e20r-email-notice-footer-text
*
* @param string $footer_text
* @param string $plugin
*
* @return mixed
*/
public function load_unsubscribe_notice( $footer_text, $plugin ) {
if ( $plugin === Payment_Warning::plugin_slug ) {
$footer_text = null;
// FIXME: Add unsubscribe link for email notifications from this plugin - $this->load_options('company_address');
}
return $footer_text;
}
/**
* Filter handler to load company address setting from DB
*
* @filter e20r-email-notice-footer-company-address
*
* @param string $company_address
* @param string $plugin
*
* @return mixed
*/
public function get_company_address( $company_address, $plugin ) {
if ( $plugin === Payment_Warning::plugin_slug ) {
$company_address = Global_Settings::load_options( 'company_address' );
}
return $company_address;
}
/**
* Filter handler to load company name setting from DB
*
* @filter e20r-email-notice-footer-company-name
*
* @param string $company_name
* @param string $plugin
*
* @return mixed
*/
public function get_company_name( $company_name, $plugin ) {
if ( $plugin === Payment_Warning::plugin_slug ) {
$company_name = Global_Settings::load_options( 'company_name' );
}
return $company_name;
}
/**
* Load all modules that require an active license (in the 'init' action!)
*/
public function load_licensed_modules() {
$utils = Utilities::get_instance();
$utils->log( "Loading licensed functionality for..." );
// Load licensed modules (if applicable)
add_action( 'e20r-pw-load-licensed-modules', array( Reminder_Editor::get_instance(), 'load_hooks' ) );
$active_addons = apply_filters( 'e20r-pw-active-addons', array(
'stripe_gateway_addon',
'paypal_gateway_addon',
'check_gateway_addon',
) );
$has_loaded = false;
foreach ( $active_addons as $addon_name ) {
if ( true === Licensing::is_licensed( $addon_name ) ) {
$utils->log( "Enable licensed module: {$addon_name}" );
$has_loaded = true;
}
}
if ( true === $has_loaded ) {
$utils->log( "Loading licensed modules/functionality!" );
do_action( 'e20r-pw-load-licensed-modules' );
}
}
/**
* Validate that we're on the plugin specific screen/page for this add-on
*
* @param array $current_screen
*/
public function check_admin_screen( $current_screen ) {
$utils = Utilities::get_instance();
if ( ! empty( $this->settings_page_hook ) && $this->settings_page_hook === $current_screen->id ) {
$utils->log( "Clear cache on register settings page" );
Cache::delete( Licensing::CACHE_KEY, Licensing::CACHE_GROUP );
}
}
/**
* Configure the Language domain for the licensing class/code
*
* @param string $domain
*
* @return string
*/
public function set_translation_domain( $domain ) {
return Payment_Warning::plugin_slug;
}
/**
* Load language/translation file(s)
*/
public function load_translation() {
$locale = apply_filters( "plugin_locale", get_locale(), Payment_Warning::plugin_slug );
$mo = Payment_Warning::plugin_slug . "-{$locale}.mo";
// Paths to local (plugin) and global (WP) language files
$local_mo = plugin_dir_path( __FILE__ ) . "/languages/{$mo}";
$global_mo = WP_LANG_DIR . "/" . Payment_Warning::plugin_slug . "/{$mo}";
// Load global version first
load_textdomain( Payment_Warning::plugin_slug, $global_mo );
// Load local version second
load_textdomain( Payment_Warning::plugin_slug, $local_mo );
}
/**
* Return list of available add-on classes in add-on directory (may not be loaded yet)
*
* @return string[]
*/
public function get_addons() {
$utils = Utilities::get_instance();
$addon_list = array();
$addon_directory_list = apply_filters( 'e20r_pw_addon_directory_path', array( plugin_dir_path( __FILE__ ) . "class/add-on/" ) );
// Search through all of the addon directories supplied
foreach ( $addon_directory_list as $addon_directory ) {
if ( false !== ( $files = scandir( $addon_directory ) ) ) {
$utils->log( "Found add-on files in {$addon_directory}" );
$excluded = apply_filters( 'e20r_licensing_excluded', array(
'e20r_default_license',
'example_gateway_addon',
'new_licenses',
'readme',
) );
foreach ( $files as $file ) {
// Skip (ignore) as add-ons to process/list
if ( '.' === $file || '..' === $file || 'e20r-pw-gateway-addon' === $file ) {
continue;
}
$parts = explode( '.', $file );
$class_name = $parts[ count( $parts ) - 2 ];
$class_name = preg_replace( '/-/', '_', $class_name );
$addon_info = explode( '_', $class_name );
$addon = array_shift( $addon_info );
if ( ! in_array( $addon, $addon_list ) &&
! in_array( $addon, array( 'e20r', 'example' ) )
) {
$utils->log( "Added {$addon} to list of possible add-ons" );
$addon_list[] = strtolower( $addon );
}
}
}
}
return $addon_list;
}
/**
* Load add-on classes & configure them
*/
private function load_addon_settings() {
global $e20r_pw_addons;
$utils = Utilities::get_instance();
$addon_directory_list = apply_filters( 'e20r_pw_addon_directory_path', array( plugin_dir_path( __FILE__ ) . "class/add-on/" ) );
// Search through all of the addon directories supplied
foreach ( $addon_directory_list as $addon_directory ) {
if ( false !== ( $files = scandir( $addon_directory ) ) ) {
$utils->log( "Found files in {$addon_directory}" );
foreach ( $files as $file ) {
if ( '.' === $file || '..' === $file || 'e20r-pw-gateway-addon' === $file || 'readme' === $file || 'class' === $file ) {
$utils->log( "Skipping file: {$file}" );
continue;
}
$parts = explode( '.', $file );
// $utils->log( "Parts: " . print_r( $parts, true ) );
$index = count( $parts ) - 2;
$class_name = $parts[ $index ];
$class_name = preg_replace( '/-/', '_', $class_name );
$utils->log( "Searching for: {$class_name}" );
/**
* BUG: Assumes the e20r_pw_addons list contains the list of active add-ons
*/
if ( is_array( $e20r_pw_addons ) && ! empty( $e20r_pw_addons ) ) {
$configured_addons = array_map( 'strtolower', array_keys( $e20r_pw_addons ) );
// $utils->log( "Loading configured add-ons: " . print_r( $configured_addons, true ) );
} else {
$configured_addons = array();
}
$excluded = apply_filters( 'e20r_licensing_excluded', array(
'e20r_default_license',
'example_gateway_addon',
'new_licenses',
'readme',
) );
if ( ! in_array( $class_name, $configured_addons ) &&
! in_array( $class_name, $excluded ) &&
false === strpos( $class_name, 'e20r_pw_gateway_addon' ) ) {
$utils->log( "Found unlisted class: {$class_name}" );
$var_name = 'class_name';
$path = $addon_directory . sanitize_file_name( $file );
$utils->log( "Path to {$class_name}: {$path}" );
// Include the add-on source file
if ( file_exists( $path ) ) {
$utils->log( "Loading source file for {$class_name}" );
require_once( $path );
if ( ! isset( $e20r_pw_addons[ $class_name ] ) ) {
$utils->log("The {$class_name} configuration array hasn't been loaded!");
do_action( 'e20r_pw_addon_load_configuration', $class_name );
}
$class = $e20r_pw_addons[ $class_name ][ $var_name ];
if ( empty( $class ) ) {
$utils->log( "Expected class value ({$class_name}) was not found!" );
continue;
}
$class = "E20R\\Payment_Warning\\Addon\\{$class}";
$utils->log( "Checking if {$class} add-on is enabled?" );
$enabled = $class::is_enabled( $class_name );
if ( true == $enabled ) {
$utils->log( "Triggered load of filters & hooks for {$class}" );
// $class::configure_addon();
}
}
} else {
$utils->log( "Skipping {$class_name}" );
}
}
}
}
}
/**
* Returns true if one of the available Gateway add-ons has an active license.
*
* @return bool
*/
public function has_licensed_gateway() {
global $e20r_pw_addons;
$has_licensed_gateway = false;
if ( ! empty( $e20r_pw_addons ) ) {
foreach ( $e20r_pw_addons as $stub => $settings ) {
if ( $stub !== 'standard_gateway_addon' ) {
$has_licensed_gateway = $has_licensed_gateway || Licensing::is_licensed( $stub );
}
}
}
return $has_licensed_gateway;
}
/**
* Check if the license(s) are valid/active/about to renew
* @since v4.3 - ENHANCEMENT: Send license warning/expiration email to admin on fixed frequency
* @since v4.3 - ENHANCEMENT: Added `e20rpw_send_license_reminder` filter to configure # of days between reminders
*/
public function check_license_warnings() {
global $e20r_pw_addons;
$products = array_keys( $e20r_pw_addons );
$utils = Utilities::get_instance();
$reminder_frequency = apply_filters( 'e20rpw_send_license_reminder', 7 );
$is_sent = ( ( intval( get_option( 'e20rpw_license_warning_sent', 0 ) ) ) <=
current_time( 'timestamp' ) + ( $reminder_frequency * DAY_IN_SECONDS ) );
$admin_email = get_option( 'admin_email' );
$utils->log( "Check for any license warnings!" );
foreach ( $products as $stub ) {
$utils->log( "Checking status for {$stub}" );
$license_status = Licensing::is_license_expiring( $stub );
$utils->log( "Status is: {$license_status}" );
if ( true === $license_status ) {
$msg = sprintf( __( 'The license for the plugin that sends upcoming payment warnings and membership expiration promotions to your members (using the %1$s payment gateway) will renew soon. To keep sending these reminders to your customers who paid via the %1$s payment gateway, please verify that <a href="%2$s" target="_blank">your license</a> will renew automatically by going to <a href="%3$s" target="_blank">your account page</a> and verify the status of your payment method and license' ), $e20r_pw_addons[ $stub ]['label'], 'https://eighty20results.com/licenses/', 'https://eighty20results.com/account/' );
if ( is_admin() ) {
$utils->add_message( $msg, 'warning', 'backend' );
}
if ( false === $is_sent ) {
$utils->log( "Sending license renewing email warning to {$admin_email}" );
wp_mail( $admin_email, __( "Important: The payment and expiration warnings license may renew soon", Payment_Warning::plugin_slug ), "<p>{$msg}</p>" );
update_option( 'e20rpw_license_warning_sent', current_time( 'timestamp' ), 'no' );
}
if ( - 1 === $license_status ) {
$msg = sprintf( __( 'Your %1$s add-on license for sending upcoming payment reminders and membership expiration promotion messages has expired. To resume sending these warnings to your members (using the %1$s payment gateway), you will need to <a href="%2$s" target="_blank">purchase and install a new %1$s license</a>.' ), $e20r_pw_addons[ $stub ]['label'], 'https://eighty20results.com/licenses/' );
if ( is_admin() ) {
$utils->add_message( $msg, 'error', 'backend' );
}
if ( false === $is_sent ) {
$utils->log( "Sending license expired email warning to {$admin_email}" );
wp_mail(
$admin_email,
__( "CRITICAL: Not sending payment and expiration warnings to your members!", Payment_Warning::plugin_slug ),
"<p>{$msg}</p>"
);
update_option( 'e20rpw_license_warning_sent', current_time( 'timestamp' ), 'no' );
}
}
}
}
}
/**
* Returns an array of add-ons that are active for this plugin
*
* @return array
*
* @access public
*
* @since 2.1 - BUG FIX: Would cache an empty list of active add-ons (if they existed)
* @since 2.1 - ENHANCEMENT: Make the get_active_addons() method public
*/
public function get_active_addons() {
global $e20r_payment_gateways;
if ( null === ( $active = Cache::get( 'e20r_pw_active_addons', Payment_Warning::cache_group ) ) ) {
$active = array();
foreach ( $e20r_payment_gateways as $addon => $settings ) {
if ( true == $settings['status'] ) {
$active[] = $addon;
}