Issues (4138)

classes/frontend/class-plan-status.php (28 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes\frontend;
3
4
/**
5
 * Holds the functionality to check and control your status with the current plan.
6
 *
7
 * @package lsx-health-plan
8
 */
9
class Plan_Status {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @var      object \lsx_health_plan\classes\frontend\Plan_Status()
17
	 */
18
	protected static $instance = null;
19
20
	/**
21
	 * Constructor
22
	 */
23
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
24
		add_action( 'init', array( $this, 'handle_day_action' ), 100 );
25
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
26
27
	/**
28
	 * Return an instance of this class.
29
	 *
30
	 * @since 1.0.0
31
	 *
32
	 * @return    object \lsx_health_plan\classes\frontend\Plan_Status()    A single instance of this class.
33
	 */
34
	public static function get_instance() {
35
		// If the single instance hasn't been set, set it now.
36
		if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
37
			self::$instance = new self();
38
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
39
		return self::$instance;
40
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
41
42
	/**
43
	 * Registers the rewrites.
44
	 */
45
	public function handle_day_action() {
46
		if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'complete' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
Detected usage of a non-sanitized input variable: $_POST['lsx-health-plan-actions']
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
47
			update_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete', true );
0 ignored issues
show
Detected usage of a possibly undefined superglobal array index: $_POST['lsx-health-plan-id']. Use isset() or empty() to check the index exists before using it
Loading history...
48
			$plan_id     = sanitize_key( $_POST['lsx-health-plan-id'] );
0 ignored issues
show
Detected usage of a possibly undefined superglobal array index: $_POST['lsx-health-plan-id']. Use isset() or empty() to check the index exists before using it
Loading history...
49
			$plan_parent = wp_get_post_parent_id( $plan_id );
0 ignored issues
show
$plan_id of type string is incompatible with the type WP_Post|integer|null expected by parameter $post of wp_get_post_parent_id(). ( Ignorable by Annotation )

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

49
			$plan_parent = wp_get_post_parent_id( /** @scrutinizer ignore-type */ $plan_id );
Loading history...
50
			if ( 0 !== $plan_parent ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
51
				$plan_id = $plan_parent;
52
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
53
			wp_safe_redirect( get_permalink( $plan_id ) );
0 ignored issues
show
It seems like get_permalink($plan_id) can also be of type false; however, parameter $location of wp_safe_redirect() 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

53
			wp_safe_redirect( /** @scrutinizer ignore-type */ get_permalink( $plan_id ) );
Loading history...
It seems like $plan_id can also be of type false and string; however, parameter $post of get_permalink() does only seem to accept WP_Post|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

53
			wp_safe_redirect( get_permalink( /** @scrutinizer ignore-type */ $plan_id ) );
Loading history...
54
		}
55
56
		if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'unlock' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
Detected usage of a non-sanitized input variable: $_POST['lsx-health-plan-actions']
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
57
			delete_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete' );
0 ignored issues
show
Detected usage of a possibly undefined superglobal array index: $_POST['lsx-health-plan-id']. Use isset() or empty() to check the index exists before using it
Loading history...
58
		}
59
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
60
}
61