|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* LSX Health Plan Conditional Helpers. |
|
4
|
|
|
* |
|
5
|
|
|
* @package lsx-health-plan |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Checks if the current post or supplied $post_ID has a workout attached. |
|
10
|
|
|
* |
|
11
|
|
|
* @param string $post_id |
|
12
|
|
|
* @return boolean |
|
13
|
|
|
*/ |
|
14
|
|
|
function lsx_health_plan_has_warmup( $post_id = '' ) { |
|
15
|
|
|
if ( '' === $post_id ) { |
|
16
|
|
|
$post_id = get_the_ID(); |
|
17
|
|
|
} |
|
18
|
|
|
return \lsx_health_plan\functions\has_attached_post( $post_id, 'plan_warmup' ); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Checks if the current post or supplied $post_ID has a workout attached. |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $post_id |
|
25
|
|
|
* @return boolean |
|
26
|
|
|
*/ |
|
27
|
|
|
function lsx_health_plan_has_workout( $post_id = '' ) { |
|
28
|
|
|
if ( ! post_type_exists( 'workout' ) ) { |
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
if ( '' === $post_id ) { |
|
32
|
|
|
$post_id = get_the_ID(); |
|
33
|
|
|
} |
|
34
|
|
|
return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_workouts' ); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Checks if the current post or supplied $post_ID has a meal attached. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $post_id |
|
41
|
|
|
* @return boolean |
|
42
|
|
|
*/ |
|
43
|
|
|
function lsx_health_plan_has_meal( $post_id = '' ) { |
|
44
|
|
|
if ( ! post_type_exists( 'meal' ) ) { |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
if ( '' === $post_id ) { |
|
48
|
|
|
$post_id = get_the_ID(); |
|
49
|
|
|
} |
|
50
|
|
|
return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_meals' ); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Checks if the current post or supplied $post_ID has a recipes attached. |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $post_id |
|
57
|
|
|
* @return boolean |
|
58
|
|
|
*/ |
|
59
|
|
|
function lsx_health_plan_has_recipe( $post_id = '' ) { |
|
60
|
|
|
if ( ! post_type_exists( 'recipe' ) ) { |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
if ( '' === $post_id ) { |
|
64
|
|
|
$post_id = get_the_ID(); |
|
65
|
|
|
} |
|
66
|
|
|
return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_recipes' ); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Checks if the current post or supplied $post_ID has a downloads attached. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $post_id |
|
73
|
|
|
* @return boolean |
|
74
|
|
|
*/ |
|
75
|
|
|
function lsx_health_plan_has_downloads( $post_id = '' ) { |
|
76
|
|
|
$has_downloads = false; |
|
77
|
|
|
if ( '' === $post_id ) { |
|
78
|
|
|
$post_id = get_the_ID(); |
|
79
|
|
|
} |
|
80
|
|
|
$downloads = \lsx_health_plan\functions\get_downloads( 'all', $post_id ); |
|
|
|
|
|
|
81
|
|
|
if ( ! empty( $downloads ) ) { |
|
82
|
|
|
$has_downloads = true; |
|
83
|
|
|
} |
|
84
|
|
|
return $has_downloads; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Checks if the current post or supplied $post_ID has a tips attached. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $post_id |
|
91
|
|
|
* @return boolean |
|
92
|
|
|
*/ |
|
93
|
|
|
function lsx_health_plan_has_tip( $post_id = '' ) { |
|
94
|
|
|
if ( ! post_type_exists( 'tip' ) ) { |
|
95
|
|
|
return false; |
|
96
|
|
|
} |
|
97
|
|
|
if ( '' === $post_id ) { |
|
98
|
|
|
$post_id = get_the_ID(); |
|
99
|
|
|
} |
|
100
|
|
|
return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_tips' ); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Checks if the current post or supplied $post_ID has a video attached. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $post_id |
|
107
|
|
|
* @return boolean |
|
108
|
|
|
*/ |
|
109
|
|
|
function lsx_health_plan_has_video( $post_id = '' ) { |
|
110
|
|
|
if ( ! post_type_exists( 'video' ) ) { |
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
if ( '' === $post_id ) { |
|
114
|
|
|
$post_id = get_the_ID(); |
|
115
|
|
|
} |
|
116
|
|
|
return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_videos' ); |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Checks to see if the current user has a valid purchase. |
|
121
|
|
|
* |
|
122
|
|
|
* @return boolean |
|
123
|
|
|
*/ |
|
124
|
|
|
function lsx_health_plan_user_has_purchase() { |
|
125
|
|
|
$valid_order = false; |
|
126
|
|
|
$product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
127
|
|
|
|
|
128
|
|
|
if ( is_user_logged_in() && false !== $product_id ) { |
|
129
|
|
|
$current_user = wp_get_current_user(); |
|
130
|
|
|
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) { |
|
|
|
|
|
|
131
|
|
|
$valid_order = true; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
return $valid_order; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Checks if the current post or supplied $post_ID has a tips attached. |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $post_id |
|
141
|
|
|
* @return boolean |
|
142
|
|
|
*/ |
|
143
|
|
|
function lsx_health_plan_is_current_tab( $needle = '' ) { |
|
144
|
|
|
$is_tab = false; |
|
145
|
|
|
$plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
146
|
|
|
if ( false === $plan_slug ) { |
|
147
|
|
|
$plan_slug = 'my-plan'; |
|
148
|
|
|
} |
|
149
|
|
|
if ( is_singular( 'plan' ) || is_page( $plan_slug ) ) { |
|
150
|
|
|
$endpoint = get_query_var( 'endpoint' ); |
|
151
|
|
|
if ( false !== $endpoint && $needle === $endpoint ) { |
|
152
|
|
|
$is_tab = true; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
return $is_tab; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Checks to see if the current day is complete or not |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $post_id |
|
162
|
|
|
* @return boolean |
|
163
|
|
|
*/ |
|
164
|
|
|
function lsx_health_plan_is_day_complete( $post_id = '', $section_key = '' ) { |
|
165
|
|
|
$is_complete = false; |
|
166
|
|
|
if ( '' === $post_id ) { |
|
167
|
|
|
$post_id = get_the_ID(); |
|
168
|
|
|
} |
|
169
|
|
|
$key = \lsx_health_plan\functions\plan\generate_section_id( $section_key ); |
|
170
|
|
|
$is_day_complete = get_user_meta( get_current_user_id(), 'day_' . $key . '_complete', true ); |
|
171
|
|
|
if ( false !== $is_day_complete && '' !== $is_day_complete ) { |
|
172
|
|
|
$is_complete = true; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
return $is_complete; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
function lsx_health_plan_is_plan_complete() { |
|
179
|
|
|
$complete = false; |
|
180
|
|
|
return $complete; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Checks if the current week has any downloads attached. |
|
185
|
|
|
* |
|
186
|
|
|
* @param string $week The week name 'week-1'. |
|
187
|
|
|
* @return boolean |
|
188
|
|
|
*/ |
|
189
|
|
|
function lsx_health_plan_week_has_downloads( $week = '' ) { |
|
190
|
|
|
$has_downloads = false; |
|
191
|
|
|
if ( '' !== $week ) { |
|
192
|
|
|
$downloads = \lsx_health_plan\functions\get_weekly_downloads( $week ); |
|
193
|
|
|
if ( ! empty( $downloads ) ) { |
|
194
|
|
|
$has_downloads = true; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
return $has_downloads; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Checks to see if the current ID has any tips attached. |
|
202
|
|
|
* |
|
203
|
|
|
* @param string $post_id |
|
204
|
|
|
* @return boolean |
|
205
|
|
|
*/ |
|
206
|
|
|
function lsx_health_plan_has_tips( $post_id = '' ) { |
|
207
|
|
|
$has_tips = false; |
|
208
|
|
|
if ( '' === $post_id ) { |
|
209
|
|
|
$post_id = get_the_ID(); |
|
210
|
|
|
} |
|
211
|
|
|
$connected_tips = get_post_meta( get_the_ID(), 'connected_tips', true ); |
|
|
|
|
|
|
212
|
|
|
$connected_tips = \lsx_health_plan\functions\check_posts_exist( $connected_tips ); |
|
|
|
|
|
|
213
|
|
|
if ( ! empty( $connected_tips ) ) { |
|
214
|
|
|
$has_tips = true; |
|
215
|
|
|
} |
|
216
|
|
|
return $has_tips; |
|
217
|
|
|
} |
|
218
|
|
|
|