Passed
Push — master ( 72b8be...029a1e )
by Warwick
05:55 queued 10s
created

lsx-health-plan.php (25 issues)

1
<?php
2
/*
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' ) ) {
16
	die;
17
}
18
define( 'LSX_HEALTH_PLAN_PATH', plugin_dir_path( __FILE__ ) );
0 ignored issues
show
The function plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
define( 'LSX_HEALTH_PLAN_PATH', /** @scrutinizer ignore-call */ plugin_dir_path( __FILE__ ) );
Loading history...
19
define( 'LSX_HEALTH_PLAN_CORE', __FILE__ );
20
define( 'LSX_HEALTH_PLAN_URL', plugin_dir_url( __FILE__ ) );
0 ignored issues
show
The function plugin_dir_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
define( 'LSX_HEALTH_PLAN_URL', /** @scrutinizer ignore-call */ plugin_dir_url( __FILE__ ) );
Loading history...
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() {
33
	global $wp_meta_boxes;
34
	$all_post_types = [ 'plan', 'video', 'workout', 'tip', 'recipe', 'meal' ];
35
	//remove_meta_box( 'wpseo_meta', $all_post_types, 'normal' );
36
	remove_meta_box( 'commentsdiv', $all_post_types, 'normal' );
0 ignored issues
show
The function remove_meta_box was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
	/** @scrutinizer ignore-call */ 
37
 remove_meta_box( 'commentsdiv', $all_post_types, 'normal' );
Loading history...
37
	remove_meta_box( 'commentstatusdiv', $all_post_types, 'normal' );
38
	remove_meta_box( 'lsx_blocks_title_meta', $all_post_types, 'side' );
39
}
40
add_action( 'add_meta_boxes', 'lsx_remove_extra_meta_box', 100 );
0 ignored issues
show
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
/** @scrutinizer ignore-call */ 
41
add_action( 'add_meta_boxes', 'lsx_remove_extra_meta_box', 100 );
Loading history...
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
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
if ( ( isset( $_GET['activated'] ) && function_exists( 'wp_verify_nonce' ) && wp_verify_nonce( /** @scrutinizer ignore-call */ sanitize_key( $_GET['activated'] ) ) ) && is_admin() ) {
Loading history...
The function is_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
if ( ( isset( $_GET['activated'] ) && function_exists( 'wp_verify_nonce' ) && wp_verify_nonce( sanitize_key( $_GET['activated'] ) ) ) && /** @scrutinizer ignore-call */ is_admin() ) {
Loading history...
46
47
	$new_page_title = 'Login';
48
	// Content to add spacing and woocommerce login shortcode
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 );
0 ignored issues
show
The function get_page_by_title was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
	$page_check = /** @scrutinizer ignore-call */ get_page_by_title( $new_page_title );
Loading history...
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 ) ) {
69
		$new_page_id = wp_insert_post( $new_page );
0 ignored issues
show
The function wp_insert_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
		$new_page_id = /** @scrutinizer ignore-call */ wp_insert_post( $new_page );
Loading history...
70
		if ( ! empty( $new_page_template ) ) {
0 ignored issues
show
The condition empty($new_page_template) is always true.
Loading history...
71
			update_post_meta( $new_page_id, '_wp_page_template', $new_page_template );
0 ignored issues
show
The function update_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
			/** @scrutinizer ignore-call */ 
72
   update_post_meta( $new_page_id, '_wp_page_template', $new_page_template );
Loading history...
72
		}
73
	}
74
}
75
76
/**
77
 * Add Login Logout Button to Main Menu
78
 *
79
 * @param [type] $items
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
80
 * @param [type] $args
81
 * @return void
82
 */
