-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWcpUserUtils.php
108 lines (100 loc) · 3.47 KB
/
WcpUserUtils.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
<?php
/*[pro strip-from="lite"]*/
namespace WebSharks\ZenCache\Pro;
/*
* Clears cache files associated with a particular user.
*
* @since 150422 Rewrite.
*
* @attaches-to `profile_update` hook.
* @attaches-to `add_user_metadata` filter.
* @attaches-to `update_user_metadata` filter.
* @attaches-to `delete_user_metadata` filter.
* @attaches-to `set_auth_cookie` hook.
* @attaches-to `clear_auth_cookie` hook.
*
* @param int $user_id A WordPress user ID.
*
* @return int Total files cleared.
*/
$self->autoClearUserCache = function ($user_id) use ($self) {
$counter = 0; // Initialize.
if (!($user_id = (integer) $user_id)) {
return $counter; // Nothing to do.
}
if (!is_null($done = &$self->cacheKey('autoClearUserCache', $user_id))) {
return $counter; // Already did this.
}
$done = true; // Flag as having been done.
if (!$self->options['enable']) {
return $counter; // Nothing to do.
}
if ($self->options['when_logged_in'] !== 'postload') {
return $counter; // Nothing to do.
}
$regex = $self->assembleCachePathRegex('', '.*?\.u\/'.preg_quote($user_id, '/').'[.\/]');
$counter += $self->wipeFilesFromCacheDir($regex); // Clear matching files.
if ($counter && is_admin() && (!IS_PRO || $self->options['change_notifications_enable'])) {
$self->enqueueNotice('<img src="'.esc_attr($self->url('/src/client-s/images/clear.png')).'" style="float:left; margin:0 10px 0 0; border:0;" />'.
sprintf(__('<strong>%1$s:</strong> detected changes. Found %2$s in the cache for user ID: <code>%3$s</code>; auto-clearing.', SLUG_TD), esc_html(NAME), esc_html($self->i18nFiles($counter)), esc_html($user_id)));
}
return $counter;
};
$self->auto_clear_user_cache = $self->autoClearUserCache; // Back compat.
/*
* Automatically clears cache files associated with a particular user.
*
* @since 150422 Rewrite.
*
* @attaches-to `profile_update` hook.
*
* @param int $user_id A WordPress user ID.
*/
$self->autoClearUserCacheA1 = function ($user_id) use ($self) {
$self->autoClearUserCache($user_id);
};
/*
* Automatically clears cache files associated with a particular user.
*
* @since 150422 Rewrite.
*
* @attaches-to `add_user_metadata` filter.
* @attaches-to `update_user_metadata` filter.
* @attaches-to `delete_user_metadata` filter.
*
* @param mixed $value Filter value (passes through).
* @param int $user_id A WordPress user ID.
*
* @return mixed The same `$value` (passes through).
*/
$self->autoClearUserCacheFA2 = function ($value, $user_id) use ($self) {
$self->autoClearUserCache($user_id);
return $value; // Filter.
};
/*
* Automatically clears cache files associated with a particular user.
*
* @since 150422 Rewrite.
*
* @attaches-to `set_auth_cookie` hook.
*
* @param mixed $_ Irrelevant hook argument value.
* @param mixed $__ Irrelevant hook argument value.
* @param mixed $___ Irrelevant hook argument value.
* @param int $user_id A WordPress user ID.
*/
$self->autoClearUserCacheA4 = function ($_, $__, $___, $user_id) use ($self) {
$self->autoClearUserCache($user_id);
};
/*
* Automatically clears cache files associated with current user.
*
* @since 150422 Rewrite.
*
* @attaches-to `clear_auth_cookie` hook.
*/
$self->autoClearUserCacheCur = function () use ($self) {
$self->autoClearUserCache(get_current_user_id());
};
$self->auto_clear_user_cache_cur = $self->autoClearUserCacheCur; // Back compat.
/*[/pro]*/