-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExpired_License.php
119 lines (104 loc) · 2.71 KB
/
Expired_License.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace harmonypay;
/**
@brief Class for handling expired license notifications and dismissals.
@since 2019-11-15 21:09:24
**/
class Expired_License
{
/**
@brief Add a notification for this ID.
@since 2019-11-15 21:11:27
**/
public function add( $notification_id )
{
$dismissals = $this->dismissals();
// Do we know about it already?
if ( isset( $dismissals[ $notification_id ] ) )
return;
$dismissals[ $notification_id ] = false;
$this->save_dismissals( $dismissals );
}
/**
@brief Dismiss a notification.
@since 2019-11-15 21:10:51
**/
public function dismiss( $notification_id )
{
}
/**
@brief Return an array of the dismissals.
@since 2019-11-15 21:12:24
**/
public function dismissals()
{
return HarmonyPay()->get_site_option( 'expired_license_nag_dismissals' );
}
/**
@brief Return the dismissal key for this notification ID.
@since 2019-11-15 22:13:09
**/
public function get_dismissal_key( $notification_id )
{
$key = md5( AUTH_SALT . $notification_id . 'hrp_dismiss_notification' );
$key = substr( $key, 0, 8 );
return $key;
}
/**
@brief Check the URL for any dismissal actions.
@since 2019-11-15 22:07:43
**/
public function maybe_dismiss()
{
$dismissals = $this->dismissals();
$save = false;
foreach( $dismissals as $dismissal => $dismissed )
{
if ( $dismissed )
continue;
$key = $this->get_dismissal_key( $dismissal );
if ( ! isset( $_GET[ 'hrp_dismiss_notification' ] ) )
continue;
if ( $_GET[ 'hrp_dismiss_notification' ] != $key )
continue;
$dismissals[ $dismissal ] = time();
$save = true;
}
if ( $save )
$this->save_dismissals( $dismissals );
}
/**
@brief Save the dismissals option.
@since 2019-11-15 21:15:02
**/
public function save_dismissals( $dismissals )
{
return HarmonyPay()->update_site_option( 'expired_license_nag_dismissals', $dismissals );
}
/**
@brief Show all necessary expired license notifications to the admin.
@since 2019-11-15 21:10:17
**/
public function show()
{
$this->maybe_dismiss();
$dismissals = $this->dismissals();
foreach( $dismissals as $dismissal => $dismissed )
{
if ( $dismissed )
continue;
$key = $this->get_dismissal_key( $dismissal );
add_action( 'admin_notices', function() use ( $key )
{
$class = 'notice notice-warning';
$message = sprintf( 'Your HarmonyPay license has expired! If you wish to renew it, please visit your <a href="options-general.php?page=harmonypay">account settings</a>. Or you can <a href="%s">dismiss this notice</a>.',
add_query_arg( 'hrp_dismiss_notification', $key )
);
printf( '<div class="%1$s"><p>%2$s</p></div>',
esc_attr( $class ),
$message
);
} );
}
}
}