lightspeeddevelopment /
lsx-health-plan
| 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 |
||||
|
0 ignored issues
–
show
Coding Style
Documentation
introduced
by
Loading history...
|
|||||
| 12 | * @return boolean |
||||
| 13 | */ |
||||
| 14 | function lsx_health_plan_has_warmup( $post_id = '' ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 15 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | $post_id = get_the_ID(); |
||||
| 17 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 18 | return \lsx_health_plan\functions\has_attached_post( $post_id, 'plan_warmup' ); |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 19 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * Checks if the current post or supplied $post_ID has a workout attached. |
||||
| 23 | * |
||||
| 24 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 25 | * @return boolean |
||||
| 26 | */ |
||||
| 27 | function lsx_health_plan_has_workout( $post_id = '' ) { |
||||
| 28 | if ( ! post_type_exists( 'workout' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 29 | return false; |
||||
| 30 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 31 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 32 | $post_id = get_the_ID(); |
||||
| 33 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 34 | $has_workouts = false; |
||||
| 35 | |||||
| 36 | $section_key = get_query_var( 'section', false ); |
||||
| 37 | if ( false !== $section_key ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 38 | $section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key ); |
||||
| 39 | if ( isset( $section_info['connected_workouts'] ) && ! empty( $section_info['connected_workouts'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 40 | $has_workouts = true; |
||||
| 41 | } |
||||
| 42 | } elseif ( \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_workouts' ) ) { |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 43 | $has_workouts = true; |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | return $has_workouts; |
||||
| 47 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Checks if the current post or supplied $post_ID has a meal attached. |
||||
| 51 | * |
||||
| 52 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 53 | * @return boolean |
||||
| 54 | */ |
||||
| 55 | function lsx_health_plan_has_meal( $post_id = '' ) { |
||||
| 56 | if ( ! post_type_exists( 'meal' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 57 | return false; |
||||
| 58 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 59 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 60 | $post_id = get_the_ID(); |
||||
| 61 | } |
||||
| 62 | |||||
| 63 | return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_meals' ); |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 64 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 65 | |||||
| 66 | /** |
||||
| 67 | * Checks if the current post or supplied $post_ID has a recipes attached. |
||||
| 68 | * |
||||
| 69 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 70 | * @return boolean |
||||
| 71 | */ |
||||
| 72 | function lsx_health_plan_has_recipe( $post_id = '' ) { |
||||
| 73 | if ( ! post_type_exists( 'recipe' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 74 | return false; |
||||
| 75 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 76 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 77 | $post_id = get_the_ID(); |
||||
| 78 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 79 | return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_recipes' ); |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 80 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 81 | |||||
| 82 | /** |
||||
| 83 | * Checks if the current post or supplied $post_ID has a downloads attached. |
||||
| 84 | * |
||||
| 85 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 86 | * @return boolean |
||||
| 87 | */ |
||||
| 88 | function lsx_health_plan_has_downloads( $post_id = '' ) { |
||||
| 89 | $has_downloads = false; |
||||
| 90 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 91 | $post_id = get_the_ID(); |
||||
| 92 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 93 | $downloads = \lsx_health_plan\functions\get_downloads( 'all', $post_id ); |
||||
| 94 | if ( ! empty( $downloads ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 95 | $has_downloads = true; |
||||
| 96 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 97 | return $has_downloads; |
||||
| 98 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 99 | |||||
| 100 | /** |
||||
| 101 | * Checks if the current post or supplied $post_ID has a tips attached. |
||||
| 102 | * |
||||
| 103 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 104 | * @return boolean |
||||
| 105 | */ |
||||
| 106 | function lsx_health_plan_has_tip( $post_id = '' ) { |
||||
| 107 | if ( ! post_type_exists( 'tip' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 108 | return false; |
||||
| 109 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 110 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 111 | $post_id = get_the_ID(); |
||||
| 112 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 113 | return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_tips' ); |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 114 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 115 | |||||
| 116 | /** |
||||
| 117 | * Checks if the current post or supplied $post_ID has a video attached. |
||||
| 118 | * |
||||
| 119 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 120 | * @return boolean |
||||
| 121 | */ |
||||
| 122 | function lsx_health_plan_has_video( $post_id = '' ) { |
||||
| 123 | if ( ! post_type_exists( 'video' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 124 | return false; |
||||
| 125 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 126 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 127 | $post_id = get_the_ID(); |
||||
| 128 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 129 | return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_videos' ); |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false; however, parameter $post_id of lsx_health_plan\functions\has_attached_post() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 130 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 131 | |||||
| 132 | /** |
||||
| 133 | * Checks to see if the current user has a valid purchase. |
||||
| 134 | * |
||||
| 135 | * @return boolean |
||||
| 136 | */ |
||||
| 137 | function lsx_health_plan_user_has_purchase() { |
||||
| 138 | $valid_order = false; |
||||
| 139 | return $valid_order; |
||||
| 140 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 141 | |||||
| 142 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 143 | * Checks if the current post or supplied $post_ID has a tips attached. |
||||
| 144 | * |
||||
| 145 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 146 | * @return boolean |
||||
| 147 | */ |
||||
| 148 | function lsx_health_plan_is_current_tab( $needle = '' ) { |
||||
| 149 | $is_tab = false; |
||||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 150 | $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
||||
| 151 | if ( false === $plan_slug ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 152 | $plan_slug = 'my-plan'; |
||||
| 153 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 154 | if ( is_singular( 'plan' ) || is_page( $plan_slug ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 155 | $endpoint = get_query_var( 'endpoint' ); |
||||
| 156 | if ( false !== $endpoint && $needle === $endpoint ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 157 | $is_tab = true; |
||||
| 158 | } |
||||
| 159 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 160 | return $is_tab; |
||||
| 161 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 162 | |||||
| 163 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 164 | * Checks to see if the current day is complete or not |
||||
| 165 | * |
||||
| 166 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 167 | * @return boolean |
||||
| 168 | */ |
||||
| 169 | function lsx_health_plan_is_day_complete( $post_id = '', $section_key = '' ) { |
||||
| 170 | $is_complete = false; |
||||
| 171 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 172 | $post_id = get_the_ID(); |
||||
| 173 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 174 | $key = \lsx_health_plan\functions\plan\generate_section_id( $section_key ); |
||||
| 175 | $is_day_complete = get_user_meta( get_current_user_id(), 'day_' . $key . '_complete', true ); |
||||
| 176 | if ( false !== $is_day_complete && '' !== $is_day_complete ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 177 | $is_complete = true; |
||||
| 178 | } |
||||
| 179 | |||||
| 180 | return $is_complete; |
||||
| 181 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 182 | |||||
| 183 | function lsx_health_plan_is_plan_complete() { |
||||
|
0 ignored issues
–
show
|
|||||
| 184 | $complete = false; |
||||
| 185 | return $complete; |
||||
| 186 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 187 | |||||
| 188 | /** |
||||
| 189 | * Checks if the current week has any downloads attached. |
||||
| 190 | * |
||||
| 191 | * @param string $week The week name 'week-1'. |
||||
| 192 | * @return boolean |
||||
| 193 | */ |
||||
| 194 | function lsx_health_plan_week_has_downloads( $week = '' ) { |
||||
| 195 | $has_downloads = false; |
||||
| 196 | if ( '' !== $week ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 197 | $downloads = \lsx_health_plan\functions\get_weekly_downloads( $week ); |
||||
| 198 | if ( ! empty( $downloads ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 199 | $has_downloads = true; |
||||
| 200 | } |
||||
| 201 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 202 | return $has_downloads; |
||||
| 203 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 204 | |||||
| 205 | /** |
||||
| 206 | * Checks to see if the current ID has any tips attached. |
||||
| 207 | * |
||||
| 208 | * @param string $post_id |
||||
|
0 ignored issues
–
show
|
|||||
| 209 | * @return boolean |
||||
| 210 | */ |
||||
| 211 | function lsx_health_plan_has_tips( $post_id = '' ) { |
||||
| 212 | $has_tips = false; |
||||
| 213 | if ( '' === $post_id ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 214 | $post_id = get_the_ID(); |
||||
| 215 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 216 | $post_type = get_post_type( $post_id ); |
||||
|
0 ignored issues
–
show
It seems like
$post_id can also be of type false and string; however, parameter $post of get_post_type() does only seem to accept WP_Post|integer|null, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 217 | $connected_tips = get_post_meta( get_the_ID(), $post_type . '_connected_tips', true ); |
||||
|
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 218 | $connected_tips = \lsx_health_plan\functions\check_posts_exist( $connected_tips ); |
||||
|
0 ignored issues
–
show
It seems like
$connected_tips can also be of type false and string; however, parameter $post_ids of lsx_health_plan\functions\check_posts_exist() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 219 | if ( ! empty( $connected_tips ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 220 | $has_tips = true; |
||||
| 221 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 222 | return $has_tips; |
||||
| 223 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 224 |