-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathclass-ms-controller-plugin.php
More file actions
1429 lines (1271 loc) · 38.8 KB
/
Copy pathclass-ms-controller-plugin.php
File metadata and controls
1429 lines (1271 loc) · 38.8 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
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
/**
* Primary controller for Membership Plugin.
*
* This controller is created during the `setup_theme` hook!
*
* Responsible for flow control, navigation and invoking other controllers.
*
* @since 1.0.0
*
* @package Membership2
* @subpackage Controller
*/
class MS_Controller_Plugin extends MS_Controller {
/**
* Plugin Menu slug.
*
* @var string
* @since 1.0.0
*
*/
const MENU_SLUG = 'membership2';
/**
* The slug of the top-level admin page
*
* @var string
* @since 1.0.0
*
*/
private static $base_slug = '';
/**
* Capability required to count as M2 'admin' user. Admin users have full
* access to all M2 features.
*
* @var $capability
* @since 1.0.0
*
*/
protected $capability = 'manage_options';
/**
* Instance of MS_Model_Plugin.
*
* @var $model
* @since 1.0.0
*
*/
private $model;
/**
* Pointer array for other controllers.
*
* @var $controllers
* @since 1.0.0
*
*/
protected $controllers = array();
/**
* Stores the callback handler for the submenu items.
* It is set by self::route_submenu_request() and is used by
* self::handle_submenu_request()
*
* @var array
* @since 1.0.0
*
*/
private $menu_handler = null;
/**
* Constructs the primary Plugin controller.
*
* Created by the MS_Plugin object during the setup_theme action.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct();
/**
* Fix for IE: This is a privacy policy which states, that we do not
* collect personal contact information without consent.
*
* Note that other plugins that output this header later will overwrite
* it! So this is a default value if no other file sends the P3P header.
*
* @since 1.0.2.2
*/
$p3p_done = false;
foreach ( headers_list() as $header ) {
if ( false !== stripos( $header, 'P3P:' ) ) {
$p3p_done = true;
break;
}
}
// We can not set header, when it's already sent.
if ( ! $p3p_done && ! headers_sent() ) {
header( 'P3P:CP="NOI"' );
}
/*
* Remove the "&msg" attribute from the URL if it was already present in
* the previous request.
*/
if ( empty( $_POST ) ) {
/*
* No form was submitted:
* It's save to redirect the request without losing form-data.
*/
if ( isset( $_GET['msg'] )
&& isset( $_SERVER['HTTP_REFERER'] )
&& MS_Helper_Utility::is_current_url( $_SERVER['HTTP_REFERER'] )
) {
// A msg is set AND the referer URL has the same msg flag!
$url = esc_url_raw( remove_query_arg( array( 'msg' ) ) );
wp_safe_redirect( $url );
exit;
}
}
/**
* We allow two ways to modify the default Admin-Capability setting:
*
* Either by defining the constant in wp-config or by using the filter.
* The constant takes priority over the filter.
*
* @since 1.0.0
*/
if ( defined( 'MS_ADMIN_CAPABILITY' ) && MS_ADMIN_CAPABILITY ) {
$this->capability = MS_ADMIN_CAPABILITY;
} else {
$this->capability = apply_filters(
'ms_admin_user_capability',
$this->capability
);
}
// Create core controllers that are available on every page.
$this->model = MS_Factory::load( 'MS_Model_Plugin' );
$this->dialogs = MS_Factory::load( 'MS_Controller_Dialog' );
$this->controllers['widget'] = MS_Factory::load( 'MS_Controller_Widget' );
$this->controllers['membership'] = MS_Factory::load( 'MS_Controller_Membership' );
$this->controllers['protection'] = MS_Factory::load( 'MS_Controller_Protection' );
$this->controllers['rule'] = MS_Factory::load( 'MS_Controller_Rule' );
$this->controllers['member'] = MS_Factory::load( 'MS_Controller_Member' );
$this->controllers['billing'] = MS_Factory::load( 'MS_Controller_Billing' );
$this->controllers['addon'] = MS_Factory::load( 'MS_Controller_Addon' );
$this->controllers['pages'] = MS_Factory::load( 'MS_Controller_Pages' );
$this->controllers['settings'] = MS_Factory::load( 'MS_Controller_Settings' );
$this->controllers['communication'] = MS_Factory::load( 'MS_Controller_Communication' );
$this->controllers['gateway'] = MS_Factory::load( 'MS_Controller_Gateway' );
$this->controllers['admin_bar'] = MS_Factory::load( 'MS_Controller_Adminbar' );
$this->controllers['membership_metabox'] = MS_Factory::load( 'MS_Controller_Metabox' );
$this->controllers['membership_shortcode'] = MS_Factory::load( 'MS_Controller_Shortcode' );
$this->controllers['frontend'] = MS_Factory::load( 'MS_Controller_Frontend' );
$this->controllers['import'] = MS_Factory::load( 'MS_Controller_Import' );
$this->controllers['help'] = MS_Factory::load( 'MS_Controller_Help' );
$this->controllers['compatibility'] = MS_Factory::load( 'MS_Controller_Compatibility' );
// API should be the last Controller to create.
$this->controllers['api'] = MS_Controller_Api::instance();
// Load the template-tags.
require_once MS_Plugin::instance()->dir . 'app/template/template-tags.php';
// Register all available styles and scripts. Nothing is enqueued.
$this->add_action( 'wp_loaded', 'wp_loaded' );
// Setup plugin admin UI.
$this->add_action( 'admin_menu', 'add_menu_pages' ); //for multisite, it needs too for Protection Rules page
if ( is_multisite() && MS_Plugin::is_network_wide() ) {
$this->add_action( 'network_admin_menu', 'add_menu_pages' );
}
// Select the right page to display.
$this->add_action( 'admin_init', 'route_submenu_request' );
//Plugin policy settings
$this->add_action( 'admin_init', 'add_privacy_policy_content' );
// This will do the ADMIN-SIDE initialization of the controllers
$this->add_action( 'ms_plugin_admin_setup', 'run_admin_init' );
// Changes the current themes "single" template to the invoice form when an invoice is displayed.
$this->add_filter( 'single_template', 'custom_single_template' );
$this->add_filter( 'page_template', 'custom_page_template' );
// Register styles and javascripts for use in front-end
$this->add_action( 'ms_register_public_scripts', 'register_public_scripts' );
$this->add_action( 'ms_register_public_scripts', 'register_public_styles' );
$this->add_action( 'wp_enqueue_scripts', 'enqueue_plugin_styles' );
$this->add_action( 'wp_enqueue_scripts', 'enqueue_plugin_scripts' );
/**
* Register data exporters and erasers
*/
$this->add_filter( 'wp_privacy_personal_data_exporters', 'register_exporter' );
$this->add_filter( 'wp_privacy_personal_data_erasers', 'register_eraser' );
}
/**
* Creates all the plugin controllers and initialize stuff.
*
* This is done after admin_menu (when in admin site) or
* after setup_theme (on front-end)
*
* @since 1.0.0
*/
public function run_admin_init() {
if ( ! is_admin() && ! is_network_admin() ) {
return;
}
/*
* This function is used to redirect the user to special kind of page
* that is not available via the menu.
*/
$this->check_special_view();
foreach ( $this->controllers as $obj ) {
$obj->admin_init();
}
// Register styles and javascripts for use in admin-side
$this->run_action( 'ms_register_admin_scripts', 'register_admin_scripts' );
$this->run_action( 'ms_register_admin_scripts', 'register_admin_styles' );
$this->run_action( 'admin_enqueue_scripts', 'enqueue_plugin_admin_styles' );
$this->run_action( 'admin_enqueue_scripts', 'enqueue_plugin_admin_scripts' );
}
/**
* If a special view is active then we ensure that it is displayed now.
*
* A special view is not accessible via the normal menu structure, like
* a Migration assistant or an overview page after updating the plugin.
*
* Special views can be set/reset/checked via these functions:
* MS_Model_Settings::set_special_view( 'name' );
* MS_Model_Settings::get_special_view();
* MS_Model_Settings::reset_special_view();
*
* @since 1.0.0
*/
protected function check_special_view() {
$view_name = MS_Model_Settings::get_special_view();
if ( ! $view_name ) {
return;
}
$view = MS_Factory::load( $view_name );
if ( $view != null ) {
$view->enqueue_scripts();
// Modify the main menu to handle our special_view for default item.
add_submenu_page(
self::$base_slug,
__( 'Membership 2', 'membership2' ),
__( 'Membership 2', 'membership2' ),
$this->capability,
self::$base_slug,
array( $this, 'handle_special_view' )
);
} else {
MS_Model_Settings::reset_special_view();
return;
}
}
/**
* Function is only called when a special view is defined. This function
* will load that view and display it.
*
* @since 1.0.0
*/
public function handle_special_view() {
$view_name = MS_Model_Settings::get_special_view();
$view = MS_Factory::load( $view_name );
echo $view->to_html();
}
/**
* Returns the WordPress hook that identifies a Membership2 admin page.
*
* Important: In order for this function to work as expected it needs to
* be called *after* the admin-menu was registered!
*
* @param string $subpage
*
* @since 1.0.0
* @return string The internal hook name
*/
public static function admin_page_hook( $subpage = '' ) {
if ( empty( $subpage ) ) {
$plugin_page = self::MENU_SLUG;
} else {
$plugin_page = self::MENU_SLUG . '-' . $subpage;
}
if ( ! function_exists( 'get_plugin_page_hookname' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$the_parent = 'admin.php';
$hook = get_plugin_page_hookname( $plugin_page, $the_parent );
return $hook;
}
/**
* Register scripts and styles
*
* @since 1.0.0
*/
public function wp_loaded() {
if ( is_admin() || is_network_admin() ) {
do_action( 'ms_register_admin_scripts' );
} else {
do_action( 'ms_register_public_scripts' );
}
}
/**
* Adds Dashboard navigation menus.
*
* @since 1.0.0
*/
public function add_menu_pages() {
global $submenu;
$limited_mode = false;
$view = MS_Model_Settings::get_special_view();
if ( $view ) {
// A special view is displayed. Do not display other menu items.
$pages = array();
$limited_mode = true;
} elseif ( MS_Plugin::is_wizard() ) {
// Submenus definition: Wizard mode
$pages = $this->get_setup_menu_pages();
$limited_mode = true;
} else {
// Submenus definition: Normal mode
$pages = $this->get_default_menu_pages();
if ( MS_Plugin::is_network_wide() && ! is_network_admin() ) {
$limited_mode = true;
}
}
/**
* Allow Add-ons and other plugins to add menu pages.
*
* A menu item is defined by an array containing the following members:
* 'title' => '...',
* 'slug' => '...',
* 'function' => callback
*
* @var array
*/
$pages = apply_filters(
'ms_plugin_menu_pages',
$pages,
$limited_mode,
$this
);
$page_keys = array_keys( $pages );
$slug = '';
if ( isset( $page_keys[0] ) && $pages[$page_keys[0]] ) {
$slug = $pages[$page_keys[0]]['slug'];
}
if ( empty( $slug ) ) {
self::$base_slug = self::MENU_SLUG;
} else {
self::$base_slug = self::MENU_SLUG . '-' . $slug;
}
/*
* Create primary menu item: Membership.
*
* The menu title is not translatable because of a bug in WordPress core
* https://core.trac.wordpress.org/ticket/18857
* Until this bug is closed the title (2nd argument) can't be translated
*/
add_menu_page(
__( 'Membership 2', 'membership2' ), // no i18n!
'Membership 2', // no i18n!. Translating menu could affect screen ids
$this->capability,
self::$base_slug,
null,
'dashicons-lock'
);
// Create submenus
foreach ( $pages as $page ) {
if ( ! is_array( $page ) ) {
continue;
}
if ( empty( $page['link'] ) ) {
$menu_link = false;
} else {
$menu_link = $page['link'];
}
$slug = self::MENU_SLUG;
if ( ! empty( $page['slug'] ) ) {
$slug .= '-' . $page['slug'];
}
$page_title = apply_filters( 'ms_admin_submenu_page_title_' . $slug, $page['title'], $slug, self::$base_slug );
$menu_title = apply_filters( 'ms_admin_submenu_menu_title_' . $slug, $page['title'], $slug, self::$base_slug );
$capability = apply_filters( 'ms_admin_submenu_capability_' . $slug, $this->capability, $slug, self::$base_slug );
$submenu_slug = apply_filters( 'ms_admin_submenu_slug_' . $slug, $slug, self::$base_slug );
add_submenu_page(
self::$base_slug,
strip_tags( $page_title ),
$menu_title,
$capability,
$submenu_slug,
array( $this, 'handle_submenu_request' )
);
/*
* WordPress does not support absolute URLs in the admin-menu.
* So we have to manny modify the menu-link href value if our slug
* is an absolute URL.
*/
if ( $menu_link ) {
$item = end( $submenu[self::$base_slug] );
$key = key( $submenu[self::$base_slug] );
$submenu[self::$base_slug][$key][2] = $menu_link;
}
}
do_action( 'ms_controller_plugin_add_menu_pages', $this );
// Setup the rest of the plugin after the menu was registered.
do_action( 'ms_plugin_admin_setup' );
}
/**
* Returns the admin menu items for setting up the plugin.
* Helper function used by add_menu_pages
*
* @since 1.0.0
* @return array
*/
private function get_setup_menu_pages() {
$pages = array(
'setup' => array(
'title' => __( 'Set-up', 'membership2' ),
'slug' => '',
),
);
$step = $this->controllers['membership']->get_step();
if ( MS_Controller_Membership::STEP_ADD_NEW == $step ) {
$pages['setup']['slug'] = 'setup';
$pages[self::MENU_SLUG] = array(
'title' => __( 'Protection Rules', 'membership2' ),
'slug' => '',
);
}
return $pages;
}
/**
* Returns the default admin menu items for Membership2.
* Helper function used by add_menu_pages
*
* @since 1.0.0
* @return array
*/
private function get_default_menu_pages() {
$show_billing = false;
$pages = array(
'memberships' => array(
'title' => __( 'Memberships', 'membership2' ),
'slug' => '',
),
'protected-content' => array(
'title' => __( 'Protection Rules', 'membership2' ),
'slug' => 'protection',
),
'members' => array(
'title' => __( 'All Members', 'membership2' ),
'slug' => 'members',
),
'add-member' => array(
'title' => __( 'Add Member', 'membership2' ),
'slug' => 'add-member',
),
'billing' => false,
'addon' => array(
'title' => __( 'Add-ons', 'membership2' ),
'slug' => 'addon',
),
'settings' => array(
'title' => __( 'Settings', 'membership2' ),
'slug' => 'settings',
),
'help' => array(
'title' => __( 'Help', 'membership2' ),
'slug' => 'help',
),
);
$show_billing = MS_Model_Membership::have_paid_membership();
if ( $show_billing ) {
$bill_count = MS_Model_Invoice::get_unpaid_invoice_count( null, true );
if ( $bill_count > 0 ) {
$msg = '%1$s <span class="update-plugins count-%3$s"><span class="pending-count"><i class="hidden">(</i>%2$s<i class="hidden">)</i></span></span>';
} else {
$msg = '%1$s';
}
$pages['billing'] = array(
'title' => sprintf(
$msg,
__( 'Billing', 'membership2' ),
$bill_count,
sanitize_html_class( $bill_count, '0' )
),
'slug' => 'billing',
);
/*
* This condition checks if the site has configured some payment
* gateways - if not then users cannot sign up for a membership.
* Show a notice if no payment gateway is configured/activated.
*/
$gateways = MS_Model_Gateway::get_gateways( true );
$payment_possible = false;
foreach ( $gateways as $key => $gateway ) {
if ( 'free' == $key ) {
continue;
}
$payment_possible = true;
break;
}
if ( ! $payment_possible ) {
mslib3()->ui->admin_message(
sprintf(
__( 'Oops, looks like you did not activate a payment gateway yet.<br />You need to set up and activate at least one gateway, otherwise your members cannot sign up to a paid membership.<br />%sFix this now »%s', 'membership2' ),
'<a href="' . self::get_admin_url( 'settings', array( 'tab' => MS_Controller_Settings::TAB_PAYMENT ) ) . '">',
'</a>'
),
'err'
);
}
}
return $pages;
}
/**
* Handles all menu-items and calls the correct callback function.
*
* We introduce this routing function to monitor all menu-item calls so we
* can make sure that network-wide protection loads the correct blog or
* admin-area before displaing the page.
*
* This function will only handle submenu items of the Membership2 menu!
*
* @since 1.0.0
*/
public function route_submenu_request() {
global $submenu;
$handler = null;
$handle_it = false;
if ( ! isset( $_GET['page'] ) ) {
return;
}
if ( $_GET['page'] === self::$base_slug ) {
$handle_it = true;
} elseif ( isset( $submenu[self::$base_slug] ) ) {
foreach ( $submenu[self::$base_slug] as $item ) {
if ( $_GET['page'] === $item[2] ) {
$handle_it = true;
break;
}
}
}
if ( ! $handle_it ) {
return;
}
if ( MS_Plugin::is_wizard() ) {
$step_add = MS_Controller_Membership::STEP_ADD_NEW == MS_Plugin::instance()->settings->wizard_step;
if ( ! $step_add || self::is_page( 'setup' ) ) {
$handler = array(
'any',
array( $this->controllers['membership'], 'admin_page_router' ),
);
} else {
$handler = array(
'site',
array( $this->controllers['protection'], 'admin_page' ),
);
}
} else {
if ( self::is_page( '' ) ) {
$handler = array(
'network',
array( $this->controllers['membership'], 'admin_page_router' ),
);
} elseif ( self::is_page( 'protection' ) ) {
$handler = array(
'site',
array( $this->controllers['protection'], 'admin_page' ),
);
} elseif ( self::is_page( 'members' ) ) {
$handler = array(
'network',
array( $this->controllers['member'], 'admin_page' ),
);
} elseif ( self::is_page( 'add-member' ) ) {
$handler = array(
'network',
array( $this->controllers['member'], 'admin_page_editor' ),
);
} elseif ( self::is_page( 'addon' ) ) {
$handler = array(
'network',
array( $this->controllers['addon'], 'admin_page' ),
);
} elseif ( self::is_page( 'settings' ) ) {
$handler = array(
'network',
array( $this->controllers['settings'], 'admin_page' ),
);
} elseif ( self::is_page( 'help' ) ) {
$handler = array(
'any',
array( $this->controllers['help'], 'admin_page' ),
);
} elseif ( self::is_page( 'billing' ) ) {
$handler = array(
'network',
array( $this->controllers['billing'], 'admin_page' ),
);
}
}
/**
* Filter that allows Add-ons to add their own sub-menu handlers.
*
* @since 1.0.0
*/
$handler = apply_filters(
'ms_route_submenu_request',
$handler,
$this
);
// Provide a fallback handler in case we could not identify the handler.
if ( ! $handler ) {
$handler = array(
'network',
array( $this->controllers['membership'], 'membership_admin_page_router' ),
);
}
// Handle the target attribute specified in $handler[0]
if ( MS_Plugin::is_network_wide() && 'any' != $handler[0] ) {
$redirect = false;
$admin_script = 'admin.php?' . $_SERVER['QUERY_STRING'];
if ( 'network' == $handler[0] && ! is_network_admin() ) {
$redirect = network_admin_url( $admin_script );
} elseif ( 'site' == $handler[0] && is_network_admin() ) {
$redirect = admin_url( $admin_script );
}
if ( $redirect ) {
if ( headers_sent() ) {
echo '<script>location.href=' . json_encode( $redirect ) . ';</script>';
} else {
wp_safe_redirect( $redirect );
}
exit;
}
}
$this->menu_handler = $handler;
}
/**
* Add Privacy policy details
*
* @since 1.1.5
*/
public function add_privacy_policy_content() {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}
$content = __( '<h3>Payment Gateways</h3>
<p class="privacy-policy-tutorial">
If you choose to accept Payments using Stripe, or PayPal, some of your customers data will be passed to the respective third party.
Some of the data includes :
<ul>
<li>Name</li>
<li>Email</li>
<li>Address</li>
<li>Phone</li>
<li>City/State/Zip</li>
</ul>
We will store order information for XXX years for tax and accounting purposes. This includes your name, email address and billing addresses.
</p>
<h3>Who on our team has access</h3>
<p class="privacy-policy-tutorial">
Members of our team have access to the information you provide us. Both Administrators and Shop Managers can access:
<ul>
<li>Order information like what was purchased, when it was purchased and</li>
<li>Customer information like your name, email address, and billing information.</li>
</ul>
</p>',
'membership2' );
wp_add_privacy_policy_content(
'Membership 2',
wp_kses_post( wpautop( $content, false ) )
);
}
/**
* Simply calls the menu-handler callback function.
*
* This function was determined by the previous call to
* self::route_submenu_request() during the admin_init hook.
*
* @since 1.0.0
*/
public function handle_submenu_request() {
if ( ! empty( $this->menu_handler ) ) {
// This function will actually render the requested page!
call_user_func( $this->menu_handler[1] );
}
}
/**
* Checks if the current user is on the specified Membership2 admin page.
*
* @param string $slug The membership2 slug (without the menu-slug prefix)
*
* @since 1.0.0
* @return bool
*/
public static function is_page( $slug ) {
$curpage = false;
if ( isset( $_REQUEST['page'] ) ) {
$curpage = sanitize_html_class( $_REQUEST['page'] );
}
if ( empty( $slug ) ) {
$slug = self::$base_slug;
} else {
$slug = self::MENU_SLUG . '-' . $slug;
}
return $curpage == $slug;
}
/**
* Checks if the current user is on any Membership2 admin page.
*
* @since 1.0.0
* @return bool
*/
public static function is_admin_page() {
$curpage = false;
if ( isset( $_REQUEST['page'] ) ) {
$curpage = sanitize_html_class( $_REQUEST['page'] );
}
$slug = self::$base_slug;
return ( strpos( $curpage, $slug ) !== false );
}
/**
* Get admin url.
*
* @param string $slug Optional. Slug of the admin page, if empty the link
* points to the main admin page.
*
* @since 1.0.0
* @return string The full URL to the admin page.
*/
public static function get_admin_url( $slug = '', $args = null ) {
$base_slug = self::$base_slug;
// These slugs are opened in network-admin for network-wide protection.
$global_slugs = array(
'memberships',
'addon',
'settings',
);
// Determine if the slug is opened in network-admin or site admin.
$network_slug = MS_Plugin::is_network_wide()
&& ( in_array( $slug, $global_slugs ) || is_network_admin() );
if ( $network_slug ) {
$base_slug = self::MENU_SLUG;
if ( 'memberships' === $slug ) {
$slug = '';
}
}
if ( 'MENU_SLUG' == $slug ) {
$slug = self::MENU_SLUG;
} elseif ( empty( $slug ) ) {
$slug = self::$base_slug;
} else {
$slug = self::MENU_SLUG . '-' . $slug;
}
if ( ! $slug ) {
$slug = self::MENU_SLUG;
}
if ( $network_slug ) {
$url = network_admin_url( 'admin.php?page=' . $slug );
} else {
$url = admin_url( 'admin.php?page=' . $slug );
}
if ( $args ) {
$url = esc_url_raw( add_query_arg( $args, $url ) );
}
return apply_filters(
'ms_controller_plugin_get_admin_url',
$url
);
}
/**
* Get admin settings url.
*
* @since 1.0.0
*
*/
public static function get_admin_settings_url() {
return apply_filters(
'ms_controller_plugin_get_admin_url',
admin_url( 'admin.php?page=' . self::MENU_SLUG . '-settings' )
);
}
/**
* Use a special template for our custom post types.
*
* Invoices:
* Replaces the themes "Single" template with our invoice template when an
* invoice is displayed. The theme can override this by defining its own
* m2-invoice.php / single-ms_invoice.php template.
*
* You can even specifiy a membership ID in the page template to create
* a custom invoice form based on the membership that is billed.
* Example:
* m2-invoice-100.php (Invoice form for membership 100)
*
* @param string $template The template path to filter.
*
* @since 1.0.0
* @see filter single_template
*
* @return string The template path.
*/
public function custom_single_template( $default_template ) {
global $post;
$template = '';
// Checks for invoice single template.
if ( $post->post_type == MS_Model_Invoice::get_post_type() ) {
$invoice = MS_Factory::load( 'MS_Model_Invoice', $post->ID );
// First look for themes 'm2-invoice-100.php' template (membership ID).
$template = get_query_template(
'm2',
'm2-invoice-' . $invoice->membership_id . '.php'
);
// Fallback to themes 'm2-invoice.php' template.
if ( ! $template ) {
$template = get_query_template(
'm2',
'm2-invoice.php'
);
}
// Second look for themes 'single-ms_invoice.php' template.
if ( ! $template && strpos( $default_template, '/single-ms_invoice.php' ) ) {
$template = $default_template;
}
// Last: Use the default M2 invoice template.
if ( ! $template ) {
$invoice_template = apply_filters(
'ms_controller_plugin_invoice_template',
MS_Plugin::instance()->dir . 'app/template/single-ms_invoice.php'
);
if ( file_exists( $invoice_template ) ) {
$template = $invoice_template;
}
}
}
if ( ! $template ) {
$template = $default_template;
}
return $template;
}
/**
* Use a special template for our membership pages.
*
* Recognized templates are:
* m2-memberships.php
* m2-protected-content.php
* m2-account.php
* m2-register.php
* m2-registration-complete.php
*
* Note that certain pages receive a membership-ID when they are loaded
* (like the m2-registration-complete or m2-register pages).
* You can even specify special pages for each membership.
*
* Example:
* m2-register-100.php (register form for membership 100)
* m2-registration-complete-100.php (thank you page for membership 100)
*
* @param string $template The default template path to filter.
*
* @since 1.0.1.0
* @see filter page_template
*
* @return string The custom template path.
*/
public function custom_page_template( $default_template ) {
$template = '';
// Checks for invoice single template.
if ( $type = MS_Model_Pages::is_membership_page() ) {
$membership_id = apply_filters(
'ms_detect_membership_id',
0,
true,
true
);
if ( $membership_id ) {
$template = get_query_template(
'm2',
array('m2-' . $type . '-' . $membership_id . '.php')
);
}
if ( ! $template ) {
$template = get_query_template(
'm2',
array('m2-' . $type . '.php')
);
}
}
if ( ! $template ) {
$template = $default_template;
}
return $template;
}
/**
* Returns information on current memberships and access to current page.
*