83
function lsx_add_login_logout_register_menu( $items, $args ) {
84
	if ( 'primary' === $args->theme_location ) {
85
		ob_start();
86
		wp_loginout( get_permalink() );
0 ignored issues
show
The function wp_loginout was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
		/** @scrutinizer ignore-call */ 
87
  wp_loginout( get_permalink() );
Loading history...
The function get_permalink was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
		wp_loginout( /** @scrutinizer ignore-call */ get_permalink() );
Loading history...
87
		$loginoutlink = ob_get_contents();
88
		ob_end_clean();
89
		if ( ! is_user_logged_in() ) {
0 ignored issues
show
The function is_user_logged_in was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
		if ( ! /** @scrutinizer ignore-call */ is_user_logged_in() ) {
Loading history...
90
			$login_slug = \lsx_health_plan\functions\get_option( 'login_slug', false );
91
			if ( false === $login_slug ) {
92
				$login_slug = 'login';
93
			}
94
			$items .= '<li class="my-login menu-item"><a rel="nofollow" href="/' . $login_slug . '/">' . __( 'Login', 'lsx-health-plan' ) . '</a></li>';
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
			$items .= '<li class="my-login menu-item"><a rel="nofollow" href="/' . $login_slug . '/">' . /** @scrutinizer ignore-call */ __( 'Login', 'lsx-health-plan' ) . '</a></li>';
Loading history...
95
		} else {
96
			$items .= '<li class="my-login menu-item">' . $loginoutlink . '</li>';
97
		}
98
		return $items;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $items returns the type string which is incompatible with the documented return type void.
Loading history...
99
	} else {
100
		return $items;
101
	}
102
}
103
add_filter( 'wp_nav_menu_items', 'lsx_add_login_logout_register_menu', 199, 2 );
0 ignored issues
show
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
/** @scrutinizer ignore-call */ 
104
add_filter( 'wp_nav_menu_items', 'lsx_add_login_logout_register_menu', 199, 2 );
Loading history...
104
105
/**
106
 * Redirect user after login or redirect
107
 *
108
 * @return void
109
 */
110
function lsx_login_redirect() {
111
	$plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false );
112
	if ( false === $plan_slug ) {
113
		$plan_slug = 'my-plan';
114
	}
115
	return home_url( $plan_slug );
0 ignored issues
show
The function home_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
	return /** @scrutinizer ignore-call */ home_url( $plan_slug );
Loading history...
116
}
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() {
125
	return \lsx_health_plan\classes\Core::get_instance();
126
}
127
lsx_health_plan();
128
129
/**
130
 * Creates the svg path
131
 *
132
 * @return void
133
 */
134
function lsx_get_svg_icon( $icon ) {
135
	$path = '/assets/images/';
136
137
	if ( file_exists( LSX_HEALTH_PLAN_PATH . $path . $icon ) ) {
138
		// Load and return the contents of the file
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 '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the documented return type void.
Loading history...
144
}
145
146
/**
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
The function get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

152
	$workout_snack = /** @scrutinizer ignore-call */ get_post_meta( get_the_ID(), $snack . '_workout_snack', true );
Loading history...
The function get_the_ID was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

152
	$workout_snack = get_post_meta( /** @scrutinizer ignore-call */ get_the_ID(), $snack . '_workout_snack', true );
Loading history...
153
	if ( ! empty( $workout_snack ) ) {
154
	?>
155
	<div class="<?php echo esc_html( $snack ); ?>-workout workout-snacks">
0 ignored issues
show
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

155
	<div class="<?php echo /** @scrutinizer ignore-call */ esc_html( $snack ); ?>-workout workout-snacks">
Loading history...
156
			<div class="content-box">
157
				<?php
158
				$snack_title = ucfirst( $snack );
159
				if ( 'pre' === $snack ) {
160
					/* Translators: %s: snack */
161
					$title_text = esc_attr_x( 'Pre-Workout Snack', 'pre workout', 'lsx-health-plan' );
0 ignored issues
show
The function esc_attr_x was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

161
					$title_text = /** @scrutinizer ignore-call */ esc_attr_x( 'Pre-Workout Snack', 'pre workout', 'lsx-health-plan' );
Loading history...
162
				} else {
163
					/* Translators: %s: snack */
164
					$title_text = esc_attr_x( 'Post-Workout Snack', 'post workout', 'lsx-health-plan' );
165
				}
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 ) ); ?>
0 ignored issues
show
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

169
				<?php echo wp_kses_post( /** @scrutinizer ignore-call */ apply_filters( 'the_content', $workout_snack ) ); ?>
Loading history...
The function wp_kses_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

169
				<?php echo /** @scrutinizer ignore-call */ wp_kses_post( apply_filters( 'the_content', $workout_snack ) ); ?>
Loading history...
170
			</div>
171
		</div>
172
	<?php
173
	}
174
}
175