@@ -8,138 +8,138 @@ |
||
8 | 8 | */ |
9 | 9 | class Plans { |
10 | 10 | |
11 | - /** |
|
12 | - * Holds class instance |
|
13 | - * |
|
14 | - * @since 1.0.0 |
|
15 | - * |
|
16 | - * @var object \lsx_health_plan\classes\integrations\woocommerce\Plans() |
|
17 | - */ |
|
18 | - protected static $instance = null; |
|
11 | + /** |
|
12 | + * Holds class instance |
|
13 | + * |
|
14 | + * @since 1.0.0 |
|
15 | + * |
|
16 | + * @var object \lsx_health_plan\classes\integrations\woocommerce\Plans() |
|
17 | + */ |
|
18 | + protected static $instance = null; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Holds the current screen var if it is active. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - public $screen = ''; |
|
20 | + /** |
|
21 | + * Holds the current screen var if it is active. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + public $screen = ''; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Holds the current array of product IDS. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - public $product_ids = array(); |
|
27 | + /** |
|
28 | + * Holds the current array of product IDS. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + public $product_ids = array(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Holds the curret parent ID. |
|
36 | - * |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - public $parent_id = 0; |
|
34 | + /** |
|
35 | + * Holds the curret parent ID. |
|
36 | + * |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + public $parent_id = 0; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor |
|
43 | - */ |
|
44 | - public function __construct() { |
|
45 | - // Remove the default restrictions, as we will add our own. |
|
46 | - add_action( 'wp', array( $this, 'set_screen' ), 1 ); |
|
47 | - add_action( 'wp', array( $this, 'disable_parent_plan_restrictions' ), 2 ); |
|
48 | - add_action( 'wp', array( $this, 'child_plan_redirect_restrictions' ), 2 ); |
|
41 | + /** |
|
42 | + * Constructor |
|
43 | + */ |
|
44 | + public function __construct() { |
|
45 | + // Remove the default restrictions, as we will add our own. |
|
46 | + add_action( 'wp', array( $this, 'set_screen' ), 1 ); |
|
47 | + add_action( 'wp', array( $this, 'disable_parent_plan_restrictions' ), 2 ); |
|
48 | + add_action( 'wp', array( $this, 'child_plan_redirect_restrictions' ), 2 ); |
|
49 | 49 | |
50 | - // Initiate the WP Head functions. |
|
51 | - add_action( 'wp_head', array( $this, 'set_screen' ) ); |
|
52 | - add_action( 'lsx_content_top', 'lsx_hp_single_plan_products' ); |
|
50 | + // Initiate the WP Head functions. |
|
51 | + add_action( 'wp_head', array( $this, 'set_screen' ) ); |
|
52 | + add_action( 'lsx_content_top', 'lsx_hp_single_plan_products' ); |
|
53 | 53 | |
54 | - // Plan Archive Actions. |
|
55 | - add_action( 'lsx_entry_before', array( $this, 'set_product_ids' ) ); |
|
56 | - } |
|
54 | + // Plan Archive Actions. |
|
55 | + add_action( 'lsx_entry_before', array( $this, 'set_product_ids' ) ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Return an instance of this class. |
|
60 | - * |
|
61 | - * @since 1.0.0 |
|
62 | - * |
|
63 | - * @return object \lsx_health_plan\classes\integrations\woocommerce\Plans() A single instance of this class. |
|
64 | - */ |
|
65 | - public static function get_instance() { |
|
66 | - // If the single instance hasn't been set, set it now. |
|
67 | - if ( null === self::$instance ) { |
|
68 | - self::$instance = new self(); |
|
69 | - } |
|
70 | - return self::$instance; |
|
71 | - } |
|
58 | + /** |
|
59 | + * Return an instance of this class. |
|
60 | + * |
|
61 | + * @since 1.0.0 |
|
62 | + * |
|
63 | + * @return object \lsx_health_plan\classes\integrations\woocommerce\Plans() A single instance of this class. |
|
64 | + */ |
|
65 | + public static function get_instance() { |
|
66 | + // If the single instance hasn't been set, set it now. |
|
67 | + if ( null === self::$instance ) { |
|
68 | + self::$instance = new self(); |
|
69 | + } |
|
70 | + return self::$instance; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Define the product metabox on the plan post type |
|
75 | - */ |
|
76 | - public function set_screen() { |
|
77 | - if ( is_singular( 'plan' ) ) { |
|
78 | - $section = get_query_var( 'section' ); |
|
79 | - if ( ! empty( $section ) ) { |
|
80 | - $this->screen = 'child_plan'; |
|
81 | - } else { |
|
82 | - $this->screen = 'parent_plan'; |
|
83 | - } |
|
84 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
85 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
86 | - $this->product_ids = $product_ids; |
|
87 | - } |
|
88 | - } |
|
89 | - if ( is_post_type_archive( 'plan' ) ) { |
|
90 | - $this->screen = 'plan_archive'; |
|
91 | - } |
|
92 | - } |
|
73 | + /** |
|
74 | + * Define the product metabox on the plan post type |
|
75 | + */ |
|
76 | + public function set_screen() { |
|
77 | + if ( is_singular( 'plan' ) ) { |
|
78 | + $section = get_query_var( 'section' ); |
|
79 | + if ( ! empty( $section ) ) { |
|
80 | + $this->screen = 'child_plan'; |
|
81 | + } else { |
|
82 | + $this->screen = 'parent_plan'; |
|
83 | + } |
|
84 | + $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
85 | + if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
86 | + $this->product_ids = $product_ids; |
|
87 | + } |
|
88 | + } |
|
89 | + if ( is_post_type_archive( 'plan' ) ) { |
|
90 | + $this->screen = 'plan_archive'; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Sets the post type archive product ids. |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function set_product_ids() { |
|
100 | - $this->product_ids = false; |
|
101 | - if ( 'plan' === get_post_type() ) { |
|
102 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
103 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
104 | - $this->product_ids = $product_ids; |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
94 | + /** |
|
95 | + * Sets the post type archive product ids. |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function set_product_ids() { |
|
100 | + $this->product_ids = false; |
|
101 | + if ( 'plan' === get_post_type() ) { |
|
102 | + $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
103 | + if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
104 | + $this->product_ids = $product_ids; |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
111 | - * restriction functionality elsewhere. |
|
112 | - */ |
|
113 | - public function disable_parent_plan_restrictions() { |
|
114 | - if ( '' === $this->screen || ! function_exists( 'wc_memberships' ) ) { |
|
115 | - return; |
|
116 | - } |
|
109 | + /** |
|
110 | + * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
111 | + * restriction functionality elsewhere. |
|
112 | + */ |
|
113 | + public function disable_parent_plan_restrictions() { |
|
114 | + if ( '' === $this->screen || ! function_exists( 'wc_memberships' ) ) { |
|
115 | + return; |
|
116 | + } |
|
117 | 117 | |
118 | - $restrictions = wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(); |
|
119 | - remove_action( 'wp', array( $restrictions, 'handle_restriction_modes' ) ); |
|
120 | - } |
|
118 | + $restrictions = wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(); |
|
119 | + remove_action( 'wp', array( $restrictions, 'handle_restriction_modes' ) ); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
124 | - * restriction functionality elsewhere. |
|
125 | - */ |
|
126 | - public function child_plan_redirect_restrictions() { |
|
127 | - if ( ! function_exists( 'wc_memberships' ) || ! is_singular( 'plan' ) || 'child_plan' !== $this->screen || ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) { |
|
128 | - return; |
|
129 | - } |
|
130 | - $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
131 | - if ( true === $restricted ) { |
|
132 | - wp_redirect( get_permalink( get_the_ID() ) ); |
|
133 | - exit; |
|
134 | - } |
|
135 | - } |
|
122 | + /** |
|
123 | + * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
124 | + * restriction functionality elsewhere. |
|
125 | + */ |
|
126 | + public function child_plan_redirect_restrictions() { |
|
127 | + if ( ! function_exists( 'wc_memberships' ) || ! is_singular( 'plan' ) || 'child_plan' !== $this->screen || ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) { |
|
128 | + return; |
|
129 | + } |
|
130 | + $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
131 | + if ( true === $restricted ) { |
|
132 | + wp_redirect( get_permalink( get_the_ID() ) ); |
|
133 | + exit; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Returns the ids of the attached products. |
|
139 | - * |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function get_products() { |
|
143 | - return $this->product_ids; |
|
144 | - } |
|
137 | + /** |
|
138 | + * Returns the ids of the attached products. |
|
139 | + * |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function get_products() { |
|
143 | + return $this->product_ids; |
|
144 | + } |
|
145 | 145 | } |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function __construct() { |
45 | 45 | // Remove the default restrictions, as we will add our own. |
46 | - add_action( 'wp', array( $this, 'set_screen' ), 1 ); |
|
47 | - add_action( 'wp', array( $this, 'disable_parent_plan_restrictions' ), 2 ); |
|
48 | - add_action( 'wp', array( $this, 'child_plan_redirect_restrictions' ), 2 ); |
|
46 | + add_action('wp', array($this, 'set_screen'), 1); |
|
47 | + add_action('wp', array($this, 'disable_parent_plan_restrictions'), 2); |
|
48 | + add_action('wp', array($this, 'child_plan_redirect_restrictions'), 2); |
|
49 | 49 | |
50 | 50 | // Initiate the WP Head functions. |
51 | - add_action( 'wp_head', array( $this, 'set_screen' ) ); |
|
52 | - add_action( 'lsx_content_top', 'lsx_hp_single_plan_products' ); |
|
51 | + add_action('wp_head', array($this, 'set_screen')); |
|
52 | + add_action('lsx_content_top', 'lsx_hp_single_plan_products'); |
|
53 | 53 | |
54 | 54 | // Plan Archive Actions. |
55 | - add_action( 'lsx_entry_before', array( $this, 'set_product_ids' ) ); |
|
55 | + add_action('lsx_entry_before', array($this, 'set_product_ids')); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public static function get_instance() { |
66 | 66 | // If the single instance hasn't been set, set it now. |
67 | - if ( null === self::$instance ) { |
|
67 | + if (null === self::$instance) { |
|
68 | 68 | self::$instance = new self(); |
69 | 69 | } |
70 | 70 | return self::$instance; |
@@ -74,19 +74,19 @@ discard block |
||
74 | 74 | * Define the product metabox on the plan post type |
75 | 75 | */ |
76 | 76 | public function set_screen() { |
77 | - if ( is_singular( 'plan' ) ) { |
|
78 | - $section = get_query_var( 'section' ); |
|
79 | - if ( ! empty( $section ) ) { |
|
77 | + if (is_singular('plan')) { |
|
78 | + $section = get_query_var('section'); |
|
79 | + if ( ! empty($section)) { |
|
80 | 80 | $this->screen = 'child_plan'; |
81 | 81 | } else { |
82 | 82 | $this->screen = 'parent_plan'; |
83 | 83 | } |
84 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
85 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
84 | + $product_ids = get_post_meta(get_the_ID(), 'plan_product', true); |
|
85 | + if (false !== $product_ids && ! empty($product_ids)) { |
|
86 | 86 | $this->product_ids = $product_ids; |
87 | 87 | } |
88 | 88 | } |
89 | - if ( is_post_type_archive( 'plan' ) ) { |
|
89 | + if (is_post_type_archive('plan')) { |
|
90 | 90 | $this->screen = 'plan_archive'; |
91 | 91 | } |
92 | 92 | } |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function set_product_ids() { |
100 | 100 | $this->product_ids = false; |
101 | - if ( 'plan' === get_post_type() ) { |
|
102 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
103 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
101 | + if ('plan' === get_post_type()) { |
|
102 | + $product_ids = get_post_meta(get_the_ID(), 'plan_product', true); |
|
103 | + if (false !== $product_ids && ! empty($product_ids)) { |
|
104 | 104 | $this->product_ids = $product_ids; |
105 | 105 | } |
106 | 106 | } |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | * restriction functionality elsewhere. |
112 | 112 | */ |
113 | 113 | public function disable_parent_plan_restrictions() { |
114 | - if ( '' === $this->screen || ! function_exists( 'wc_memberships' ) ) { |
|
114 | + if ('' === $this->screen || ! function_exists('wc_memberships')) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | 118 | $restrictions = wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(); |
119 | - remove_action( 'wp', array( $restrictions, 'handle_restriction_modes' ) ); |
|
119 | + remove_action('wp', array($restrictions, 'handle_restriction_modes')); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | * restriction functionality elsewhere. |
125 | 125 | */ |
126 | 126 | public function child_plan_redirect_restrictions() { |
127 | - if ( ! function_exists( 'wc_memberships' ) || ! is_singular( 'plan' ) || 'child_plan' !== $this->screen || ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) { |
|
127 | + if ( ! function_exists('wc_memberships') || ! is_singular('plan') || 'child_plan' !== $this->screen || ! function_exists('wc_memberships_is_post_content_restricted')) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | - $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
131 | - if ( true === $restricted ) { |
|
132 | - wp_redirect( get_permalink( get_the_ID() ) ); |
|
130 | + $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can('wc_memberships_view_restricted_post_content', get_the_ID()); |
|
131 | + if (true === $restricted) { |
|
132 | + wp_redirect(get_permalink(get_the_ID())); |
|
133 | 133 | exit; |
134 | 134 | } |
135 | 135 | } |