|
1
|
|
|
<?php |
|
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
|
|
|
* Contructor |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct() { |
|
24
|
|
|
add_action( 'init', array( $this, 'handle_day_action' ), 100 ); |
|
25
|
|
|
} |
|
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 ) { |
|
37
|
|
|
self::$instance = new self(); |
|
38
|
|
|
} |
|
39
|
|
|
return self::$instance; |
|
40
|
|
|
} |
|
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' ) ) { |
|
47
|
|
|
update_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete', true ); |
|
48
|
|
|
$plan_id = sanitize_key( $_POST['lsx-health-plan-id'] ); |
|
49
|
|
|
$plan_parent = wp_get_post_parent_id( $plan_id ); |
|
|
|
|
|
|
50
|
|
|
if ( 0 !== $plan_parent ) { |
|
51
|
|
|
$plan_id = $plan_parent; |
|
52
|
|
|
} |
|
53
|
|
|
wp_safe_redirect( get_permalink( $plan_id ) ); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'unlock' ) ) { |
|
57
|
|
|
delete_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete' ); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|