1 | <?php |
||||
2 | /* |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
3 | * Plugin Name: LSX Health Plan |
||||
4 | * Plugin URI: https://github.com/lightspeeddevelopment/lsx-health-plan |
||||
5 | * Description: LSX Health Plan extension adds a meal and workout plan, with recipes. |
||||
6 | * Author: LightSpeed |
||||
7 | * Version: 1.4.0 |
||||
8 | * Author URI: https://www.lsdev.biz/ |
||||
9 | * License: GPL3 |
||||
10 | * Text Domain: lsx-health-plan |
||||
11 | * Domain Path: /languages/ |
||||
12 | */ |
||||
13 | |||||
14 | // If this file is called directly, abort. |
||||
15 | if ( ! defined( 'WPINC' ) ) { |
||||
0 ignored issues
–
show
|
|||||
16 | die; |
||||
17 | } |
||||
0 ignored issues
–
show
|
|||||
18 | define( 'LSX_HEALTH_PLAN_PATH', plugin_dir_path( __FILE__ ) ); |
||||
19 | define( 'LSX_HEALTH_PLAN_CORE', __FILE__ ); |
||||
20 | define( 'LSX_HEALTH_PLAN_URL', plugin_dir_url( __FILE__ ) ); |
||||
21 | define( 'LSX_HEALTH_PLAN_VER', '1.4.0' ); |
||||
22 | |||||
23 | /* ======================= Below is the Plugin Class init ========================= */ |
||||
24 | |||||
25 | require_once LSX_HEALTH_PLAN_PATH . '/classes/class-core.php'; |
||||
26 | |||||
27 | /** |
||||
28 | * Remove unnecessary custom post types |
||||
29 | * |
||||
30 | * @return void |
||||
31 | */ |
||||
32 | function lsx_remove_extra_meta_box() { |
||||
0 ignored issues
–
show
|
|||||
33 | global $wp_meta_boxes; |
||||
34 | $all_post_types = [ 'plan', 'video', 'workout', 'tip', 'recipe', 'meal' ]; |
||||
0 ignored issues
–
show
|
|||||
35 | //remove_meta_box( 'wpseo_meta', $all_post_types, 'normal' ); |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
36 | remove_meta_box( 'commentsdiv', $all_post_types, 'normal' ); |
||||
37 | remove_meta_box( 'commentstatusdiv', $all_post_types, 'normal' ); |
||||
38 | remove_meta_box( 'lsx_blocks_title_meta', $all_post_types, 'side' ); |
||||
39 | } |
||||
0 ignored issues
–
show
|
|||||
40 | add_action( 'add_meta_boxes', 'lsx_remove_extra_meta_box', 100 ); |
||||
41 | |||||
42 | /** |
||||
43 | * Create Login page with woocommerce shortcode if the page is not created |
||||
44 | */ |
||||
45 | if ( ( isset( $_GET['activated'] ) && function_exists( 'wp_verify_nonce' ) && wp_verify_nonce( sanitize_key( $_GET['activated'] ) ) ) && is_admin() ) { |
||||
0 ignored issues
–
show
|
|||||
46 | |||||
47 | $new_page_title = 'Login'; |
||||
48 | // Content to add spacing and woocommerce login shortcode |
||||
0 ignored issues
–
show
|
|||||
49 | $new_page_content = '<!-- wp:lsx-blocks/lsx-container {"containerMaxWidth":600} --> |
||||
50 | <div style="background-color:transparent;padding-left:3%;padding-right:3%;padding-bottom:3%;padding-top:3%;margin-top:3%;margin-bottom:3%" class="wp-block-lsx-blocks-lsx-container aligncenter lsx-block-container"><div class="lsx-container-inside"><div class="lsx-container-content" style="max-width:600px"><!-- wp:paragraph --> |
||||
51 | <p></p> |
||||
52 | <!-- /wp:paragraph --> |
||||
53 | |||||
54 | <!-- wp:shortcode --> |
||||
55 | [woocommerce_my_account] |
||||
56 | <!-- /wp:shortcode --></div></div></div> |
||||
57 | <!-- /wp:lsx-blocks/lsx-container -->'; |
||||
58 | $new_page_template = ''; |
||||
59 | |||||
60 | $page_check = get_page_by_title( $new_page_title ); |
||||
61 | $new_page = array( |
||||
62 | 'post_type' => 'page', |
||||
63 | 'post_title' => $new_page_title, |
||||
64 | 'post_content' => $new_page_content, |
||||
65 | 'post_status' => 'publish', |
||||
66 | 'post_author' => 1, |
||||
67 | ); |
||||
68 | if ( ! isset( $page_check->ID ) ) { |
||||
0 ignored issues
–
show
|
|||||
69 | $new_page_id = wp_insert_post( $new_page ); |
||||
70 | if ( ! empty( $new_page_template ) ) { |
||||
0 ignored issues
–
show
|
|||||
71 | update_post_meta( $new_page_id, '_wp_page_template', $new_page_template ); |
||||
72 | } |
||||
73 | } |
||||
74 | } |
||||
75 | |||||
76 | /** |
||||
77 | * Add Login Logout Button to Main Menu |
||||
78 | * |
||||
79 | * @param [type] $items |
||||
0 ignored issues
–
show
|
|||||
80 | * @param [type] $args |
||||
0 ignored issues
–
show
|
|||||
81 | * @return void |
||||
0 ignored issues
–
show
|
|||||
82 | */ |
||||
83 | function lsx_add_login_logout_register_menu( $items, $args ) { |
||||
0 ignored issues
–
show
|
|||||
84 | if ( 'primary' === $args->theme_location ) { |
||||
0 ignored issues
–
show
|
|||||
85 | ob_start(); |
||||
86 | wp_loginout( get_permalink() ); |
||||
0 ignored issues
–
show
It seems like
get_permalink() can also be of type false ; however, parameter $redirect of wp_loginout() 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
![]() |
|||||
87 | $loginoutlink = ob_get_contents(); |
||||
88 | ob_end_clean(); |
||||
89 | if ( ! is_user_logged_in() ) { |
||||
0 ignored issues
–
show
|
|||||
90 | $login_slug = \lsx_health_plan\functions\get_option( 'login_slug', false ); |
||||
91 | if ( false === $login_slug ) { |
||||
0 ignored issues
–
show
|
|||||
92 | $login_slug = 'login'; |
||||
93 | } |
||||
0 ignored issues
–
show
|
|||||
94 | $items .= '<li class="my-login menu-item"><a rel="nofollow" href="/' . $login_slug . '/">' . __( 'Login', 'lsx-health-plan' ) . '</a></li>'; |
||||
95 | } else { |
||||
96 | $items .= '<li class="my-login menu-item">' . $loginoutlink . '</li>'; |
||||
97 | } |
||||
0 ignored issues
–
show
|
|||||
98 | return $items; |
||||
99 | } else { |
||||
100 | return $items; |
||||
101 | } |
||||
102 | } |
||||
0 ignored issues
–
show
|
|||||
103 | add_filter( 'wp_nav_menu_items', 'lsx_add_login_logout_register_menu', 199, 2 ); |
||||
104 | |||||
105 | /** |
||||
106 | * Redirect user after login or redirect |
||||
107 | * |
||||
108 | * @return void |
||||
0 ignored issues
–
show
|
|||||
109 | */ |
||||
110 | function lsx_login_redirect() { |
||||
0 ignored issues
–
show
|
|||||
111 | $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
||||
112 | if ( false === $plan_slug ) { |
||||
0 ignored issues
–
show
|
|||||
113 | $plan_slug = 'my-plan'; |
||||
114 | } |
||||
0 ignored issues
–
show
|
|||||
115 | return home_url( $plan_slug ); |
||||
116 | } |
||||
0 ignored issues
–
show
|
|||||
117 | add_filter( 'woocommerce_login_redirect', 'lsx_login_redirect' ); |
||||
118 | |||||
119 | /** |
||||
120 | * Undocumented function |
||||
121 | * |
||||
122 | * @return object lsx_health_plan\classes\Core::get_instance(); |
||||
123 | */ |
||||
124 | function lsx_health_plan() { |
||||
0 ignored issues
–
show
|
|||||
125 | return \lsx_health_plan\classes\Core::get_instance(); |
||||
126 | } |
||||
0 ignored issues
–
show
|
|||||
127 | lsx_health_plan(); |
||||
128 | |||||
129 | /** |
||||
0 ignored issues
–
show
|
|||||
130 | * Creates the svg path |
||||
131 | * |
||||
132 | * @return void |
||||
0 ignored issues
–
show
|
|||||
133 | */ |
||||
134 | function lsx_get_svg_icon( $icon ) { |
||||
0 ignored issues
–
show
|
|||||
135 | $path = '/assets/images/'; |
||||
136 | |||||
137 | if ( file_exists( LSX_HEALTH_PLAN_PATH . $path . $icon ) ) { |
||||
0 ignored issues
–
show
|
|||||
138 | // Load and return the contents of the file |
||||
0 ignored issues
–
show
|
|||||
139 | return include LSX_HEALTH_PLAN_PATH . $path . $icon; |
||||
140 | } |
||||
141 | |||||
142 | // Return a blank string if we can't find the file. |
||||
143 | return ''; |
||||
144 | } |
||||
0 ignored issues
–
show
|
|||||
145 | |||||
146 | /** |
||||
0 ignored issues
–
show
|
|||||
147 | * Workout Snacks |
||||
148 | * |
||||
149 | * @return void |
||||
150 | */ |
||||
151 | function lsx_workout_snacks( $snack ) { |
||||
152 | $workout_snack = get_post_meta( get_the_ID(), $snack . '_workout_snack', 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
![]() |
|||||
153 | if ( ! empty( $workout_snack ) ) { |
||||
0 ignored issues
–
show
|
|||||
154 | ?> |
||||
155 | <div class="<?php echo esc_html( $snack ); ?>-workout workout-snacks"> |
||||
156 | <div class="content-box"> |
||||
157 | <?php |
||||
158 | $snack_title = ucfirst( $snack ); |
||||
159 | if ( 'pre' === $snack ) { |
||||
0 ignored issues
–
show
|
|||||
160 | /* Translators: %s: snack */ |
||||
161 | $title_text = esc_attr_x( 'Pre-Workout Snack', 'pre workout', 'lsx-health-plan' ); |
||||
162 | } else { |
||||
163 | /* Translators: %s: snack */ |
||||
164 | $title_text = esc_attr_x( 'Post-Workout Snack', 'post workout', 'lsx-health-plan' ); |
||||
165 | } |
||||
0 ignored issues
–
show
|
|||||
166 | $title = sprintf( $title_text, $snack_title ); |
||||
167 | ?> |
||||
168 | <h3 class="title-lined"><?php echo esc_html( $title ); ?></h3> |
||||
169 | <?php echo wp_kses_post( apply_filters( 'the_content', $workout_snack ) ); ?> |
||||
170 | </div> |
||||
171 | </div> |
||||
172 | <?php |
||||
173 | } |
||||
174 | } |
||||
0 ignored issues
–
show
|
|||||
175 |