Passed
Push — master ( ff4a98...d2efa5 )
by Warwick
04:51
created

lsx-health-plan.php (34 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__ ) );
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() {
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' );
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 );
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
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
46
47
	$new_page_title = 'Login';
48
	// Content to add spacing and woocommerce login shortcode
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
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
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
69
		$new_page_id = wp_insert_post( $new_page );
70
		if ( ! empty( $new_page_template ) ) {
0 ignored issues
show
The condition empty($new_page_template) is always true.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
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...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
80
 * @param [type] $args
81
 * @return void
82
 */
83
function lsx_add_login_logout_register_menu( $items, $args ) {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
84
	if ( 'primary' === $args->theme_location ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ignore-type  annotation

86
		wp_loginout( /** @scrutinizer ignore-type */ get_permalink() );
Loading history...
87
		$loginoutlink = ob_get_contents();
88
		ob_end_clean();
89
		if ( ! is_user_logged_in() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
90
			$login_slug = \lsx_health_plan\functions\get_option( 'login_slug', false );
91
			if ( false === $login_slug ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
92
				$login_slug = 'login';
93
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
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
No blank line found after control structure
Loading history...
98
		return $items;
99
	} else {
100
		return $items;
101
	}
102
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
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
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 );
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
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
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
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
145
146
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$snack" missing
Loading history...
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 ignore-type  annotation

152
	$workout_snack = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), $snack . '_workout_snack', true );
Loading history...
153
	if ( ! empty( $workout_snack ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
No blank line found after control structure
Loading history...
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
Expected 1 blank line before closing function brace; 0 found
Loading history...
175