|
1
|
|
|
<?php |
|
2
|
|
|
namespace lsx_health_plan\classes; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* LSX Health Plan Frontend Class. |
|
6
|
|
|
* |
|
7
|
|
|
* @package lsx-health-plan |
|
8
|
|
|
*/ |
|
9
|
|
|
class Frontend { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Holds class instance |
|
13
|
|
|
* |
|
14
|
|
|
* @since 1.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @var object \lsx_health_plan\classes\Frontend() |
|
17
|
|
|
*/ |
|
18
|
|
|
protected static $instance = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var object \lsx_health_plan\classes\frontend\Endpoints(); |
|
22
|
|
|
*/ |
|
23
|
|
|
public $endpoints; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var object \lsx_health_plan\classes\frontend\Gallery(); |
|
27
|
|
|
*/ |
|
28
|
|
|
public $gallery; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var object \lsx_health_plan\classes\frontend\Plan_Status(); |
|
32
|
|
|
*/ |
|
33
|
|
|
public $plan_status; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var object \lsx_health_plan\classes\frontend\General(); |
|
37
|
|
|
*/ |
|
38
|
|
|
public $general; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var object \lsx_health_plan\classes\frontend\Template_Redirects(); |
|
42
|
|
|
*/ |
|
43
|
|
|
public $template_redirects; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Contructor |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct() { |
|
49
|
|
|
if ( ! is_admin() ) { |
|
50
|
|
|
$this->load_classes(); |
|
51
|
|
|
add_action( 'template_redirect', array( $this, 'redirect' ) ); |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Return an instance of this class. |
|
58
|
|
|
* |
|
59
|
|
|
* @since 1.0.0 |
|
60
|
|
|
* |
|
61
|
|
|
* @return object \lsx_health_plan\classes\Frontend() A single instance of this class. |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function get_instance() { |
|
64
|
|
|
// If the single instance hasn't been set, set it now. |
|
65
|
|
|
if ( null === self::$instance ) { |
|
66
|
|
|
self::$instance = new self(); |
|
67
|
|
|
} |
|
68
|
|
|
return self::$instance; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Loads the variable classes and the static classes. |
|
73
|
|
|
*/ |
|
74
|
|
|
private function load_classes() { |
|
75
|
|
|
require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-endpoints.php'; |
|
76
|
|
|
$this->endpoints = frontend\Endpoints::get_instance(); |
|
77
|
|
|
|
|
78
|
|
|
require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-modals.php'; |
|
79
|
|
|
$this->modals = Modals::get_instance(); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-gallery.php'; |
|
82
|
|
|
$this->gallery = frontend\Gallery::get_instance(); |
|
83
|
|
|
|
|
84
|
|
|
require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-plan-status.php'; |
|
85
|
|
|
$this->plan_status = frontend\Plan_Status::get_instance(); |
|
86
|
|
|
|
|
87
|
|
|
require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-general.php'; |
|
88
|
|
|
$this->general = frontend\General::get_instance(); |
|
89
|
|
|
|
|
90
|
|
|
require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-template-redirects.php'; |
|
91
|
|
|
$this->template_redirects = frontend\Template_Redirects::get_instance(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Redirect the user from the cart or checkout page if they have purchased the product already. |
|
96
|
|
|
* |
|
97
|
|
|
* @return void |
|
98
|
|
|
*/ |
|
99
|
|
|
public function redirect() { |
|
100
|
|
|
if ( ! is_user_logged_in() || ! function_exists( 'wc_get_page_id' ) || is_home() ) { |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
if ( lsx_health_plan_user_has_purchase() && ( is_page( wc_get_page_id( 'cart' ) ) || is_page( wc_get_page_id( 'checkout' ) ) ) ) { |
|
104
|
|
|
wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
|
|
|
|
|
105
|
|
|
die; |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
109
|
|
|
if ( false !== $product_id && is_single( $product_id ) ) { |
|
110
|
|
|
wp_redirect( home_url() ); |
|
111
|
|
|
die; |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|