@@ -17,27 +17,27 @@ discard block |
||
| 17 | 17 | * @return boolean |
| 18 | 18 | */ |
| 19 | 19 | function has_attached_post( $post_id = '', $meta_key = '', $single = true ) { |
| 20 | - $has_post = false; |
|
| 21 | - if ( '' === $post_id ) { |
|
| 22 | - $post_id = get_the_ID(); |
|
| 23 | - } |
|
| 24 | - $items = get_post_meta( $post_id, $meta_key, $single ); |
|
| 25 | - if ( '' !== $items && false !== $items && 0 !== $items ) { |
|
| 26 | - if ( ! is_array( $items ) ) { |
|
| 27 | - $items = array( $items ); |
|
| 28 | - } |
|
| 29 | - $items = check_posts_exist( $items ); |
|
| 30 | - if ( ! empty( $items ) ) { |
|
| 31 | - $has_post = true; |
|
| 32 | - } |
|
| 33 | - } else { |
|
| 34 | - // Check for defaults. |
|
| 35 | - $options = get_option( 'all' ); |
|
| 36 | - if ( isset( $options[ $meta_key ] ) && '' !== $options[ $meta_key ] && ! empty( $options[ $meta_key ] ) ) { |
|
| 37 | - $has_post = true; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - return $has_post; |
|
| 20 | + $has_post = false; |
|
| 21 | + if ( '' === $post_id ) { |
|
| 22 | + $post_id = get_the_ID(); |
|
| 23 | + } |
|
| 24 | + $items = get_post_meta( $post_id, $meta_key, $single ); |
|
| 25 | + if ( '' !== $items && false !== $items && 0 !== $items ) { |
|
| 26 | + if ( ! is_array( $items ) ) { |
|
| 27 | + $items = array( $items ); |
|
| 28 | + } |
|
| 29 | + $items = check_posts_exist( $items ); |
|
| 30 | + if ( ! empty( $items ) ) { |
|
| 31 | + $has_post = true; |
|
| 32 | + } |
|
| 33 | + } else { |
|
| 34 | + // Check for defaults. |
|
| 35 | + $options = get_option( 'all' ); |
|
| 36 | + if ( isset( $options[ $meta_key ] ) && '' !== $options[ $meta_key ] && ! empty( $options[ $meta_key ] ) ) { |
|
| 37 | + $has_post = true; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + return $has_post; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -48,18 +48,18 @@ discard block |
||
| 48 | 48 | * @return mixed Option value |
| 49 | 49 | */ |
| 50 | 50 | function get_option( $key = '', $default = false ) { |
| 51 | - if ( function_exists( 'cmb2_get_option' ) ) { |
|
| 52 | - return cmb2_get_option( 'lsx_health_plan_options', $key, $default ); |
|
| 53 | - } |
|
| 54 | - // Fallback to get_option if CMB2 is not loaded yet. |
|
| 55 | - $opts = \get_option( 'lsx_health_plan_options', $default ); |
|
| 56 | - $val = $default; |
|
| 57 | - if ( 'all' === $key ) { |
|
| 58 | - $val = $opts; |
|
| 59 | - } elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) { |
|
| 60 | - $val = $opts[ $key ]; |
|
| 61 | - } |
|
| 62 | - return $val; |
|
| 51 | + if ( function_exists( 'cmb2_get_option' ) ) { |
|
| 52 | + return cmb2_get_option( 'lsx_health_plan_options', $key, $default ); |
|
| 53 | + } |
|
| 54 | + // Fallback to get_option if CMB2 is not loaded yet. |
|
| 55 | + $opts = \get_option( 'lsx_health_plan_options', $default ); |
|
| 56 | + $val = $default; |
|
| 57 | + if ( 'all' === $key ) { |
|
| 58 | + $val = $opts; |
|
| 59 | + } elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) { |
|
| 60 | + $val = $opts[ $key ]; |
|
| 61 | + } |
|
| 62 | + return $val; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -70,54 +70,54 @@ discard block |
||
| 70 | 70 | * @return mixed Option value |
| 71 | 71 | */ |
| 72 | 72 | function get_downloads( $type = 'all', $post_id = '' ) { |
| 73 | - $lsx_health_plan = \lsx_health_plan(); |
|
| 74 | - $post_types = $lsx_health_plan->get_post_types(); |
|
| 75 | - if ( '' === $post_id ) { |
|
| 76 | - $post_id = get_the_ID(); |
|
| 77 | - } |
|
| 78 | - $downloads = array(); |
|
| 79 | - $options = get_option( 'all' ); |
|
| 80 | - |
|
| 81 | - foreach ( $post_types as $post_type ) { |
|
| 82 | - if ( 'all' === $type || in_array( $type, $post_types, true ) ) { |
|
| 83 | - |
|
| 84 | - // Get the default downloads for this post type. |
|
| 85 | - $default_downloads = array(); |
|
| 86 | - $new_downloads = array(); |
|
| 87 | - if ( isset( $options[ 'download_' . $post_type ] ) ) { |
|
| 88 | - if ( is_array( $options[ 'download_' . $post_type ] ) ) { |
|
| 89 | - $default_downloads = $options[ 'download_' . $post_type ]; |
|
| 90 | - } else { |
|
| 91 | - $default_downloads[] = $options[ 'download_' . $post_type ]; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if ( 'page' === $post_type ) { |
|
| 96 | - $key = 'plan_warmup'; |
|
| 97 | - } else { |
|
| 98 | - $key = 'connected_' . $post_type . 's'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $connected_items = get_post_meta( $post_id, $key, true ); |
|
| 102 | - if ( ! empty( $connected_items ) ) { |
|
| 103 | - foreach ( $connected_items as $connected_item ) { |
|
| 104 | - $current_downloads = get_post_meta( $connected_item, 'connected_downloads', true ); |
|
| 105 | - if ( false !== $current_downloads && ! empty( $current_downloads ) ) { |
|
| 106 | - $new_downloads = array_merge( $new_downloads, $current_downloads ); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if ( ! empty( $new_downloads ) ) { |
|
| 112 | - $downloads = array_merge( $downloads, $new_downloads ); |
|
| 113 | - } elseif ( ! empty( $default_downloads ) ) { |
|
| 114 | - $downloads = array_merge( $downloads, $default_downloads ); |
|
| 115 | - } |
|
| 116 | - $downloads = array_unique( $downloads ); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - $downloads = check_posts_exist( $downloads ); |
|
| 120 | - return $downloads; |
|
| 73 | + $lsx_health_plan = \lsx_health_plan(); |
|
| 74 | + $post_types = $lsx_health_plan->get_post_types(); |
|
| 75 | + if ( '' === $post_id ) { |
|
| 76 | + $post_id = get_the_ID(); |
|
| 77 | + } |
|
| 78 | + $downloads = array(); |
|
| 79 | + $options = get_option( 'all' ); |
|
| 80 | + |
|
| 81 | + foreach ( $post_types as $post_type ) { |
|
| 82 | + if ( 'all' === $type || in_array( $type, $post_types, true ) ) { |
|
| 83 | + |
|
| 84 | + // Get the default downloads for this post type. |
|
| 85 | + $default_downloads = array(); |
|
| 86 | + $new_downloads = array(); |
|
| 87 | + if ( isset( $options[ 'download_' . $post_type ] ) ) { |
|
| 88 | + if ( is_array( $options[ 'download_' . $post_type ] ) ) { |
|
| 89 | + $default_downloads = $options[ 'download_' . $post_type ]; |
|
| 90 | + } else { |
|
| 91 | + $default_downloads[] = $options[ 'download_' . $post_type ]; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if ( 'page' === $post_type ) { |
|
| 96 | + $key = 'plan_warmup'; |
|
| 97 | + } else { |
|
| 98 | + $key = 'connected_' . $post_type . 's'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $connected_items = get_post_meta( $post_id, $key, true ); |
|
| 102 | + if ( ! empty( $connected_items ) ) { |
|
| 103 | + foreach ( $connected_items as $connected_item ) { |
|
| 104 | + $current_downloads = get_post_meta( $connected_item, 'connected_downloads', true ); |
|
| 105 | + if ( false !== $current_downloads && ! empty( $current_downloads ) ) { |
|
| 106 | + $new_downloads = array_merge( $new_downloads, $current_downloads ); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if ( ! empty( $new_downloads ) ) { |
|
| 112 | + $downloads = array_merge( $downloads, $new_downloads ); |
|
| 113 | + } elseif ( ! empty( $default_downloads ) ) { |
|
| 114 | + $downloads = array_merge( $downloads, $default_downloads ); |
|
| 115 | + } |
|
| 116 | + $downloads = array_unique( $downloads ); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + $downloads = check_posts_exist( $downloads ); |
|
| 120 | + return $downloads; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,35 +127,35 @@ discard block |
||
| 127 | 127 | * @return array an array of the downloads or empty. |
| 128 | 128 | */ |
| 129 | 129 | function get_weekly_downloads( $week = '' ) { |
| 130 | - $downloads = array(); |
|
| 131 | - if ( '' !== $week ) { |
|
| 132 | - $saved_downloads = get_transient( 'lsx_hp_weekly_downloads_' . $week ); |
|
| 133 | - if ( false !== $saved_downloads && ! empty( $saved_downloads ) ) { |
|
| 134 | - $downloads = $saved_downloads; |
|
| 135 | - } else { |
|
| 136 | - $args = array( |
|
| 137 | - 'orderby' => 'title', |
|
| 138 | - 'order' => 'ASC', |
|
| 139 | - 'post_type' => 'dlm_download', |
|
| 140 | - 'posts_per_page' => -1, |
|
| 141 | - 'nopagin' => true, |
|
| 142 | - 'fields' => 'ids', |
|
| 143 | - 'tax_query' => array( |
|
| 144 | - array( |
|
| 145 | - 'taxonomy' => 'dlm_download_category', |
|
| 146 | - 'field' => 'slug', |
|
| 147 | - 'terms' => array( $week ), |
|
| 148 | - ), |
|
| 149 | - ), |
|
| 150 | - ); |
|
| 151 | - $download_query = new \WP_Query( $args ); |
|
| 152 | - if ( $download_query->have_posts() ) { |
|
| 153 | - $downloads = $download_query->posts; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - $downloads = check_posts_exist( $downloads ); |
|
| 158 | - return $downloads; |
|
| 130 | + $downloads = array(); |
|
| 131 | + if ( '' !== $week ) { |
|
| 132 | + $saved_downloads = get_transient( 'lsx_hp_weekly_downloads_' . $week ); |
|
| 133 | + if ( false !== $saved_downloads && ! empty( $saved_downloads ) ) { |
|
| 134 | + $downloads = $saved_downloads; |
|
| 135 | + } else { |
|
| 136 | + $args = array( |
|
| 137 | + 'orderby' => 'title', |
|
| 138 | + 'order' => 'ASC', |
|
| 139 | + 'post_type' => 'dlm_download', |
|
| 140 | + 'posts_per_page' => -1, |
|
| 141 | + 'nopagin' => true, |
|
| 142 | + 'fields' => 'ids', |
|
| 143 | + 'tax_query' => array( |
|
| 144 | + array( |
|
| 145 | + 'taxonomy' => 'dlm_download_category', |
|
| 146 | + 'field' => 'slug', |
|
| 147 | + 'terms' => array( $week ), |
|
| 148 | + ), |
|
| 149 | + ), |
|
| 150 | + ); |
|
| 151 | + $download_query = new \WP_Query( $args ); |
|
| 152 | + if ( $download_query->have_posts() ) { |
|
| 153 | + $downloads = $download_query->posts; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + $downloads = check_posts_exist( $downloads ); |
|
| 158 | + return $downloads; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -165,22 +165,22 @@ discard block |
||
| 165 | 165 | * @return void |
| 166 | 166 | */ |
| 167 | 167 | function check_posts_exist( $post_ids = array() ) { |
| 168 | - $new_ids = array(); |
|
| 169 | - global $wpdb; |
|
| 170 | - if ( is_array( $post_ids ) && ! empty( $post_ids ) ) { |
|
| 171 | - $post_ids = "'" . implode( "','", $post_ids ) . "'"; |
|
| 172 | - $query = " |
|
| 168 | + $new_ids = array(); |
|
| 169 | + global $wpdb; |
|
| 170 | + if ( is_array( $post_ids ) && ! empty( $post_ids ) ) { |
|
| 171 | + $post_ids = "'" . implode( "','", $post_ids ) . "'"; |
|
| 172 | + $query = " |
|
| 173 | 173 | SELECT `ID` |
| 174 | 174 | FROM `{$wpdb->posts}` |
| 175 | 175 | WHERE `ID` IN ({$post_ids}) |
| 176 | 176 | AND `post_status` != 'trash' |
| 177 | 177 | "; |
| 178 | - $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL |
|
| 179 | - if ( ! empty( $results ) ) { |
|
| 180 | - $new_ids = wp_list_pluck( $results, 'ID' ); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - return $new_ids; |
|
| 178 | + $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL |
|
| 179 | + if ( ! empty( $results ) ) { |
|
| 180 | + $new_ids = wp_list_pluck( $results, 'ID' ); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + return $new_ids; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | * @return void |
| 193 | 193 | */ |
| 194 | 194 | function register_modal( $id = '', $title = '', $body = '' ) { |
| 195 | - lsx_health_plan()->frontend->modals->register_modal( |
|
| 196 | - array( |
|
| 197 | - 'title' => $title, |
|
| 198 | - 'body' => $body, |
|
| 199 | - ), |
|
| 200 | - $id |
|
| 201 | - ); |
|
| 195 | + lsx_health_plan()->frontend->modals->register_modal( |
|
| 196 | + array( |
|
| 197 | + 'title' => $title, |
|
| 198 | + 'body' => $body, |
|
| 199 | + ), |
|
| 200 | + $id |
|
| 201 | + ); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | * @return void |
| 209 | 209 | */ |
| 210 | 210 | function output_modal( $args = array() ) { |
| 211 | - $defaults = array( |
|
| 212 | - 'id' => '', |
|
| 213 | - 'title' => '', |
|
| 214 | - 'body' => '', |
|
| 215 | - ); |
|
| 216 | - $args = wp_parse_args( $args, $defaults ); |
|
| 217 | - ?> |
|
| 211 | + $defaults = array( |
|
| 212 | + 'id' => '', |
|
| 213 | + 'title' => '', |
|
| 214 | + 'body' => '', |
|
| 215 | + ); |
|
| 216 | + $args = wp_parse_args( $args, $defaults ); |
|
| 217 | + ?> |
|
| 218 | 218 | <!-- Modal --> |
| 219 | 219 | <div class="modal fade lsx-health-plan-modal" id="<?php echo esc_html( $args['id'] ); ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo esc_html( $args['id'] ); ?>" aria-hidden="true"> |
| 220 | 220 | <div class="modal-dialog" role="document"> |
@@ -222,36 +222,36 @@ discard block |
||
| 222 | 222 | <button type="button" class="close" data-dismiss="modal">×</button> |
| 223 | 223 | <div class="modal-header"> |
| 224 | 224 | <?php |
| 225 | - if ( '' !== $args['title'] ) { |
|
| 226 | - echo wp_kses_post( '<h2>' . $args['title'] . '</h2>' ); |
|
| 227 | - } |
|
| 228 | - ?> |
|
| 225 | + if ( '' !== $args['title'] ) { |
|
| 226 | + echo wp_kses_post( '<h2>' . $args['title'] . '</h2>' ); |
|
| 227 | + } |
|
| 228 | + ?> |
|
| 229 | 229 | </div> |
| 230 | 230 | <div class="modal-body"> |
| 231 | 231 | <?php |
| 232 | - if ( '' !== $args['body'] ) { |
|
| 233 | - $allowed_html = array( |
|
| 234 | - 'iframe' => array( |
|
| 235 | - 'data-src' => array(), |
|
| 236 | - 'src' => array(), |
|
| 237 | - 'width' => array(), |
|
| 238 | - 'height' => array(), |
|
| 239 | - 'frameBorder' => array( '0' ), |
|
| 240 | - 'class' => array(), |
|
| 241 | - 'allowFullScreen' => array(), |
|
| 242 | - 'style' => array(), |
|
| 243 | - ), |
|
| 244 | - 'h5' => array( |
|
| 245 | - 'class' => array(), |
|
| 246 | - ), |
|
| 247 | - ); |
|
| 248 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
| 249 | - echo wp_kses_post( $args['body'] ); |
|
| 250 | - } else { |
|
| 251 | - echo wp_kses( $args['body'], $allowed_html ); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - ?> |
|
| 232 | + if ( '' !== $args['body'] ) { |
|
| 233 | + $allowed_html = array( |
|
| 234 | + 'iframe' => array( |
|
| 235 | + 'data-src' => array(), |
|
| 236 | + 'src' => array(), |
|
| 237 | + 'width' => array(), |
|
| 238 | + 'height' => array(), |
|
| 239 | + 'frameBorder' => array( '0' ), |
|
| 240 | + 'class' => array(), |
|
| 241 | + 'allowFullScreen' => array(), |
|
| 242 | + 'style' => array(), |
|
| 243 | + ), |
|
| 244 | + 'h5' => array( |
|
| 245 | + 'class' => array(), |
|
| 246 | + ), |
|
| 247 | + ); |
|
| 248 | + if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
| 249 | + echo wp_kses_post( $args['body'] ); |
|
| 250 | + } else { |
|
| 251 | + echo wp_kses( $args['body'], $allowed_html ); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + ?> |
|
| 255 | 255 | </div> |
| 256 | 256 | </div> |
| 257 | 257 | </div> |
@@ -267,18 +267,18 @@ discard block |
||
| 267 | 267 | * @return void |
| 268 | 268 | */ |
| 269 | 269 | function get_video_url( $embed ) { |
| 270 | - $url = ''; |
|
| 271 | - if ( false !== stripos( $embed, '<iframe' ) ) { |
|
| 272 | - preg_match( '/src="([^"]+)"/', $embed, $match ); |
|
| 273 | - if ( is_array( $match ) && isset( $match[1] ) ) { |
|
| 274 | - $url = '<iframe data-src="' . $match[1] . '" style="border: 0;" frameBorder="0" class="giphy-embed" allowFullScreen height="300" width="100%"></iframe>'; |
|
| 275 | - } else { |
|
| 276 | - $url = $embed; |
|
| 277 | - } |
|
| 278 | - } else { |
|
| 279 | - $url = $embed; |
|
| 280 | - } |
|
| 281 | - return $url; |
|
| 270 | + $url = ''; |
|
| 271 | + if ( false !== stripos( $embed, '<iframe' ) ) { |
|
| 272 | + preg_match( '/src="([^"]+)"/', $embed, $match ); |
|
| 273 | + if ( is_array( $match ) && isset( $match[1] ) ) { |
|
| 274 | + $url = '<iframe data-src="' . $match[1] . '" style="border: 0;" frameBorder="0" class="giphy-embed" allowFullScreen height="300" width="100%"></iframe>'; |
|
| 275 | + } else { |
|
| 276 | + $url = $embed; |
|
| 277 | + } |
|
| 278 | + } else { |
|
| 279 | + $url = $embed; |
|
| 280 | + } |
|
| 281 | + return $url; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -289,18 +289,18 @@ discard block |
||
| 289 | 289 | * @return boolean |
| 290 | 290 | */ |
| 291 | 291 | function is_week_complete( $term_id = false, $section_keys = array(), $group_title = '' ) { |
| 292 | - $return = false; |
|
| 293 | - if ( ! empty( $section_keys ) ) { |
|
| 294 | - $group_count = count( $section_keys ); |
|
| 295 | - foreach ( $section_keys as &$pid ) { |
|
| 296 | - $pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id( $pid ) . '_complete'; |
|
| 297 | - } |
|
| 298 | - $days_complete = get_meta_amounts( $section_keys ); |
|
| 299 | - if ( (int) $group_count === (int) $days_complete ) { |
|
| 300 | - $return = true; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - return $return; |
|
| 292 | + $return = false; |
|
| 293 | + if ( ! empty( $section_keys ) ) { |
|
| 294 | + $group_count = count( $section_keys ); |
|
| 295 | + foreach ( $section_keys as &$pid ) { |
|
| 296 | + $pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id( $pid ) . '_complete'; |
|
| 297 | + } |
|
| 298 | + $days_complete = get_meta_amounts( $section_keys ); |
|
| 299 | + if ( (int) $group_count === (int) $days_complete ) { |
|
| 300 | + $return = true; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + return $return; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -311,23 +311,23 @@ discard block |
||
| 311 | 311 | * @return void |
| 312 | 312 | */ |
| 313 | 313 | function get_meta_amounts( $post_ids = array() ) { |
| 314 | - global $wpdb; |
|
| 315 | - $amount = 0; |
|
| 316 | - $current_user = wp_get_current_user(); |
|
| 317 | - if ( false !== $current_user && ! empty( $post_ids ) ) { |
|
| 318 | - $post_ids = "'" . implode( "','", $post_ids ) . "'"; |
|
| 319 | - $query = " |
|
| 314 | + global $wpdb; |
|
| 315 | + $amount = 0; |
|
| 316 | + $current_user = wp_get_current_user(); |
|
| 317 | + if ( false !== $current_user && ! empty( $post_ids ) ) { |
|
| 318 | + $post_ids = "'" . implode( "','", $post_ids ) . "'"; |
|
| 319 | + $query = " |
|
| 320 | 320 | SELECT COUNT(`meta_value`) |
| 321 | 321 | FROM `{$wpdb->usermeta}` |
| 322 | 322 | WHERE `meta_key` IN ({$post_ids}) |
| 323 | 323 | AND `user_id` = '{$current_user->ID}' |
| 324 | 324 | "; |
| 325 | - $results = $wpdb->get_var( $query ); // WPCS: unprepared SQL |
|
| 326 | - if ( ! empty( $results ) ) { |
|
| 327 | - $amount = $results; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - return $amount; |
|
| 325 | + $results = $wpdb->get_var( $query ); // WPCS: unprepared SQL |
|
| 326 | + if ( ! empty( $results ) ) { |
|
| 327 | + $amount = $results; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + return $amount; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -337,39 +337,39 @@ discard block |
||
| 337 | 337 | * @return void |
| 338 | 338 | */ |
| 339 | 339 | function hp_get_plan_type_meta( $post ) { |
| 340 | - $plan_meta = ''; |
|
| 340 | + $plan_meta = ''; |
|
| 341 | 341 | |
| 342 | - $term_obj_list = get_the_terms( $post->ID, 'plan-type' ); |
|
| 343 | - if ( false !== $term_obj_list ) { |
|
| 344 | - $terms_string = join( ' & ', wp_list_pluck( $term_obj_list, 'name' ) ); |
|
| 345 | - $terms_ids = wp_list_pluck( $term_obj_list, 'term_id' ); |
|
| 342 | + $term_obj_list = get_the_terms( $post->ID, 'plan-type' ); |
|
| 343 | + if ( false !== $term_obj_list ) { |
|
| 344 | + $terms_string = join( ' & ', wp_list_pluck( $term_obj_list, 'name' ) ); |
|
| 345 | + $terms_ids = wp_list_pluck( $term_obj_list, 'term_id' ); |
|
| 346 | 346 | |
| 347 | - foreach ( $terms_ids as $terms_id ) { |
|
| 348 | - $term_thumbnail_id = get_term_meta( $terms_id, 'thumbnail', true ); |
|
| 349 | - $img = wp_get_attachment_image_src( $term_thumbnail_id, 'thumbnail' ); |
|
| 350 | - if ( ! empty( $img ) ) { |
|
| 351 | - $image_url = $img[0]; |
|
| 352 | - $img = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url( $image_url ) . '" />'; |
|
| 353 | - } |
|
| 347 | + foreach ( $terms_ids as $terms_id ) { |
|
| 348 | + $term_thumbnail_id = get_term_meta( $terms_id, 'thumbnail', true ); |
|
| 349 | + $img = wp_get_attachment_image_src( $term_thumbnail_id, 'thumbnail' ); |
|
| 350 | + if ( ! empty( $img ) ) { |
|
| 351 | + $image_url = $img[0]; |
|
| 352 | + $img = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url( $image_url ) . '" />'; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - $plan_meta .= $img; |
|
| 356 | - } |
|
| 355 | + $plan_meta .= $img; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - $plan_meta = '<div class="plan-meta">' . $plan_meta . '<span>' . $terms_string . '</span></div>'; |
|
| 359 | - } |
|
| 358 | + $plan_meta = '<div class="plan-meta">' . $plan_meta . '<span>' . $terms_string . '</span></div>'; |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return $plan_meta; |
|
| 361 | + return $plan_meta; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
| 365 | 365 | * Limit media library access |
| 366 | 366 | */ |
| 367 | 367 | function set_only_author( $wp_query ) { |
| 368 | - global $current_user; |
|
| 369 | - if ( is_admin() && ! current_user_can( 'edit_others_posts' ) ) { |
|
| 370 | - $wp_query->set( 'administrator', $current_user->ID ); |
|
| 371 | - add_filter( 'views_upload', 'fix_media_counts' ); |
|
| 372 | - } |
|
| 368 | + global $current_user; |
|
| 369 | + if ( is_admin() && ! current_user_can( 'edit_others_posts' ) ) { |
|
| 370 | + $wp_query->set( 'administrator', $current_user->ID ); |
|
| 371 | + add_filter( 'views_upload', 'fix_media_counts' ); |
|
| 372 | + } |
|
| 373 | 373 | } |
| 374 | 374 | add_action( 'pre_get_posts', '\lsx_health_plan\functions\set_only_author' ); |
| 375 | 375 | |
@@ -380,12 +380,12 @@ discard block |
||
| 380 | 380 | * @return void |
| 381 | 381 | */ |
| 382 | 382 | function hp_excerpt( $post_id ) { |
| 383 | - if ( ! has_excerpt( $post_id ) ) { |
|
| 384 | - $content = wp_trim_words( get_post_field( 'post_content', $post_id ), 10 ); |
|
| 385 | - } else { |
|
| 386 | - $content = get_the_excerpt( $post_id ); |
|
| 387 | - } |
|
| 388 | - return $content; |
|
| 383 | + if ( ! has_excerpt( $post_id ) ) { |
|
| 384 | + $content = wp_trim_words( get_post_field( 'post_content', $post_id ), 10 ); |
|
| 385 | + } else { |
|
| 386 | + $content = get_the_excerpt( $post_id ); |
|
| 387 | + } |
|
| 388 | + return $content; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * @return void |
| 396 | 396 | */ |
| 397 | 397 | function column_class( $columns = '3' ) { |
| 398 | - $cols .= '5' === $columns ? '15' : 12 / $columns; |
|
| 399 | - return $cols; |
|
| 398 | + $cols .= '5' === $columns ? '15' : 12 / $columns; |
|
| 399 | + return $cols; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -406,22 +406,22 @@ discard block |
||
| 406 | 406 | * @return void |
| 407 | 407 | */ |
| 408 | 408 | function get_exercises_by_workout( $workout = '' ) { |
| 409 | - $exercises = array(); |
|
| 410 | - $i = 1; |
|
| 411 | - $section_counter = 6; |
|
| 412 | - while ( $i <= $section_counter ) { |
|
| 413 | - $group_name = 'workout_section_' . $i; |
|
| 414 | - $groups = get_post_meta( $workout, $group_name, true ); |
|
| 415 | - if ( ! empty( $groups ) ) { |
|
| 416 | - foreach ( $groups as $group ) { |
|
| 417 | - if ( isset( $group['connected_exercises'] ) ) { |
|
| 418 | - $exercises[] = $group['connected_exercises']; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - $i++; |
|
| 423 | - } |
|
| 424 | - return $exercises; |
|
| 409 | + $exercises = array(); |
|
| 410 | + $i = 1; |
|
| 411 | + $section_counter = 6; |
|
| 412 | + while ( $i <= $section_counter ) { |
|
| 413 | + $group_name = 'workout_section_' . $i; |
|
| 414 | + $groups = get_post_meta( $workout, $group_name, true ); |
|
| 415 | + if ( ! empty( $groups ) ) { |
|
| 416 | + foreach ( $groups as $group ) { |
|
| 417 | + if ( isset( $group['connected_exercises'] ) ) { |
|
| 418 | + $exercises[] = $group['connected_exercises']; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + $i++; |
|
| 423 | + } |
|
| 424 | + return $exercises; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | |
@@ -432,20 +432,20 @@ discard block |
||
| 432 | 432 | * @return int |
| 433 | 433 | */ |
| 434 | 434 | function get_progress( $plan_id = false ) { |
| 435 | - $progress = 0; |
|
| 436 | - $complete = array(); |
|
| 437 | - $count = 0; |
|
| 438 | - if ( false !== $plan_id && \lsx_health_plan\functions\plan\has_sections( $plan_id ) ) { |
|
| 439 | - $sections = \lsx_health_plan\functions\plan\get_sections(); |
|
| 440 | - $all_count = count( $sections ); |
|
| 441 | - foreach ( $sections as $section_key => $section_values ) { |
|
| 442 | - if ( lsx_health_plan_is_day_complete( $plan_id, $section_values['title'] ) ) { |
|
| 443 | - $complete[] = true; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - $progress = (int) count( $complete ) / (int) $all_count * 100; |
|
| 447 | - } |
|
| 448 | - return $progress; |
|
| 435 | + $progress = 0; |
|
| 436 | + $complete = array(); |
|
| 437 | + $count = 0; |
|
| 438 | + if ( false !== $plan_id && \lsx_health_plan\functions\plan\has_sections( $plan_id ) ) { |
|
| 439 | + $sections = \lsx_health_plan\functions\plan\get_sections(); |
|
| 440 | + $all_count = count( $sections ); |
|
| 441 | + foreach ( $sections as $section_key => $section_values ) { |
|
| 442 | + if ( lsx_health_plan_is_day_complete( $plan_id, $section_values['title'] ) ) { |
|
| 443 | + $complete[] = true; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + $progress = (int) count( $complete ) / (int) $all_count * 100; |
|
| 447 | + } |
|
| 448 | + return $progress; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -457,18 +457,18 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | function hp_back_archive_link() { |
| 459 | 459 | |
| 460 | - $post_type = 'exercise'; |
|
| 461 | - if ( is_tax( 'recipe-cuisine' ) || is_tax( 'recipe-type' ) ) { |
|
| 462 | - $post_type = 'recipe'; |
|
| 463 | - } |
|
| 460 | + $post_type = 'exercise'; |
|
| 461 | + if ( is_tax( 'recipe-cuisine' ) || is_tax( 'recipe-type' ) ) { |
|
| 462 | + $post_type = 'recipe'; |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - if ( is_tax() ) { |
|
| 466 | - ?> |
|
| 465 | + if ( is_tax() ) { |
|
| 466 | + ?> |
|
| 467 | 467 | <div class="archive-category-title hp-archive-category-title"> |
| 468 | 468 | <a class="back-to-blog" href="<?php echo ( esc_url( get_post_type_archive_link( $post_type ) ) ); ?>"><?php echo esc_html__( 'Back To ', 'lsx' ) . esc_html( $post_type ) . 's'; ?></a> |
| 469 | 469 | </div> |
| 470 | 470 | <?php |
| 471 | - } |
|
| 471 | + } |
|
| 472 | 472 | } |
| 473 | 473 | add_action( 'lsx_content_wrap_before', '\lsx_health_plan\functions\hp_back_archive_link', 20 ); |
| 474 | 474 | |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | * @return array |
| 480 | 480 | */ |
| 481 | 481 | function prep_array( $item ) { |
| 482 | - if ( ! is_array( $item ) ) { |
|
| 483 | - $item = explode( ',', $item ); |
|
| 484 | - if ( ! is_array( $item ) ) { |
|
| 485 | - $item = array( $item ); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - return $item; |
|
| 482 | + if ( ! is_array( $item ) ) { |
|
| 483 | + $item = explode( ',', $item ); |
|
| 484 | + if ( ! is_array( $item ) ) { |
|
| 485 | + $item = array( $item ); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + return $item; |
|
| 489 | 489 | } |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | <?php |
| 13 | 13 | $args = array( |
| 14 | - 'post_parent' => get_the_ID(), |
|
| 15 | - 'post_type' => 'plan', |
|
| 14 | + 'post_parent' => get_the_ID(), |
|
| 15 | + 'post_type' => 'plan', |
|
| 16 | 16 | ); |
| 17 | 17 | |
| 18 | 18 | $plan_id = get_the_ID(); |
@@ -28,23 +28,23 @@ discard block |
||
| 28 | 28 | $connected_articles = get_post_meta( get_the_ID(), ( $plan . '_connected_articles' ), true ); |
| 29 | 29 | |
| 30 | 30 | if ( ! empty( $has_sections ) ) { |
| 31 | - $plan_type_class = 'parent-plan'; |
|
| 32 | - if ( 0 !== $has_parent ) { |
|
| 33 | - $plan_type_class = 'parent-sub-plan'; |
|
| 34 | - } |
|
| 31 | + $plan_type_class = 'parent-plan'; |
|
| 32 | + if ( 0 !== $has_parent ) { |
|
| 33 | + $plan_type_class = 'parent-sub-plan'; |
|
| 34 | + } |
|
| 35 | 35 | } else { |
| 36 | - $plan_type_class = 'unique-plan'; |
|
| 37 | - if ( 0 !== $has_parent ) { |
|
| 38 | - $plan_type_class = 'child-plan-' . $has_parent; |
|
| 39 | - } |
|
| 36 | + $plan_type_class = 'unique-plan'; |
|
| 37 | + if ( 0 !== $has_parent ) { |
|
| 38 | + $plan_type_class = 'child-plan-' . $has_parent; |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // Get the plan restrictions. |
| 43 | 43 | if ( function_exists( 'wc_memberships_is_post_content_restricted' ) && wc_memberships_is_post_content_restricted( get_the_ID() ) ) { |
| 44 | - $restricted = ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
| 44 | + $restricted = ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
| 45 | 45 | } |
| 46 | 46 | if ( false === $restricted ) { |
| 47 | - $round_progress = round( \lsx_health_plan\functions\get_progress( get_the_ID() ), 0 ); |
|
| 47 | + $round_progress = round( \lsx_health_plan\functions\get_progress( get_the_ID() ), 0 ); |
|
| 48 | 48 | } |
| 49 | 49 | ?> |
| 50 | 50 | |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | </div> |
| 63 | 63 | |
| 64 | 64 | <?php |
| 65 | - if ( ! empty( $has_sections ) ) { |
|
| 66 | - if ( false === $is_section ) { |
|
| 67 | - ?> |
|
| 65 | + if ( ! empty( $has_sections ) ) { |
|
| 66 | + if ( false === $is_section ) { |
|
| 67 | + ?> |
|
| 68 | 68 | <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> |
| 69 | 69 | <div class="entry-content"> |
| 70 | 70 | <div class="single-plan-inner main-plan-content"> |
@@ -75,29 +75,29 @@ discard block |
||
| 75 | 75 | <div class="plan"> |
| 76 | 76 | <?php |
| 77 | 77 | |
| 78 | - // The top part |
|
| 79 | - echo wp_kses_post( wp_kses_post( lsx_health_plan_main_content() ) ); |
|
| 78 | + // The top part |
|
| 79 | + echo wp_kses_post( wp_kses_post( lsx_health_plan_main_content() ) ); |
|
| 80 | 80 | |
| 81 | - echo wp_kses_post( '<h3 class="my-plan-title">' . __( 'Your Game Plan', 'lsx-health-plan' ) . '</h3>' ); |
|
| 81 | + echo wp_kses_post( '<h3 class="my-plan-title">' . __( 'Your Game Plan', 'lsx-health-plan' ) . '</h3>' ); |
|
| 82 | 82 | |
| 83 | - ?> |
|
| 83 | + ?> |
|
| 84 | 84 | <div class="the-plan-content"> |
| 85 | 85 | <?php |
| 86 | - if ( false === $restricted ) { |
|
| 87 | - echo wp_kses_post( '<span class="progress"><progress class="bar" value="' . $round_progress . '" max="100"> ' . $round_progress . '% </progress><span>' . $round_progress . '%</span></span>' ); |
|
| 88 | - } |
|
| 86 | + if ( false === $restricted ) { |
|
| 87 | + echo wp_kses_post( '<span class="progress"><progress class="bar" value="' . $round_progress . '" max="100"> ' . $round_progress . '% </progress><span>' . $round_progress . '%</span></span>' ); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - echo do_shortcode( '[lsx_health_plan_day_plan_block week_view="true" show_downloads="true" plan="' . get_the_ID() . '"]' ); |
|
| 90 | + echo do_shortcode( '[lsx_health_plan_day_plan_block week_view="true" show_downloads="true" plan="' . get_the_ID() . '"]' ); |
|
| 91 | 91 | |
| 92 | - ?> |
|
| 92 | + ?> |
|
| 93 | 93 | <div class="row status-plan-buttons main-plan-btn"> |
| 94 | 94 | <?php |
| 95 | - if ( function_exists( 'wc_get_page_id' ) ) { |
|
| 96 | - ?> |
|
| 95 | + if ( function_exists( 'wc_get_page_id' ) ) { |
|
| 96 | + ?> |
|
| 97 | 97 | <a class="btn border-btn" href="<?php echo wp_kses_post( get_permalink( wc_get_page_id( 'myaccount' ) ) ); ?>"><?php esc_html_e( 'My Plans', 'lsx-health-plan' ); ?></a> |
| 98 | 98 | <?php |
| 99 | - } |
|
| 100 | - ?> |
|
| 99 | + } |
|
| 100 | + ?> |
|
| 101 | 101 | </div> |
| 102 | 102 | </div> |
| 103 | 103 | </div> |
@@ -106,32 +106,32 @@ discard block |
||
| 106 | 106 | </div><!-- .entry-content --> |
| 107 | 107 | </article> |
| 108 | 108 | <?php |
| 109 | - } else { |
|
| 110 | - lsx_health_plan_single_nav(); |
|
| 111 | - lsx_health_plan_single_tabs(); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - ?> |
|
| 109 | + } else { |
|
| 110 | + lsx_health_plan_single_nav(); |
|
| 111 | + lsx_health_plan_single_tabs(); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + ?> |
|
| 115 | 115 | </div> |
| 116 | 116 | |
| 117 | 117 | <?php |
| 118 | - // Show the buttons on the single plan tabs. |
|
| 119 | - if ( ! empty( $has_sections ) && false !== $is_section ) { |
|
| 120 | - ?> |
|
| 118 | + // Show the buttons on the single plan tabs. |
|
| 119 | + if ( ! empty( $has_sections ) && false !== $is_section ) { |
|
| 120 | + ?> |
|
| 121 | 121 | <div class="row status-plan-buttons"> |
| 122 | 122 | <?php lsx_health_plan_day_button(); ?> |
| 123 | 123 | </div> |
| 124 | 124 | <?php |
| 125 | - } |
|
| 126 | - ?> |
|
| 125 | + } |
|
| 126 | + ?> |
|
| 127 | 127 | |
| 128 | 128 | <?php lsx_content_bottom(); ?> |
| 129 | 129 | |
| 130 | 130 | <?php |
| 131 | - if ( ! empty( $connected_articles ) ) { |
|
| 132 | - lsx_hp_single_related( $connected_articles, __( 'Latest articles', 'lsx-health-plan' ) ); |
|
| 133 | - } |
|
| 134 | - ?> |
|
| 131 | + if ( ! empty( $connected_articles ) ) { |
|
| 132 | + lsx_hp_single_related( $connected_articles, __( 'Latest articles', 'lsx-health-plan' ) ); |
|
| 133 | + } |
|
| 134 | + ?> |
|
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | </main><!-- #main --> |
@@ -8,98 +8,98 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Plan_Query { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Holds class instance |
|
| 13 | - * |
|
| 14 | - * @since 1.0.0 |
|
| 15 | - * |
|
| 16 | - * @var object \lsx_health_plan\classes\frontend\Plan_Query() |
|
| 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\frontend\Plan_Query() |
|
| 17 | + */ |
|
| 18 | + protected static $instance = null; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Holds the sections for the current plan. |
|
| 22 | - * |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $sections = array(); |
|
| 20 | + /** |
|
| 21 | + * Holds the sections for the current plan. |
|
| 22 | + * |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $sections = array(); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Holds the variable true/false if the current plan has sections or not. |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - public $has_sections = false; |
|
| 27 | + /** |
|
| 28 | + * Holds the variable true/false if the current plan has sections or not. |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + public $has_sections = false; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Contructor |
|
| 36 | - */ |
|
| 37 | - public function __construct() { |
|
| 38 | - } |
|
| 34 | + /** |
|
| 35 | + * Contructor |
|
| 36 | + */ |
|
| 37 | + public function __construct() { |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Return an instance of this class. |
|
| 42 | - * |
|
| 43 | - * @since 1.0.0 |
|
| 44 | - * |
|
| 45 | - * @return object \lsx_health_plan\classes\frontend\Plan_Query() A single instance of this class. |
|
| 46 | - */ |
|
| 47 | - public static function get_instance() { |
|
| 48 | - // If the single instance hasn't been set, set it now. |
|
| 49 | - if ( null === self::$instance ) { |
|
| 50 | - self::$instance = new self(); |
|
| 51 | - } |
|
| 52 | - return self::$instance; |
|
| 53 | - } |
|
| 40 | + /** |
|
| 41 | + * Return an instance of this class. |
|
| 42 | + * |
|
| 43 | + * @since 1.0.0 |
|
| 44 | + * |
|
| 45 | + * @return object \lsx_health_plan\classes\frontend\Plan_Query() A single instance of this class. |
|
| 46 | + */ |
|
| 47 | + public static function get_instance() { |
|
| 48 | + // If the single instance hasn't been set, set it now. |
|
| 49 | + if ( null === self::$instance ) { |
|
| 50 | + self::$instance = new self(); |
|
| 51 | + } |
|
| 52 | + return self::$instance; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Undocumented function |
|
| 57 | - * |
|
| 58 | - * @return void |
|
| 59 | - */ |
|
| 60 | - public function query_sections( $plan_id = '' ) { |
|
| 61 | - if ( '' === $plan_id ) { |
|
| 62 | - $plan_id = get_the_ID(); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Undocumented function |
|
| 57 | + * |
|
| 58 | + * @return void |
|
| 59 | + */ |
|
| 60 | + public function query_sections( $plan_id = '' ) { |
|
| 61 | + if ( '' === $plan_id ) { |
|
| 62 | + $plan_id = get_the_ID(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $section_array = get_post_meta( $plan_id, 'plan_sections', true ); |
|
| 66 | - if ( ! empty( $section_array ) ) { |
|
| 67 | - $this->has_sections = true; |
|
| 68 | - $this->sections = $section_array; |
|
| 69 | - } |
|
| 70 | - return $this->has_sections; |
|
| 71 | - } |
|
| 65 | + $section_array = get_post_meta( $plan_id, 'plan_sections', true ); |
|
| 66 | + if ( ! empty( $section_array ) ) { |
|
| 67 | + $this->has_sections = true; |
|
| 68 | + $this->sections = $section_array; |
|
| 69 | + } |
|
| 70 | + return $this->has_sections; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function get_sections( $group = false ) { |
|
| 74 | - $sections = $this->sections; |
|
| 75 | - if ( false !== $group ) { |
|
| 76 | - $sections = $this->group_sections( $sections ); |
|
| 77 | - } |
|
| 78 | - return $sections; |
|
| 79 | - } |
|
| 73 | + public function get_sections( $group = false ) { |
|
| 74 | + $sections = $this->sections; |
|
| 75 | + if ( false !== $group ) { |
|
| 76 | + $sections = $this->group_sections( $sections ); |
|
| 77 | + } |
|
| 78 | + return $sections; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function get_section_count() { |
|
| 82 | - return count( $this->sections ); |
|
| 83 | - } |
|
| 81 | + public function get_section_count() { |
|
| 82 | + return count( $this->sections ); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * This will group the sections by their "Group" field. |
|
| 87 | - * |
|
| 88 | - * @param array $sections |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - public function group_sections( $sections = array() ) { |
|
| 92 | - $groups = array(); |
|
| 93 | - if ( ! empty( $sections ) ) { |
|
| 94 | - foreach ( $sections as $section_key => $section_values ) { |
|
| 95 | - $group_key = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) ); |
|
| 96 | - if ( isset( $section_values['group'] ) && '' !== $section_values['group'] ) { |
|
| 97 | - $group_key = $section_values['group']; |
|
| 98 | - } |
|
| 99 | - $group_key = sanitize_title( $group_key ); |
|
| 100 | - $groups[ $group_key ][ $section_key ] = $section_values; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - return $groups; |
|
| 104 | - } |
|
| 85 | + /** |
|
| 86 | + * This will group the sections by their "Group" field. |
|
| 87 | + * |
|
| 88 | + * @param array $sections |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + public function group_sections( $sections = array() ) { |
|
| 92 | + $groups = array(); |
|
| 93 | + if ( ! empty( $sections ) ) { |
|
| 94 | + foreach ( $sections as $section_key => $section_values ) { |
|
| 95 | + $group_key = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) ); |
|
| 96 | + if ( isset( $section_values['group'] ) && '' !== $section_values['group'] ) { |
|
| 97 | + $group_key = $section_values['group']; |
|
| 98 | + } |
|
| 99 | + $group_key = sanitize_title( $group_key ); |
|
| 100 | + $groups[ $group_key ][ $section_key ] = $section_values; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + return $groups; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -8,120 +8,120 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Frontend { |
| 10 | 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\Modals(); |
|
| 27 | - */ |
|
| 28 | - public $modals; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var object \lsx_health_plan\classes\frontend\Gallery(); |
|
| 32 | - */ |
|
| 33 | - public $gallery; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var object \lsx_health_plan\classes\frontend\Plan_Status(); |
|
| 37 | - */ |
|
| 38 | - public $plan_status; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var object \lsx_health_plan\classes\frontend\Plan_Query(); |
|
| 42 | - */ |
|
| 43 | - public $plan_query; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var object \lsx_health_plan\classes\frontend\General(); |
|
| 47 | - */ |
|
| 48 | - public $general; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var object \lsx_health_plan\classes\frontend\Template_Redirects(); |
|
| 52 | - */ |
|
| 53 | - public $template_redirects; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Contructor |
|
| 57 | - */ |
|
| 58 | - public function __construct() { |
|
| 59 | - if ( ! is_admin() ) { |
|
| 60 | - $this->load_classes(); |
|
| 61 | - add_action( 'template_redirect', array( $this, 'redirect' ) ); |
|
| 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\Modals(); |
|
| 27 | + */ |
|
| 28 | + public $modals; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var object \lsx_health_plan\classes\frontend\Gallery(); |
|
| 32 | + */ |
|
| 33 | + public $gallery; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var object \lsx_health_plan\classes\frontend\Plan_Status(); |
|
| 37 | + */ |
|
| 38 | + public $plan_status; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var object \lsx_health_plan\classes\frontend\Plan_Query(); |
|
| 42 | + */ |
|
| 43 | + public $plan_query; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var object \lsx_health_plan\classes\frontend\General(); |
|
| 47 | + */ |
|
| 48 | + public $general; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var object \lsx_health_plan\classes\frontend\Template_Redirects(); |
|
| 52 | + */ |
|
| 53 | + public $template_redirects; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Contructor |
|
| 57 | + */ |
|
| 58 | + public function __construct() { |
|
| 59 | + if ( ! is_admin() ) { |
|
| 60 | + $this->load_classes(); |
|
| 61 | + add_action( 'template_redirect', array( $this, 'redirect' ) ); |
|
| 62 | 62 | |
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Return an instance of this class. |
|
| 68 | - * |
|
| 69 | - * @since 1.0.0 |
|
| 70 | - * |
|
| 71 | - * @return object \lsx_health_plan\classes\Frontend() A single instance of this class. |
|
| 72 | - */ |
|
| 73 | - public static function get_instance() { |
|
| 74 | - // If the single instance hasn't been set, set it now. |
|
| 75 | - if ( null === self::$instance ) { |
|
| 76 | - self::$instance = new self(); |
|
| 77 | - } |
|
| 78 | - return self::$instance; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Loads the variable classes and the static classes. |
|
| 83 | - */ |
|
| 84 | - private function load_classes() { |
|
| 85 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-endpoints.php'; |
|
| 86 | - $this->endpoints = frontend\Endpoints::get_instance(); |
|
| 87 | - |
|
| 88 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-modals.php'; |
|
| 89 | - $this->modals = Modals::get_instance(); |
|
| 90 | - |
|
| 91 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-gallery.php'; |
|
| 92 | - $this->gallery = frontend\Gallery::get_instance(); |
|
| 93 | - |
|
| 94 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-plan-status.php'; |
|
| 95 | - $this->plan_status = frontend\Plan_Status::get_instance(); |
|
| 96 | - |
|
| 97 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-plan-query.php'; |
|
| 98 | - $this->plan_query = frontend\Plan_Query::get_instance(); |
|
| 99 | - |
|
| 100 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-general.php'; |
|
| 101 | - $this->general = frontend\General::get_instance(); |
|
| 102 | - |
|
| 103 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-template-redirects.php'; |
|
| 104 | - $this->template_redirects = frontend\Template_Redirects::get_instance(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Redirect the user from the cart or checkout page if they have purchased the product already. |
|
| 109 | - * |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function redirect() { |
|
| 113 | - if ( ! is_user_logged_in() || ! function_exists( 'wc_get_page_id' ) || is_home() ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - if ( lsx_health_plan_user_has_purchase() && ( is_page( wc_get_page_id( 'cart' ) ) || is_page( wc_get_page_id( 'checkout' ) ) ) ) { |
|
| 117 | - wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
| 118 | - die; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
| 122 | - if ( false !== $product_id && is_single( $product_id ) ) { |
|
| 123 | - wp_redirect( home_url() ); |
|
| 124 | - wp_die(); |
|
| 125 | - } |
|
| 126 | - } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Return an instance of this class. |
|
| 68 | + * |
|
| 69 | + * @since 1.0.0 |
|
| 70 | + * |
|
| 71 | + * @return object \lsx_health_plan\classes\Frontend() A single instance of this class. |
|
| 72 | + */ |
|
| 73 | + public static function get_instance() { |
|
| 74 | + // If the single instance hasn't been set, set it now. |
|
| 75 | + if ( null === self::$instance ) { |
|
| 76 | + self::$instance = new self(); |
|
| 77 | + } |
|
| 78 | + return self::$instance; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Loads the variable classes and the static classes. |
|
| 83 | + */ |
|
| 84 | + private function load_classes() { |
|
| 85 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-endpoints.php'; |
|
| 86 | + $this->endpoints = frontend\Endpoints::get_instance(); |
|
| 87 | + |
|
| 88 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-modals.php'; |
|
| 89 | + $this->modals = Modals::get_instance(); |
|
| 90 | + |
|
| 91 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-gallery.php'; |
|
| 92 | + $this->gallery = frontend\Gallery::get_instance(); |
|
| 93 | + |
|
| 94 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-plan-status.php'; |
|
| 95 | + $this->plan_status = frontend\Plan_Status::get_instance(); |
|
| 96 | + |
|
| 97 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-plan-query.php'; |
|
| 98 | + $this->plan_query = frontend\Plan_Query::get_instance(); |
|
| 99 | + |
|
| 100 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-general.php'; |
|
| 101 | + $this->general = frontend\General::get_instance(); |
|
| 102 | + |
|
| 103 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-template-redirects.php'; |
|
| 104 | + $this->template_redirects = frontend\Template_Redirects::get_instance(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Redirect the user from the cart or checkout page if they have purchased the product already. |
|
| 109 | + * |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function redirect() { |
|
| 113 | + if ( ! is_user_logged_in() || ! function_exists( 'wc_get_page_id' ) || is_home() ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + if ( lsx_health_plan_user_has_purchase() && ( is_page( wc_get_page_id( 'cart' ) ) || is_page( wc_get_page_id( 'checkout' ) ) ) ) { |
|
| 117 | + wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
| 118 | + die; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
| 122 | + if ( false !== $product_id && is_single( $product_id ) ) { |
|
| 123 | + wp_redirect( home_url() ); |
|
| 124 | + wp_die(); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | } |