author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core User API |
0 | 4 |
* |
5 |
* @package WordPress |
|
5 | 6 |
* @subpackage Users |
0 | 7 |
*/ |
8 |
||
9 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
* Authenticates and logs a user in with 'remember' capability. |
0 | 11 |
* |
12 |
* The credentials is an array that has 'user_login', 'user_password', and |
|
13 |
* 'remember' indices. If the credentials is not given, then the log in form |
|
14 |
* will be assumed and used if set. |
|
15 |
* |
|
16 |
* The various authentication cookies will be set by this function and will be |
|
17 |
* set for a longer period depending on if the 'remember' credential is set to |
|
18 |
* true. |
|
19 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* Note: wp_signon() doesn't handle setting the current user. This means that if the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* function is called before the {@see 'init'} hook is fired, is_user_logged_in() will |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* evaluate as false until that point. If is_user_logged_in() is needed in conjunction |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* with wp_signon(), wp_set_current_user() should be called explicitly. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* |
0 | 25 |
* @since 2.5.0 |
26 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* @global string $auth_secure_cookie |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
* @param array $credentials { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
* Optional. User info in order to sign on. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
* @type string $user_login Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
* @type string $user_password User password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
* @type bool $remember Whether to 'remember' the user. Increases the time |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
36 |
* that the cookie will be kept. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
37 |
* } |
5 | 38 |
* @param string|bool $secure_cookie Optional. Whether to use secure cookie. |
39 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
|
0 | 40 |
*/ |
5 | 41 |
function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
global $auth_secure_cookie, $wpdb; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
43 |
|
9 | 44 |
if ( empty( $credentials ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
45 |
$credentials = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
'user_login' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
'user_password' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
'remember' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
49 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
51 |
if ( ! empty( $_POST['log'] ) && is_string( $_POST['log'] ) ) { |
16 | 52 |
$credentials['user_login'] = wp_unslash( $_POST['log'] ); |
9 | 53 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
54 |
if ( ! empty( $_POST['pwd'] ) && is_string( $_POST['pwd'] ) ) { |
0 | 55 |
$credentials['user_password'] = $_POST['pwd']; |
9 | 56 |
} |
57 |
if ( ! empty( $_POST['rememberme'] ) ) { |
|
0 | 58 |
$credentials['remember'] = $_POST['rememberme']; |
9 | 59 |
} |
0 | 60 |
} |
61 |
||
9 | 62 |
if ( ! empty( $credentials['remember'] ) ) { |
0 | 63 |
$credentials['remember'] = true; |
9 | 64 |
} else { |
0 | 65 |
$credentials['remember'] = false; |
9 | 66 |
} |
0 | 67 |
|
5 | 68 |
/** |
69 |
* Fires before the user is authenticated. |
|
70 |
* |
|
71 |
* The variables passed to the callbacks are passed by reference, |
|
72 |
* and can be modified by callback functions. |
|
73 |
* |
|
74 |
* @since 1.5.1 |
|
75 |
* |
|
76 |
* @todo Decide whether to deprecate the wp_authenticate action. |
|
77 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
* @param string $user_login Username (passed by reference). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* @param string $user_password User password (passed by reference). |
5 | 80 |
*/ |
81 |
do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
|
0 | 82 |
|
9 | 83 |
if ( '' === $secure_cookie ) { |
0 | 84 |
$secure_cookie = is_ssl(); |
9 | 85 |
} |
0 | 86 |
|
5 | 87 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* Filters whether to use a secure sign-on cookie. |
5 | 89 |
* |
90 |
* @since 3.1.0 |
|
91 |
* |
|
92 |
* @param bool $secure_cookie Whether to use a secure sign-on cookie. |
|
93 |
* @param array $credentials { |
|
9 | 94 |
* Array of entered sign-on data. |
95 |
* |
|
96 |
* @type string $user_login Username. |
|
97 |
* @type string $user_password Password entered. |
|
5 | 98 |
* @type bool $remember Whether to 'remember' the user. Increases the time |
99 |
* that the cookie will be kept. Default false. |
|
9 | 100 |
* } |
5 | 101 |
*/ |
102 |
$secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
|
0 | 103 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
104 |
// XXX ugly hack to pass this to wp_authenticate_cookie(). |
0 | 105 |
$auth_secure_cookie = $secure_cookie; |
106 |
||
9 | 107 |
add_filter( 'authenticate', 'wp_authenticate_cookie', 30, 3 ); |
108 |
||
109 |
$user = wp_authenticate( $credentials['user_login'], $credentials['user_password'] ); |
|
110 |
||
111 |
if ( is_wp_error( $user ) ) { |
|
0 | 112 |
return $user; |
113 |
} |
|
114 |
||
9 | 115 |
wp_set_auth_cookie( $user->ID, $credentials['remember'], $secure_cookie ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
// Clear `user_activation_key` after a successful login. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
118 |
if ( ! empty( $user->user_activation_key ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
119 |
$wpdb->update( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
120 |
$wpdb->users, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
'user_activation_key' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
array( 'ID' => $user->ID ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
$user->user_activation_key = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
|
5 | 130 |
/** |
131 |
* Fires after the user has successfully logged in. |
|
132 |
* |
|
133 |
* @since 1.5.0 |
|
134 |
* |
|
135 |
* @param string $user_login Username. |
|
136 |
* @param WP_User $user WP_User object of the logged-in user. |
|
137 |
*/ |
|
138 |
do_action( 'wp_login', $user->user_login, $user ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
|
0 | 140 |
return $user; |
141 |
} |
|
142 |
||
143 |
/** |
|
19 | 144 |
* Authenticates a user, confirming the username and password are valid. |
5 | 145 |
* |
146 |
* @since 2.8.0 |
|
147 |
* |
|
148 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
|
149 |
* @param string $username Username for authentication. |
|
150 |
* @param string $password Password for authentication. |
|
151 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
|
0 | 152 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
153 |
function wp_authenticate_username_password( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
154 |
$user, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
155 |
$username, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
156 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
157 |
$password |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
158 |
) { |
5 | 159 |
if ( $user instanceof WP_User ) { |
160 |
return $user; |
|
161 |
} |
|
0 | 162 |
|
9 | 163 |
if ( empty( $username ) || empty( $password ) ) { |
164 |
if ( is_wp_error( $user ) ) { |
|
0 | 165 |
return $user; |
9 | 166 |
} |
0 | 167 |
|
168 |
$error = new WP_Error(); |
|
169 |
||
9 | 170 |
if ( empty( $username ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
$error->add( 'empty_username', __( '<strong>Error:</strong> The username field is empty.' ) ); |
9 | 172 |
} |
173 |
||
174 |
if ( empty( $password ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
$error->add( 'empty_password', __( '<strong>Error:</strong> The password field is empty.' ) ); |
9 | 176 |
} |
0 | 177 |
|
178 |
return $error; |
|
179 |
} |
|
180 |
||
9 | 181 |
$user = get_user_by( 'login', $username ); |
182 |
||
183 |
if ( ! $user ) { |
|
184 |
return new WP_Error( |
|
185 |
'invalid_username', |
|
18 | 186 |
sprintf( |
187 |
/* translators: %s: User name. */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
188 |
__( '<strong>Error:</strong> The username <strong>%s</strong> is not registered on this site. If you are unsure of your username, try your email address instead.' ), |
18 | 189 |
$username |
190 |
) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
} |
0 | 193 |
|
5 | 194 |
/** |
19 | 195 |
* Filters whether the given user can be authenticated with the provided password. |
5 | 196 |
* |
197 |
* @since 2.5.0 |
|
198 |
* |
|
199 |
* @param WP_User|WP_Error $user WP_User or WP_Error object if a previous |
|
200 |
* callback failed authentication. |
|
201 |
* @param string $password Password to check against the user. |
|
202 |
*/ |
|
203 |
$user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
9 | 204 |
if ( is_wp_error( $user ) ) { |
0 | 205 |
return $user; |
9 | 206 |
} |
0 | 207 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
208 |
$valid = wp_check_password( $password, $user->user_pass, $user->ID ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
209 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
210 |
if ( ! $valid ) { |
9 | 211 |
return new WP_Error( |
212 |
'incorrect_password', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
sprintf( |
16 | 214 |
/* translators: %s: User name. */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
215 |
__( '<strong>Error:</strong> The password you entered for the username %s is incorrect.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
'<strong>' . $username . '</strong>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
' <a href="' . wp_lostpassword_url() . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
__( 'Lost your password?' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
'</a>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
224 |
if ( wp_password_needs_rehash( $user->user_pass, $user->ID ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
225 |
wp_set_password( $password, $user->ID ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
226 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
227 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
* Authenticates a user using the email and password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object if a previous |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* callback failed authentication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* @param string $email Email address for authentication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* @param string $password Password for authentication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
242 |
function wp_authenticate_email_password( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
243 |
$user, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
244 |
$email, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
245 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
246 |
$password |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
247 |
) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
if ( $user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
if ( empty( $email ) || empty( $password ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
if ( is_wp_error( $user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
$error = new WP_Error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
if ( empty( $email ) ) { |
16 | 260 |
// Uses 'empty_username' for back-compat with wp_signon(). |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
$error->add( 'empty_username', __( '<strong>Error:</strong> The email field is empty.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
if ( empty( $password ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
$error->add( 'empty_password', __( '<strong>Error:</strong> The password field is empty.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
if ( ! is_email( $email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
$user = get_user_by( 'email', $email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
if ( ! $user ) { |
9 | 278 |
return new WP_Error( |
279 |
'invalid_email', |
|
16 | 280 |
__( 'Unknown email address. Check again or try your username.' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
/** This filter is documented in wp-includes/user.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
$user = apply_filters( 'wp_authenticate_user', $user, $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
if ( is_wp_error( $user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
291 |
$valid = wp_check_password( $password, $user->user_pass, $user->ID ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
292 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
293 |
if ( ! $valid ) { |
9 | 294 |
return new WP_Error( |
295 |
'incorrect_password', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
sprintf( |
16 | 297 |
/* translators: %s: Email address. */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
__( '<strong>Error:</strong> The password you entered for the email address %s is incorrect.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
'<strong>' . $email . '</strong>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
' <a href="' . wp_lostpassword_url() . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
__( 'Lost your password?' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
'</a>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
} |
0 | 306 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
307 |
if ( wp_password_needs_rehash( $user->user_pass, $user->ID ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
308 |
wp_set_password( $password, $user->ID ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
309 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
310 |
|
0 | 311 |
return $user; |
312 |
} |
|
313 |
||
314 |
/** |
|
19 | 315 |
* Authenticates the user using the WordPress auth cookie. |
5 | 316 |
* |
317 |
* @since 2.8.0 |
|
318 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* @global string $auth_secure_cookie |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* |
5 | 321 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
322 |
* @param string $username Username. If not empty, cancels the cookie authentication. |
|
323 |
* @param string $password Password. If not empty, cancels the cookie authentication. |
|
324 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
|
0 | 325 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
326 |
function wp_authenticate_cookie( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
327 |
$user, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
328 |
$username, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
329 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
330 |
$password |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
331 |
) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
global $auth_secure_cookie; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
|
5 | 334 |
if ( $user instanceof WP_User ) { |
335 |
return $user; |
|
336 |
} |
|
0 | 337 |
|
9 | 338 |
if ( empty( $username ) && empty( $password ) ) { |
0 | 339 |
$user_id = wp_validate_auth_cookie(); |
9 | 340 |
if ( $user_id ) { |
341 |
return new WP_User( $user_id ); |
|
342 |
} |
|
0 | 343 |
|
9 | 344 |
if ( $auth_secure_cookie ) { |
0 | 345 |
$auth_cookie = SECURE_AUTH_COOKIE; |
9 | 346 |
} else { |
0 | 347 |
$auth_cookie = AUTH_COOKIE; |
9 | 348 |
} |
349 |
||
350 |
if ( ! empty( $_COOKIE[ $auth_cookie ] ) ) { |
|
351 |
return new WP_Error( 'expired_session', __( 'Please log in again.' ) ); |
|
352 |
} |
|
0 | 353 |
|
354 |
// If the cookie is not set, be silent. |
|
355 |
} |
|
356 |
||
357 |
return $user; |
|
358 |
} |
|
359 |
||
360 |
/** |
|
18 | 361 |
* Authenticates the user using an application password. |
362 |
* |
|
363 |
* @since 5.6.0 |
|
364 |
* |
|
365 |
* @param WP_User|WP_Error|null $input_user WP_User or WP_Error object if a previous |
|
366 |
* callback failed authentication. |
|
367 |
* @param string $username Username for authentication. |
|
368 |
* @param string $password Password for authentication. |
|
369 |
* @return WP_User|WP_Error|null WP_User on success, WP_Error on failure, null if |
|
370 |
* null is passed in and this isn't an API request. |
|
371 |
*/ |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
372 |
function wp_authenticate_application_password( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
373 |
$input_user, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
374 |
$username, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
375 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
376 |
$password |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
377 |
) { |
18 | 378 |
if ( $input_user instanceof WP_User ) { |
379 |
return $input_user; |
|
380 |
} |
|
381 |
||
382 |
if ( ! WP_Application_Passwords::is_in_use() ) { |
|
383 |
return $input_user; |
|
384 |
} |
|
385 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
386 |
// The 'REST_REQUEST' check here may happen too early for the constant to be available. |
18 | 387 |
$is_api_request = ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ); |
388 |
||
389 |
/** |
|
390 |
* Filters whether this is an API request that Application Passwords can be used on. |
|
391 |
* |
|
392 |
* By default, Application Passwords is available for the REST API and XML-RPC. |
|
393 |
* |
|
394 |
* @since 5.6.0 |
|
395 |
* |
|
396 |
* @param bool $is_api_request If this is an acceptable API request. |
|
397 |
*/ |
|
398 |
$is_api_request = apply_filters( 'application_password_is_api_request', $is_api_request ); |
|
399 |
||
400 |
if ( ! $is_api_request ) { |
|
401 |
return $input_user; |
|
402 |
} |
|
403 |
||
404 |
$error = null; |
|
405 |
$user = get_user_by( 'login', $username ); |
|
406 |
||
407 |
if ( ! $user && is_email( $username ) ) { |
|
408 |
$user = get_user_by( 'email', $username ); |
|
409 |
} |
|
410 |
||
411 |
// If the login name is invalid, short circuit. |
|
412 |
if ( ! $user ) { |
|
413 |
if ( is_email( $username ) ) { |
|
414 |
$error = new WP_Error( |
|
415 |
'invalid_email', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
__( '<strong>Error:</strong> Unknown email address. Check again or try your username.' ) |
18 | 417 |
); |
418 |
} else { |
|
419 |
$error = new WP_Error( |
|
420 |
'invalid_username', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
__( '<strong>Error:</strong> Unknown username. Check again or try your email address.' ) |
18 | 422 |
); |
423 |
} |
|
424 |
} elseif ( ! wp_is_application_passwords_available() ) { |
|
425 |
$error = new WP_Error( |
|
426 |
'application_passwords_disabled', |
|
427 |
__( 'Application passwords are not available.' ) |
|
428 |
); |
|
429 |
} elseif ( ! wp_is_application_passwords_available_for_user( $user ) ) { |
|
430 |
$error = new WP_Error( |
|
431 |
'application_passwords_disabled_for_user', |
|
432 |
__( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' ) |
|
433 |
); |
|
434 |
} |
|
435 |
||
436 |
if ( $error ) { |
|
437 |
/** |
|
438 |
* Fires when an application password failed to authenticate the user. |
|
439 |
* |
|
440 |
* @since 5.6.0 |
|
441 |
* |
|
442 |
* @param WP_Error $error The authentication error. |
|
443 |
*/ |
|
444 |
do_action( 'application_password_failed_authentication', $error ); |
|
445 |
||
446 |
return $error; |
|
447 |
} |
|
448 |
||
449 |
/* |
|
19 | 450 |
* Strips out anything non-alphanumeric. This is so passwords can be used with |
18 | 451 |
* or without spaces to indicate the groupings for readability. |
452 |
* |
|
453 |
* Generated application passwords are exclusively alphanumeric. |
|
454 |
*/ |
|
455 |
$password = preg_replace( '/[^a-z\d]/i', '', $password ); |
|
456 |
||
457 |
$hashed_passwords = WP_Application_Passwords::get_user_application_passwords( $user->ID ); |
|
458 |
||
459 |
foreach ( $hashed_passwords as $key => $item ) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
460 |
if ( ! WP_Application_Passwords::check_password( $password, $item['password'] ) ) { |
18 | 461 |
continue; |
462 |
} |
|
463 |
||
464 |
$error = new WP_Error(); |
|
465 |
||
466 |
/** |
|
467 |
* Fires when an application password has been successfully checked as valid. |
|
468 |
* |
|
469 |
* This allows for plugins to add additional constraints to prevent an application password from being used. |
|
470 |
* |
|
471 |
* @since 5.6.0 |
|
472 |
* |
|
473 |
* @param WP_Error $error The error object. |
|
474 |
* @param WP_User $user The user authenticating. |
|
475 |
* @param array $item The details about the application password. |
|
476 |
* @param string $password The raw supplied password. |
|
477 |
*/ |
|
478 |
do_action( 'wp_authenticate_application_password_errors', $error, $user, $item, $password ); |
|
479 |
||
480 |
if ( is_wp_error( $error ) && $error->has_errors() ) { |
|
481 |
/** This action is documented in wp-includes/user.php */ |
|
482 |
do_action( 'application_password_failed_authentication', $error ); |
|
483 |
||
484 |
return $error; |
|
485 |
} |
|
486 |
||
487 |
WP_Application_Passwords::record_application_password_usage( $user->ID, $item['uuid'] ); |
|
488 |
||
489 |
/** |
|
490 |
* Fires after an application password was used for authentication. |
|
491 |
* |
|
492 |
* @since 5.6.0 |
|
493 |
* |
|
494 |
* @param WP_User $user The user who was authenticated. |
|
495 |
* @param array $item The application password used. |
|
496 |
*/ |
|
497 |
do_action( 'application_password_did_authenticate', $user, $item ); |
|
498 |
||
499 |
return $user; |
|
500 |
} |
|
501 |
||
502 |
$error = new WP_Error( |
|
503 |
'incorrect_password', |
|
504 |
__( 'The provided password is an invalid application password.' ) |
|
505 |
); |
|
506 |
||
507 |
/** This action is documented in wp-includes/user.php */ |
|
508 |
do_action( 'application_password_failed_authentication', $error ); |
|
509 |
||
510 |
return $error; |
|
511 |
} |
|
512 |
||
513 |
/** |
|
514 |
* Validates the application password credentials passed via Basic Authentication. |
|
515 |
* |
|
516 |
* @since 5.6.0 |
|
517 |
* |
|
518 |
* @param int|false $input_user User ID if one has been determined, false otherwise. |
|
519 |
* @return int|false The authenticated user ID if successful, false otherwise. |
|
520 |
*/ |
|
521 |
function wp_validate_application_password( $input_user ) { |
|
522 |
// Don't authenticate twice. |
|
523 |
if ( ! empty( $input_user ) ) { |
|
524 |
return $input_user; |
|
525 |
} |
|
526 |
||
527 |
if ( ! wp_is_application_passwords_available() ) { |
|
528 |
return $input_user; |
|
529 |
} |
|
530 |
||
531 |
// Both $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] must be set in order to attempt authentication. |
|
532 |
if ( ! isset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ) ) { |
|
533 |
return $input_user; |
|
534 |
} |
|
535 |
||
536 |
$authenticated = wp_authenticate_application_password( null, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ); |
|
537 |
||
538 |
if ( $authenticated instanceof WP_User ) { |
|
539 |
return $authenticated->ID; |
|
540 |
} |
|
541 |
||
542 |
// If it wasn't a user what got returned, just pass on what we had received originally. |
|
543 |
return $input_user; |
|
544 |
} |
|
545 |
||
546 |
/** |
|
19 | 547 |
* For Multisite blogs, checks if the authenticated user has been marked as a |
0 | 548 |
* spammer, or if the user's primary blog has been marked as spam. |
549 |
* |
|
550 |
* @since 3.7.0 |
|
5 | 551 |
* |
552 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
|
553 |
* @return WP_User|WP_Error WP_User on success, WP_Error if the user is considered a spammer. |
|
0 | 554 |
*/ |
555 |
function wp_authenticate_spam_check( $user ) { |
|
5 | 556 |
if ( $user instanceof WP_User && is_multisite() ) { |
557 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
* Filters whether the user has been marked as a spammer. |
5 | 559 |
* |
560 |
* @since 3.7.0 |
|
561 |
* |
|
562 |
* @param bool $spammed Whether the user is considered a spammer. |
|
563 |
* @param WP_User $user User to check against. |
|
564 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
$spammed = apply_filters( 'check_is_user_spammed', is_user_spammy( $user ), $user ); |
0 | 566 |
|
9 | 567 |
if ( $spammed ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
568 |
return new WP_Error( 'spammer_account', __( '<strong>Error:</strong> Your account has been marked as a spammer.' ) ); |
9 | 569 |
} |
0 | 570 |
} |
571 |
return $user; |
|
572 |
} |
|
573 |
||
574 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
* Validates the logged-in cookie. |
5 | 576 |
* |
577 |
* Checks the logged-in cookie if the previous auth cookie could not be |
|
578 |
* validated and parsed. |
|
579 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
* This is a callback for the {@see 'determine_current_user'} filter, rather than API. |
5 | 581 |
* |
582 |
* @since 3.9.0 |
|
583 |
* |
|
18 | 584 |
* @param int|false $user_id The user ID (or false) as received from |
585 |
* the `determine_current_user` filter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* @return int|false User ID if validated, false otherwise. If a user ID from |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* an earlier filter callback is received, that value is returned. |
5 | 588 |
*/ |
589 |
function wp_validate_logged_in_cookie( $user_id ) { |
|
590 |
if ( $user_id ) { |
|
591 |
return $user_id; |
|
592 |
} |
|
593 |
||
9 | 594 |
if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { |
5 | 595 |
return false; |
596 |
} |
|
597 |
||
9 | 598 |
return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' ); |
5 | 599 |
} |
600 |
||
601 |
/** |
|
19 | 602 |
* Gets the number of posts a user has written. |
0 | 603 |
* |
604 |
* @since 3.0.0 |
|
5 | 605 |
* @since 4.1.0 Added `$post_type` argument. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* of post types to `$post_type`. |
5 | 608 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 610 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
* @param int $userid User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
* @param array|string $post_type Optional. Single post type or array of post types to count the number of posts for. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* @param bool $public_only Optional. Whether to only return counts for public posts. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
* @return string Number of posts the user has written in this post type. |
0 | 615 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
function count_user_posts( $userid, $post_type = 'post', $public_only = false ) { |
0 | 617 |
global $wpdb; |
618 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
619 |
$post_type = array_unique( (array) $post_type ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
620 |
sort( $post_type ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
621 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
$where = get_posts_by_author_sql( $post_type, true, $userid, $public_only ); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
623 |
$query = "SELECT COUNT(*) FROM $wpdb->posts $where"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
624 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
625 |
$last_changed = wp_cache_get_last_changed( 'posts' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
626 |
$cache_key = 'count_user_posts:' . md5( $query ) . ':' . $last_changed; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
627 |
$count = wp_cache_get( $cache_key, 'post-queries' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
628 |
if ( false === $count ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
629 |
$count = $wpdb->get_var( $query ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
630 |
wp_cache_set( $cache_key, $count, 'post-queries' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
631 |
} |
0 | 632 |
|
5 | 633 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* Filters the number of posts a user has written. |
5 | 635 |
* |
636 |
* @since 2.7.0 |
|
637 |
* @since 4.1.0 Added `$post_type` argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* @since 4.3.1 Added `$public_only` argument. |
5 | 639 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* @param int $count The user's post count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* @param int $userid User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* @param string|array $post_type Single post type or array of post types to count the number of posts for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* @param bool $public_only Whether to limit counted posts to public posts. |
5 | 644 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only ); |
0 | 646 |
} |
647 |
||
648 |
/** |
|
19 | 649 |
* Gets the number of posts written by a list of users. |
0 | 650 |
* |
651 |
* @since 3.0.0 |
|
652 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* |
16 | 655 |
* @param int[] $users Array of user IDs. |
656 |
* @param string|string[] $post_type Optional. Single post type or array of post types to check. Defaults to 'post'. |
|
657 |
* @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
|
658 |
* @return string[] Amount of posts each user has written, as strings, keyed by user ID. |
|
0 | 659 |
*/ |
660 |
function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
|
661 |
global $wpdb; |
|
662 |
||
9 | 663 |
if ( empty( $users ) || ! is_array( $users ) ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
664 |
return array(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
665 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
666 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
667 |
/** |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
668 |
* Filters whether to short-circuit performing the post counts. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
669 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
670 |
* When filtering, return an array of posts counts as strings, keyed |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
671 |
* by the user ID. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
672 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
673 |
* @since 6.8.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
674 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
675 |
* @param string[]|null $count The post counts. Return a non-null value to short-circuit. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
676 |
* @param int[] $users Array of user IDs. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
677 |
* @param string|string[] $post_type Single post type or array of post types to check. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
678 |
* @param bool $public_only Whether to only return counts for public posts. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
679 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
680 |
$pre = apply_filters( 'pre_count_many_users_posts', null, $users, $post_type, $public_only ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
681 |
if ( null !== $pre ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
682 |
return $pre; |
9 | 683 |
} |
0 | 684 |
|
685 |
$userlist = implode( ',', array_map( 'absint', $users ) ); |
|
9 | 686 |
$where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
0 | 687 |
|
688 |
$result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
689 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
690 |
$count = array_fill_keys( $users, 0 ); |
0 | 691 |
foreach ( $result as $row ) { |
692 |
$count[ $row[0] ] = $row[1]; |
|
693 |
} |
|
694 |
||
695 |
return $count; |
|
696 |
} |
|
697 |
||
698 |
// |
|
16 | 699 |
// User option functions. |
0 | 700 |
// |
701 |
||
702 |
/** |
|
19 | 703 |
* Gets the current user's ID. |
0 | 704 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
* @since MU (3.0.0) |
0 | 706 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* @return int The current user's ID, or 0 if no user is logged in. |
0 | 708 |
*/ |
709 |
function get_current_user_id() { |
|
9 | 710 |
if ( ! function_exists( 'wp_get_current_user' ) ) { |
0 | 711 |
return 0; |
9 | 712 |
} |
0 | 713 |
$user = wp_get_current_user(); |
714 |
return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
|
715 |
} |
|
716 |
||
717 |
/** |
|
19 | 718 |
* Retrieves user option that can be either per Site or per Network. |
0 | 719 |
* |
720 |
* If the user ID is not given, then the current user will be used instead. If |
|
721 |
* the user ID is given, then the user data will be retrieved. The filter for |
|
722 |
* the result, will also pass the original option name and finally the user data |
|
723 |
* object as the third parameter. |
|
724 |
* |
|
725 |
* The option will first check for the per site name and then the per Network name. |
|
726 |
* |
|
727 |
* @since 2.0.0 |
|
5 | 728 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 730 |
* |
5 | 731 |
* @param string $option User option name. |
732 |
* @param int $user Optional. User ID. |
|
733 |
* @param string $deprecated Use get_option() to check for an option in the options table. |
|
734 |
* @return mixed User option value on success, false on failure. |
|
0 | 735 |
*/ |
736 |
function get_user_option( $option, $user = 0, $deprecated = '' ) { |
|
737 |
global $wpdb; |
|
738 |
||
9 | 739 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
_deprecated_argument( __FUNCTION__, '3.0.0' ); |
9 | 741 |
} |
742 |
||
743 |
if ( empty( $user ) ) { |
|
0 | 744 |
$user = get_current_user_id(); |
9 | 745 |
} |
746 |
||
16 | 747 |
$user = get_userdata( $user ); |
748 |
if ( ! $user ) { |
|
0 | 749 |
return false; |
9 | 750 |
} |
0 | 751 |
|
752 |
$prefix = $wpdb->get_blog_prefix(); |
|
16 | 753 |
if ( $user->has_prop( $prefix . $option ) ) { // Blog-specific. |
0 | 754 |
$result = $user->get( $prefix . $option ); |
16 | 755 |
} elseif ( $user->has_prop( $option ) ) { // User-specific and cross-blog. |
0 | 756 |
$result = $user->get( $option ); |
9 | 757 |
} else { |
0 | 758 |
$result = false; |
9 | 759 |
} |
0 | 760 |
|
5 | 761 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
* Filters a specific user option value. |
5 | 763 |
* |
764 |
* The dynamic portion of the hook name, `$option`, refers to the user option name. |
|
765 |
* |
|
766 |
* @since 2.5.0 |
|
767 |
* |
|
768 |
* @param mixed $result Value for the user's option. |
|
769 |
* @param string $option Name of the option being retrieved. |
|
770 |
* @param WP_User $user WP_User object of the user whose option is being retrieved. |
|
771 |
*/ |
|
772 |
return apply_filters( "get_user_option_{$option}", $result, $option, $user ); |
|
0 | 773 |
} |
774 |
||
775 |
/** |
|
19 | 776 |
* Updates user option with global blog capability. |
0 | 777 |
* |
778 |
* User options are just like user metadata except that they have support for |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
779 |
* global blog options. If the 'is_global' parameter is false, which it is by default, |
0 | 780 |
* it will prepend the WordPress table prefix to the option name. |
781 |
* |
|
782 |
* Deletes the user option if $newvalue is empty. |
|
783 |
* |
|
784 |
* @since 2.0.0 |
|
785 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 787 |
* |
788 |
* @param int $user_id User ID. |
|
0 | 789 |
* @param string $option_name User option name. |
5 | 790 |
* @param mixed $newvalue User option value. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
791 |
* @param bool $is_global Optional. Whether option name is global or blog specific. |
5 | 792 |
* Default false (blog specific). |
793 |
* @return int|bool User meta ID if the option didn't exist, true on successful update, |
|
794 |
* false on failure. |
|
0 | 795 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
796 |
function update_user_option( $user_id, $option_name, $newvalue, $is_global = false ) { |
0 | 797 |
global $wpdb; |
798 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
799 |
if ( ! $is_global ) { |
0 | 800 |
$option_name = $wpdb->get_blog_prefix() . $option_name; |
9 | 801 |
} |
0 | 802 |
|
803 |
return update_user_meta( $user_id, $option_name, $newvalue ); |
|
804 |
} |
|
805 |
||
806 |
/** |
|
19 | 807 |
* Deletes user option with global blog capability. |
0 | 808 |
* |
809 |
* User options are just like user metadata except that they have support for |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
810 |
* global blog options. If the 'is_global' parameter is false, which it is by default, |
0 | 811 |
* it will prepend the WordPress table prefix to the option name. |
812 |
* |
|
813 |
* @since 3.0.0 |
|
5 | 814 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 816 |
* |
5 | 817 |
* @param int $user_id User ID |
0 | 818 |
* @param string $option_name User option name. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
819 |
* @param bool $is_global Optional. Whether option name is global or blog specific. |
5 | 820 |
* Default false (blog specific). |
821 |
* @return bool True on success, false on failure. |
|
0 | 822 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
823 |
function delete_user_option( $user_id, $option_name, $is_global = false ) { |
0 | 824 |
global $wpdb; |
825 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
826 |
if ( ! $is_global ) { |
0 | 827 |
$option_name = $wpdb->get_blog_prefix() . $option_name; |
9 | 828 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
829 |
|
0 | 830 |
return delete_user_meta( $user_id, $option_name ); |
831 |
} |
|
832 |
||
833 |
/** |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
834 |
* Retrieves user info by user ID. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
835 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
836 |
* @since 6.7.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
837 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
838 |
* @param int $user_id User ID. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
839 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
840 |
* @return WP_User|false WP_User object on success, false on failure. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
841 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
842 |
function get_user( $user_id ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
843 |
return get_user_by( 'id', $user_id ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
844 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
845 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
846 |
/** |
19 | 847 |
* Retrieves list of users matching criteria. |
0 | 848 |
* |
849 |
* @since 3.1.0 |
|
5 | 850 |
* |
851 |
* @see WP_User_Query |
|
0 | 852 |
* |
18 | 853 |
* @param array $args Optional. Arguments to retrieve users. See WP_User_Query::prepare_query() |
5 | 854 |
* for more information on accepted arguments. |
0 | 855 |
* @return array List of users. |
856 |
*/ |
|
857 |
function get_users( $args = array() ) { |
|
858 |
||
9 | 859 |
$args = wp_parse_args( $args ); |
0 | 860 |
$args['count_total'] = false; |
861 |
||
9 | 862 |
$user_search = new WP_User_Query( $args ); |
0 | 863 |
|
864 |
return (array) $user_search->get_results(); |
|
865 |
} |
|
866 |
||
867 |
/** |
|
19 | 868 |
* Lists all the users of the site, with several options available. |
869 |
* |
|
870 |
* @since 5.9.0 |
|
871 |
* |
|
872 |
* @param string|array $args { |
|
873 |
* Optional. Array or string of default arguments. |
|
874 |
* |
|
875 |
* @type string $orderby How to sort the users. Accepts 'nicename', 'email', 'url', 'registered', |
|
876 |
* 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name', |
|
877 |
* 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'. |
|
878 |
* @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'. |
|
879 |
* @type int $number Maximum users to return or display. Default empty (all users). |
|
880 |
* @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false. |
|
881 |
* @type bool $show_fullname Whether to show the user's full name. Default false. |
|
882 |
* @type string $feed If not empty, show a link to the user's feed and use this text as the alt |
|
883 |
* parameter of the link. Default empty. |
|
884 |
* @type string $feed_image If not empty, show a link to the user's feed and use this image URL as |
|
885 |
* clickable anchor. Default empty. |
|
886 |
* @type string $feed_type The feed type to link to, such as 'rss2'. Defaults to default feed type. |
|
887 |
* @type bool $echo Whether to output the result or instead return it. Default true. |
|
888 |
* @type string $style If 'list', each user is wrapped in an `<li>` element, otherwise the users |
|
889 |
* will be separated by commas. |
|
890 |
* @type bool $html Whether to list the items in HTML form or plaintext. Default true. |
|
891 |
* @type string $exclude An array, comma-, or space-separated list of user IDs to exclude. Default empty. |
|
892 |
* @type string $include An array, comma-, or space-separated list of user IDs to include. Default empty. |
|
893 |
* } |
|
894 |
* @return string|null The output if echo is false. Otherwise null. |
|
895 |
*/ |
|
896 |
function wp_list_users( $args = array() ) { |
|
897 |
$defaults = array( |
|
898 |
'orderby' => 'name', |
|
899 |
'order' => 'ASC', |
|
900 |
'number' => '', |
|
901 |
'exclude_admin' => true, |
|
902 |
'show_fullname' => false, |
|
903 |
'feed' => '', |
|
904 |
'feed_image' => '', |
|
905 |
'feed_type' => '', |
|
906 |
'echo' => true, |
|
907 |
'style' => 'list', |
|
908 |
'html' => true, |
|
909 |
'exclude' => '', |
|
910 |
'include' => '', |
|
911 |
); |
|
912 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
913 |
$parsed_args = wp_parse_args( $args, $defaults ); |
19 | 914 |
|
915 |
$return = ''; |
|
916 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
917 |
$query_args = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); |
19 | 918 |
$query_args['fields'] = 'ids'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
919 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
920 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
921 |
* Filters the query arguments for the list of all users of the site. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
922 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
923 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
924 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
925 |
* @param array $query_args The query arguments for get_users(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
926 |
* @param array $parsed_args The arguments passed to wp_list_users() combined with the defaults. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
927 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
928 |
$query_args = apply_filters( 'wp_list_users_args', $query_args, $parsed_args ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
929 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
930 |
$users = get_users( $query_args ); |
19 | 931 |
|
932 |
foreach ( $users as $user_id ) { |
|
933 |
$user = get_userdata( $user_id ); |
|
934 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
935 |
if ( $parsed_args['exclude_admin'] && 'admin' === $user->display_name ) { |
19 | 936 |
continue; |
937 |
} |
|
938 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
939 |
if ( $parsed_args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
940 |
$name = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
941 |
/* translators: 1: User's first name, 2: Last name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
942 |
_x( '%1$s %2$s', 'Display name based on first name and last name' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
943 |
$user->first_name, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
944 |
$user->last_name |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
945 |
); |
19 | 946 |
} else { |
947 |
$name = $user->display_name; |
|
948 |
} |
|
949 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
950 |
if ( ! $parsed_args['html'] ) { |
19 | 951 |
$return .= $name . ', '; |
952 |
||
953 |
continue; // No need to go further to process HTML. |
|
954 |
} |
|
955 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
956 |
if ( 'list' === $parsed_args['style'] ) { |
19 | 957 |
$return .= '<li>'; |
958 |
} |
|
959 |
||
960 |
$row = $name; |
|
961 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
962 |
if ( ! empty( $parsed_args['feed_image'] ) || ! empty( $parsed_args['feed'] ) ) { |
19 | 963 |
$row .= ' '; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
964 |
if ( empty( $parsed_args['feed_image'] ) ) { |
19 | 965 |
$row .= '('; |
966 |
} |
|
967 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
968 |
$row .= '<a href="' . get_author_feed_link( $user->ID, $parsed_args['feed_type'] ) . '"'; |
19 | 969 |
|
970 |
$alt = ''; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
971 |
if ( ! empty( $parsed_args['feed'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
972 |
$alt = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
973 |
$name = $parsed_args['feed']; |
19 | 974 |
} |
975 |
||
976 |
$row .= '>'; |
|
977 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
978 |
if ( ! empty( $parsed_args['feed_image'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
979 |
$row .= '<img src="' . esc_url( $parsed_args['feed_image'] ) . '" style="border: none;"' . $alt . ' />'; |
19 | 980 |
} else { |
981 |
$row .= $name; |
|
982 |
} |
|
983 |
||
984 |
$row .= '</a>'; |
|
985 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
986 |
if ( empty( $parsed_args['feed_image'] ) ) { |
19 | 987 |
$row .= ')'; |
988 |
} |
|
989 |
} |
|
990 |
||
991 |
$return .= $row; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
992 |
$return .= ( 'list' === $parsed_args['style'] ) ? '</li>' : ', '; |
19 | 993 |
} |
994 |
||
995 |
$return = rtrim( $return, ', ' ); |
|
996 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
997 |
if ( ! $parsed_args['echo'] ) { |
19 | 998 |
return $return; |
999 |
} |
|
1000 |
echo $return; |
|
1001 |
} |
|
1002 |
||
1003 |
/** |
|
1004 |
* Gets the sites a user belongs to. |
|
0 | 1005 |
* |
1006 |
* @since 3.0.0 |
|
9 | 1007 |
* @since 4.7.0 Converted to use `get_sites()`. |
0 | 1008 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 1010 |
* |
1011 |
* @param int $user_id User ID |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
* @param bool $all Whether to retrieve all sites, or only sites that are not |
5 | 1013 |
* marked as deleted, archived, or spam. |
18 | 1014 |
* @return object[] A list of the user's sites. An empty array if the user doesn't exist |
1015 |
* or belongs to no sites. |
|
0 | 1016 |
*/ |
1017 |
function get_blogs_of_user( $user_id, $all = false ) { |
|
1018 |
global $wpdb; |
|
1019 |
||
1020 |
$user_id = (int) $user_id; |
|
1021 |
||
16 | 1022 |
// Logged out users can't have sites. |
9 | 1023 |
if ( empty( $user_id ) ) { |
0 | 1024 |
return array(); |
9 | 1025 |
} |
0 | 1026 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
* Filters the list of a user's sites before it is populated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
* |
16 | 1030 |
* Returning a non-null value from the filter will effectively short circuit |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
* get_blogs_of_user(), returning that value instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
* |
18 | 1035 |
* @param null|object[] $sites An array of site objects of which the user is a member. |
1036 |
* @param int $user_id User ID. |
|
1037 |
* @param bool $all Whether the returned array should contain all sites, including |
|
1038 |
* those marked 'deleted', 'archived', or 'spam'. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
$sites = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
if ( null !== $sites ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
return $sites; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
|
0 | 1046 |
$keys = get_user_meta( $user_id ); |
9 | 1047 |
if ( empty( $keys ) ) { |
0 | 1048 |
return array(); |
9 | 1049 |
} |
0 | 1050 |
|
1051 |
if ( ! is_multisite() ) { |
|
9 | 1052 |
$site_id = get_current_blog_id(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1053 |
$sites = array( $site_id => new stdClass() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
$sites[ $site_id ]->userblog_id = $site_id; |
9 | 1055 |
$sites[ $site_id ]->blogname = get_option( 'blogname' ); |
1056 |
$sites[ $site_id ]->domain = ''; |
|
1057 |
$sites[ $site_id ]->path = ''; |
|
1058 |
$sites[ $site_id ]->site_id = 1; |
|
1059 |
$sites[ $site_id ]->siteurl = get_option( 'siteurl' ); |
|
1060 |
$sites[ $site_id ]->archived = 0; |
|
1061 |
$sites[ $site_id ]->spam = 0; |
|
1062 |
$sites[ $site_id ]->deleted = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
return $sites; |
0 | 1064 |
} |
1065 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
$site_ids = array(); |
0 | 1067 |
|
1068 |
if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
$site_ids[] = 1; |
0 | 1070 |
unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); |
1071 |
} |
|
1072 |
||
1073 |
$keys = array_keys( $keys ); |
|
1074 |
||
1075 |
foreach ( $keys as $key ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1076 |
if ( ! str_ends_with( $key, 'capabilities' ) ) { |
0 | 1077 |
continue; |
9 | 1078 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1079 |
if ( $wpdb->base_prefix && ! str_starts_with( $key, $wpdb->base_prefix ) ) { |
0 | 1080 |
continue; |
9 | 1081 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
$site_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
9 | 1083 |
if ( ! is_numeric( $site_id ) ) { |
0 | 1084 |
continue; |
9 | 1085 |
} |
0 | 1086 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
$site_ids[] = (int) $site_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
$sites = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
if ( ! empty( $site_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
$args = array( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1094 |
'number' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1095 |
'site__in' => $site_ids, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
if ( ! $all ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
$args['archived'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
$args['spam'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
$args['deleted'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
$_sites = get_sites( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
foreach ( $_sites as $site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
$sites[ $site->id ] = (object) array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
'userblog_id' => $site->id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
'blogname' => $site->blogname, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
'domain' => $site->domain, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
'path' => $site->path, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
'site_id' => $site->network_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
'siteurl' => $site->siteurl, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
'archived' => $site->archived, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
'mature' => $site->mature, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
'spam' => $site->spam, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
'deleted' => $site->deleted, |
0 | 1117 |
); |
1118 |
} |
|
1119 |
} |
|
1120 |
||
5 | 1121 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
* Filters the list of sites a user belongs to. |
5 | 1123 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
* @since MU (3.0.0) |
5 | 1125 |
* |
18 | 1126 |
* @param object[] $sites An array of site objects belonging to the user. |
1127 |
* @param int $user_id User ID. |
|
1128 |
* @param bool $all Whether the returned sites array should contain all sites, including |
|
1129 |
* those marked 'deleted', 'archived', or 'spam'. Default false. |
|
5 | 1130 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
return apply_filters( 'get_blogs_of_user', $sites, $user_id, $all ); |
0 | 1132 |
} |
1133 |
||
1134 |
/** |
|
19 | 1135 |
* Finds out whether a user is a member of a given blog. |
0 | 1136 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1140 |
* |
1141 |
* @param int $user_id Optional. The unique ID of the user. Defaults to the current user. |
|
1142 |
* @param int $blog_id Optional. ID of the blog to check. Defaults to the current site. |
|
1143 |
* @return bool |
|
1144 |
*/ |
|
1145 |
function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
|
0 | 1148 |
$user_id = (int) $user_id; |
1149 |
$blog_id = (int) $blog_id; |
|
1150 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
if ( empty( $user_id ) ) { |
0 | 1152 |
$user_id = get_current_user_id(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1155 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1156 |
* Technically not needed, but does save calls to get_site() and get_user_meta() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1157 |
* in the event that the function is called when a user isn't logged in. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1158 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
if ( empty( $user_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
$user = get_userdata( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
if ( ! $user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
if ( empty( $blog_id ) ) { |
0 | 1173 |
$blog_id = get_current_blog_id(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
$blog = get_site( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
if ( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
$keys = get_user_meta( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
if ( empty( $keys ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
|
16 | 1187 |
// No underscore before capabilities in $base_capabilities_key. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
$base_capabilities_key = $wpdb->base_prefix . 'capabilities'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
$site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1191 |
if ( isset( $keys[ $base_capabilities_key ] ) && 1 === $blog_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
if ( isset( $keys[ $site_capabilities_key ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
return false; |
0 | 1200 |
} |
1201 |
||
1202 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
* Adds meta data to a user. |
0 | 1204 |
* |
1205 |
* @since 3.0.0 |
|
1206 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
* @param string $meta_key Metadata name. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1209 |
* @param mixed $meta_value Metadata value. Arrays and objects are stored as serialized data and |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1210 |
* will be returned as the same type when retrieved. Other data types will |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1211 |
* be stored as strings in the database: |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1212 |
* - false is stored and retrieved as an empty string ('') |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1213 |
* - true is stored and retrieved as '1' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1214 |
* - numbers (both integer and float) are stored and retrieved as strings |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1215 |
* Must be serializable if non-scalar. |
16 | 1216 |
* @param bool $unique Optional. Whether the same key should not be added. |
1217 |
* Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* @return int|false Meta ID on success, false on failure. |
0 | 1219 |
*/ |
9 | 1220 |
function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) { |
1221 |
return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique ); |
|
0 | 1222 |
} |
1223 |
||
1224 |
/** |
|
19 | 1225 |
* Removes metadata matching criteria from a user. |
0 | 1226 |
* |
1227 |
* You can match based on the key, or key and value. Removing based on key and |
|
1228 |
* value, will keep from removing duplicate metadata with the same key. It also |
|
1229 |
* allows removing all metadata matching key, if needed. |
|
1230 |
* |
|
1231 |
* @since 3.0.0 |
|
16 | 1232 |
* |
1233 |
* @link https://developer.wordpress.org/reference/functions/delete_user_meta/ |
|
0 | 1234 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
* @param int $user_id User ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* @param string $meta_key Metadata name. |
16 | 1237 |
* @param mixed $meta_value Optional. Metadata value. If provided, |
1238 |
* rows will only be removed that match the value. |
|
1239 |
* Must be serializable if non-scalar. Default empty. |
|
0 | 1240 |
* @return bool True on success, false on failure. |
1241 |
*/ |
|
9 | 1242 |
function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { |
1243 |
return delete_metadata( 'user', $user_id, $meta_key, $meta_value ); |
|
0 | 1244 |
} |
1245 |
||
1246 |
/** |
|
19 | 1247 |
* Retrieves user meta field for a user. |
0 | 1248 |
* |
1249 |
* @since 3.0.0 |
|
16 | 1250 |
* |
1251 |
* @link https://developer.wordpress.org/reference/functions/get_user_meta/ |
|
0 | 1252 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* @param int $user_id User ID. |
16 | 1254 |
* @param string $key Optional. The meta key to retrieve. By default, |
1255 |
* returns data for all keys. |
|
1256 |
* @param bool $single Optional. Whether to return a single value. |
|
18 | 1257 |
* This parameter has no effect if `$key` is not specified. |
16 | 1258 |
* Default false. |
18 | 1259 |
* @return mixed An array of values if `$single` is false. |
1260 |
* The value of meta data field if `$single` is true. |
|
1261 |
* False for an invalid `$user_id` (non-numeric, zero, or negative value). |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1262 |
* An empty array if a valid but non-existing user ID is passed and `$single` is false. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1263 |
* An empty string if a valid but non-existing user ID is passed and `$single` is true. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1264 |
* Note: Non-serialized values are returned as strings: |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1265 |
* - false values are returned as empty strings ('') |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1266 |
* - true values are returned as '1' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1267 |
* - numbers (both integer and float) are returned as strings |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1268 |
* Arrays and objects retain their original type. |
0 | 1269 |
*/ |
9 | 1270 |
function get_user_meta( $user_id, $key = '', $single = false ) { |
1271 |
return get_metadata( 'user', $user_id, $key, $single ); |
|
0 | 1272 |
} |
1273 |
||
1274 |
/** |
|
19 | 1275 |
* Updates user meta field based on user ID. |
0 | 1276 |
* |
1277 |
* Use the $prev_value parameter to differentiate between meta fields with the |
|
1278 |
* same key and user ID. |
|
1279 |
* |
|
1280 |
* If the meta field for the user does not exist, it will be added. |
|
1281 |
* |
|
1282 |
* @since 3.0.0 |
|
16 | 1283 |
* |
1284 |
* @link https://developer.wordpress.org/reference/functions/update_user_meta/ |
|
0 | 1285 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
* @param string $meta_key Metadata key. |
16 | 1288 |
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
1289 |
* @param mixed $prev_value Optional. Previous value to check before updating. |
|
1290 |
* If specified, only update existing metadata entries with |
|
1291 |
* this value. Otherwise, update all entries. Default empty. |
|
1292 |
* @return int|bool Meta ID if the key didn't exist, true on successful update, |
|
1293 |
* false on failure or if the value passed to the function |
|
1294 |
* is the same as the one that is already in the database. |
|
0 | 1295 |
*/ |
9 | 1296 |
function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { |
1297 |
return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value ); |
|
0 | 1298 |
} |
1299 |
||
1300 |
/** |
|
19 | 1301 |
* Counts number of users who have each of the user roles. |
0 | 1302 |
* |
1303 |
* Assumes there are neither duplicated nor orphaned capabilities meta_values. |
|
1304 |
* Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query() |
|
1305 |
* Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users. |
|
1306 |
* Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257. |
|
1307 |
* |
|
1308 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
* @since 4.4.0 The number of users with no role is now included in the `none` element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
* @since 4.9.0 The `$site_id` parameter was added to support multisite. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
* @param string $strategy Optional. The computational strategy to use when counting the users. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
* Accepts either 'time' or 'memory'. Default 'time'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site. |
16 | 1317 |
* @return array { |
1318 |
* User counts. |
|
1319 |
* |
|
1320 |
* @type int $total_users Total number of users on the site. |
|
1321 |
* @type int[] $avail_roles Array of user counts keyed by user role. |
|
1322 |
* } |
|
0 | 1323 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
function count_users( $strategy = 'time', $site_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
global $wpdb; |
0 | 1326 |
|
16 | 1327 |
// Initialize. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
if ( ! $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
$site_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
} |
9 | 1331 |
|
1332 |
/** |
|
18 | 1333 |
* Filters the user count before queries are run. |
1334 |
* |
|
1335 |
* Return a non-null value to cause count_users() to return early. |
|
9 | 1336 |
* |
1337 |
* @since 5.1.0 |
|
1338 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1339 |
* @param null|array $result The value to return instead. Default null to continue with the query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1340 |
* @param string $strategy Optional. The computational strategy to use when counting the users. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1341 |
* Accepts either 'time' or 'memory'. Default 'time'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1342 |
* @param int $site_id The site ID to count users for. |
9 | 1343 |
*/ |
1344 |
$pre = apply_filters( 'pre_count_users', null, $strategy, $site_id ); |
|
1345 |
||
1346 |
if ( null !== $pre ) { |
|
1347 |
return $pre; |
|
1348 |
} |
|
1349 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
$blog_prefix = $wpdb->get_blog_prefix( $site_id ); |
9 | 1351 |
$result = array(); |
0 | 1352 |
|
16 | 1353 |
if ( 'time' === $strategy ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1354 |
if ( is_multisite() && get_current_blog_id() !== $site_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
switch_to_blog( $site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
$avail_roles = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
$avail_roles = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
} |
0 | 1361 |
|
1362 |
// Build a CPU-intensive query that will return concise information. |
|
1363 |
$select_count = array(); |
|
1364 |
foreach ( $avail_roles as $this_role => $name ) { |
|
9 | 1365 |
$select_count[] = $wpdb->prepare( 'COUNT(NULLIF(`meta_value` LIKE %s, false))', '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%' ); |
0 | 1366 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
$select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))"; |
9 | 1368 |
$select_count = implode( ', ', $select_count ); |
0 | 1369 |
|
1370 |
// Add the meta_value index to the selection list, then run the query. |
|
9 | 1371 |
$row = $wpdb->get_row( |
1372 |
" |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
SELECT {$select_count}, COUNT(*) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
FROM {$wpdb->usermeta} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
INNER JOIN {$wpdb->users} ON user_id = ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
WHERE meta_key = '{$blog_prefix}capabilities' |
9 | 1377 |
", |
1378 |
ARRAY_N |
|
1379 |
); |
|
0 | 1380 |
|
1381 |
// Run the previous loop again to associate results with role names. |
|
9 | 1382 |
$col = 0; |
0 | 1383 |
$role_counts = array(); |
1384 |
foreach ( $avail_roles as $this_role => $name ) { |
|
9 | 1385 |
$count = (int) $row[ $col++ ]; |
1386 |
if ( $count > 0 ) { |
|
1387 |
$role_counts[ $this_role ] = $count; |
|
0 | 1388 |
} |
1389 |
} |
|
1390 |
||
9 | 1391 |
$role_counts['none'] = (int) $row[ $col++ ]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
|
0 | 1393 |
// Get the meta_value index from the end of the result set. |
9 | 1394 |
$total_users = (int) $row[ $col ]; |
0 | 1395 |
|
1396 |
$result['total_users'] = $total_users; |
|
1397 |
$result['avail_roles'] =& $role_counts; |
|
1398 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
$avail_roles = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
'none' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
|
9 | 1403 |
$users_of_blog = $wpdb->get_col( |
1404 |
" |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
SELECT meta_value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
FROM {$wpdb->usermeta} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
INNER JOIN {$wpdb->users} ON user_id = ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
WHERE meta_key = '{$blog_prefix}capabilities' |
9 | 1409 |
" |
1410 |
); |
|
0 | 1411 |
|
1412 |
foreach ( $users_of_blog as $caps_meta ) { |
|
9 | 1413 |
$b_roles = maybe_unserialize( $caps_meta ); |
1414 |
if ( ! is_array( $b_roles ) ) { |
|
0 | 1415 |
continue; |
9 | 1416 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
if ( empty( $b_roles ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1418 |
++$avail_roles['none']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
} |
0 | 1420 |
foreach ( $b_roles as $b_role => $val ) { |
9 | 1421 |
if ( isset( $avail_roles[ $b_role ] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1422 |
++$avail_roles[ $b_role ]; |
0 | 1423 |
} else { |
9 | 1424 |
$avail_roles[ $b_role ] = 1; |
0 | 1425 |
} |
1426 |
} |
|
1427 |
} |
|
1428 |
||
1429 |
$result['total_users'] = count( $users_of_blog ); |
|
1430 |
$result['avail_roles'] =& $avail_roles; |
|
1431 |
} |
|
1432 |
||
1433 |
return $result; |
|
1434 |
} |
|
1435 |
||
19 | 1436 |
/** |
1437 |
* Returns the number of active users in your installation. |
|
1438 |
* |
|
1439 |
* Note that on a large site the count may be cached and only updated twice daily. |
|
1440 |
* |
|
1441 |
* @since MU (3.0.0) |
|
1442 |
* @since 4.8.0 The `$network_id` parameter has been added. |
|
1443 |
* @since 6.0.0 Moved to wp-includes/user.php. |
|
1444 |
* |
|
1445 |
* @param int|null $network_id ID of the network. Defaults to the current network. |
|
1446 |
* @return int Number of active users on the network. |
|
1447 |
*/ |
|
1448 |
function get_user_count( $network_id = null ) { |
|
1449 |
if ( ! is_multisite() && null !== $network_id ) { |
|
1450 |
_doing_it_wrong( |
|
1451 |
__FUNCTION__, |
|
1452 |
sprintf( |
|
1453 |
/* translators: %s: $network_id */ |
|
1454 |
__( 'Unable to pass %s if not using multisite.' ), |
|
1455 |
'<code>$network_id</code>' |
|
1456 |
), |
|
1457 |
'6.0.0' |
|
1458 |
); |
|
1459 |
} |
|
1460 |
||
1461 |
return (int) get_network_option( $network_id, 'user_count', -1 ); |
|
1462 |
} |
|
1463 |
||
1464 |
/** |
|
1465 |
* Updates the total count of users on the site if live user counting is enabled. |
|
1466 |
* |
|
1467 |
* @since 6.0.0 |
|
1468 |
* |
|
1469 |
* @param int|null $network_id ID of the network. Defaults to the current network. |
|
1470 |
* @return bool Whether the update was successful. |
|
1471 |
*/ |
|
1472 |
function wp_maybe_update_user_counts( $network_id = null ) { |
|
1473 |
if ( ! is_multisite() && null !== $network_id ) { |
|
1474 |
_doing_it_wrong( |
|
1475 |
__FUNCTION__, |
|
1476 |
sprintf( |
|
1477 |
/* translators: %s: $network_id */ |
|
1478 |
__( 'Unable to pass %s if not using multisite.' ), |
|
1479 |
'<code>$network_id</code>' |
|
1480 |
), |
|
1481 |
'6.0.0' |
|
1482 |
); |
|
1483 |
} |
|
1484 |
||
1485 |
$is_small_network = ! wp_is_large_user_count( $network_id ); |
|
1486 |
/** This filter is documented in wp-includes/ms-functions.php */ |
|
1487 |
if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) { |
|
1488 |
return false; |
|
1489 |
} |
|
1490 |
||
1491 |
return wp_update_user_counts( $network_id ); |
|
1492 |
} |
|
1493 |
||
1494 |
/** |
|
1495 |
* Updates the total count of users on the site. |
|
1496 |
* |
|
1497 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
1498 |
* @since 6.0.0 |
|
1499 |
* |
|
1500 |
* @param int|null $network_id ID of the network. Defaults to the current network. |
|
1501 |
* @return bool Whether the update was successful. |
|
1502 |
*/ |
|
1503 |
function wp_update_user_counts( $network_id = null ) { |
|
1504 |
global $wpdb; |
|
1505 |
||
1506 |
if ( ! is_multisite() && null !== $network_id ) { |
|
1507 |
_doing_it_wrong( |
|
1508 |
__FUNCTION__, |
|
1509 |
sprintf( |
|
1510 |
/* translators: %s: $network_id */ |
|
1511 |
__( 'Unable to pass %s if not using multisite.' ), |
|
1512 |
'<code>$network_id</code>' |
|
1513 |
), |
|
1514 |
'6.0.0' |
|
1515 |
); |
|
1516 |
} |
|
1517 |
||
1518 |
$query = "SELECT COUNT(ID) as c FROM $wpdb->users"; |
|
1519 |
if ( is_multisite() ) { |
|
1520 |
$query .= " WHERE spam = '0' AND deleted = '0'"; |
|
1521 |
} |
|
1522 |
||
1523 |
$count = $wpdb->get_var( $query ); |
|
1524 |
||
1525 |
return update_network_option( $network_id, 'user_count', $count ); |
|
1526 |
} |
|
1527 |
||
1528 |
/** |
|
1529 |
* Schedules a recurring recalculation of the total count of users. |
|
1530 |
* |
|
1531 |
* @since 6.0.0 |
|
1532 |
*/ |
|
1533 |
function wp_schedule_update_user_counts() { |
|
1534 |
if ( ! is_main_site() ) { |
|
1535 |
return; |
|
1536 |
} |
|
1537 |
||
1538 |
if ( ! wp_next_scheduled( 'wp_update_user_counts' ) && ! wp_installing() ) { |
|
1539 |
wp_schedule_event( time(), 'twicedaily', 'wp_update_user_counts' ); |
|
1540 |
} |
|
1541 |
} |
|
1542 |
||
1543 |
/** |
|
1544 |
* Determines whether the site has a large number of users. |
|
1545 |
* |
|
1546 |
* The default criteria for a large site is more than 10,000 users. |
|
1547 |
* |
|
1548 |
* @since 6.0.0 |
|
1549 |
* |
|
1550 |
* @param int|null $network_id ID of the network. Defaults to the current network. |
|
1551 |
* @return bool Whether the site has a large number of users. |
|
1552 |
*/ |
|
1553 |
function wp_is_large_user_count( $network_id = null ) { |
|
1554 |
if ( ! is_multisite() && null !== $network_id ) { |
|
1555 |
_doing_it_wrong( |
|
1556 |
__FUNCTION__, |
|
1557 |
sprintf( |
|
1558 |
/* translators: %s: $network_id */ |
|
1559 |
__( 'Unable to pass %s if not using multisite.' ), |
|
1560 |
'<code>$network_id</code>' |
|
1561 |
), |
|
1562 |
'6.0.0' |
|
1563 |
); |
|
1564 |
} |
|
1565 |
||
1566 |
$count = get_user_count( $network_id ); |
|
1567 |
||
1568 |
/** |
|
1569 |
* Filters whether the site is considered large, based on its number of users. |
|
1570 |
* |
|
1571 |
* @since 6.0.0 |
|
1572 |
* |
|
1573 |
* @param bool $is_large_user_count Whether the site has a large number of users. |
|
1574 |
* @param int $count The total number of users. |
|
1575 |
* @param int|null $network_id ID of the network. `null` represents the current network. |
|
1576 |
*/ |
|
1577 |
return apply_filters( 'wp_is_large_user_count', $count > 10000, $count, $network_id ); |
|
1578 |
} |
|
1579 |
||
0 | 1580 |
// |
16 | 1581 |
// Private helper functions. |
0 | 1582 |
// |
1583 |
||
1584 |
/** |
|
19 | 1585 |
* Sets up global user vars. |
0 | 1586 |
* |
1587 |
* Used by wp_set_current_user() for back compat. Might be deprecated in the future. |
|
1588 |
* |
|
1589 |
* @since 2.0.4 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
* @global string $user_login The user username for logging in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
* @global WP_User $userdata User data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
* @global int $user_level The level of the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1594 |
* @global int $user_ID The ID of the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
* @global string $user_email The email address of the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
* @global string $user_url The url in the user's profile |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
* @global string $user_identity The display name of the user |
0 | 1598 |
* |
9 | 1599 |
* @param int $for_user_id Optional. User ID to set up global data. Default 0. |
0 | 1600 |
*/ |
9 | 1601 |
function setup_userdata( $for_user_id = 0 ) { |
0 | 1602 |
global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
1603 |
||
9 | 1604 |
if ( ! $for_user_id ) { |
0 | 1605 |
$for_user_id = get_current_user_id(); |
9 | 1606 |
} |
0 | 1607 |
$user = get_userdata( $for_user_id ); |
1608 |
||
1609 |
if ( ! $user ) { |
|
16 | 1610 |
$user_ID = 0; |
1611 |
$user_level = 0; |
|
1612 |
$userdata = null; |
|
1613 |
$user_login = ''; |
|
1614 |
$user_email = ''; |
|
1615 |
$user_url = ''; |
|
1616 |
$user_identity = ''; |
|
0 | 1617 |
return; |
1618 |
} |
|
1619 |
||
9 | 1620 |
$user_ID = (int) $user->ID; |
1621 |
$user_level = (int) $user->user_level; |
|
1622 |
$userdata = $user; |
|
1623 |
$user_login = $user->user_login; |
|
1624 |
$user_email = $user->user_email; |
|
1625 |
$user_url = $user->user_url; |
|
0 | 1626 |
$user_identity = $user->display_name; |
1627 |
} |
|
1628 |
||
1629 |
/** |
|
19 | 1630 |
* Creates dropdown HTML content of users. |
0 | 1631 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1632 |
* The content can either be displayed, which it is by default, or retrieved by |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1633 |
* setting the 'echo' argument to false. The 'include' and 'exclude' arguments |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1634 |
* are optional; if they are not specified, all users will be displayed. Only one |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1635 |
* can be used in a single call, either 'include' or 'exclude', but not both. |
0 | 1636 |
* |
1637 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
* @since 4.5.0 Added the 'display_name_with_login' value for 'show'. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1639 |
* @since 4.7.0 Added the 'role', 'role__in', and 'role__not_in' parameters. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1640 |
* @since 5.9.0 Added the 'capability', 'capability__in', and 'capability__not_in' parameters. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1641 |
* Deprecated the 'who' parameter. |
5 | 1642 |
* |
1643 |
* @param array|string $args { |
|
1644 |
* Optional. Array or string of arguments to generate a drop-down of users. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
* See WP_User_Query::prepare_query() for additional available arguments. |
0 | 1646 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1647 |
* @type string $show_option_all Text to show as the drop-down default (all). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1648 |
* Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1649 |
* @type string $show_option_none Text to show as the drop-down default when no |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1650 |
* users were found. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1651 |
* @type int|string $option_none_value Value to use for `$show_option_none` when no users |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1652 |
* were found. Default -1. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1653 |
* @type string $hide_if_only_one_author Whether to skip generating the drop-down |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1654 |
* if only one user was found. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1655 |
* @type string $orderby Field to order found users by. Accepts user fields. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1656 |
* Default 'display_name'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1657 |
* @type string $order Whether to order users in ascending or descending |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1658 |
* order. Accepts 'ASC' (ascending) or 'DESC' (descending). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1659 |
* Default 'ASC'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1660 |
* @type int[]|string $include Array or comma-separated list of user IDs to include. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1661 |
* Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1662 |
* @type int[]|string $exclude Array or comma-separated list of user IDs to exclude. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1663 |
* Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1664 |
* @type bool|int $multi Whether to skip the ID attribute on the 'select' element. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1665 |
* Accepts 1|true or 0|false. Default 0|false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1666 |
* @type string $show User data to display. If the selected item is empty |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1667 |
* then the 'user_login' will be displayed in parentheses. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1668 |
* Accepts any user field, or 'display_name_with_login' to show |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1669 |
* the display name with user_login in parentheses. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1670 |
* Default 'display_name'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1671 |
* @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1672 |
* or 0|false (return). Default 1|true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1673 |
* @type int $selected Which user ID should be selected. Default 0. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1674 |
* @type bool $include_selected Whether to always include the selected user ID in the drop- |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1675 |
* down. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1676 |
* @type string $name Name attribute of select element. Default 'user'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1677 |
* @type string $id ID attribute of the select element. Default is the value of `$name`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1678 |
* @type string $class Class attribute of the select element. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1679 |
* @type int $blog_id ID of blog (Multisite only). Default is ID of the current blog. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1680 |
* @type string $who Deprecated, use `$capability` instead. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1681 |
* Which type of users to query. Accepts only an empty string or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1682 |
* 'authors'. Default empty (all users). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1683 |
* @type string|string[] $role An array or a comma-separated list of role names that users |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1684 |
* must match to be included in results. Note that this is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1685 |
* an inclusive list: users must match *each* role. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1686 |
* @type string[] $role__in An array of role names. Matched users must have at least one |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1687 |
* of these roles. Default empty array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1688 |
* @type string[] $role__not_in An array of role names to exclude. Users matching one or more |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1689 |
* of these roles will not be included in results. Default empty array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1690 |
* @type string|string[] $capability An array or a comma-separated list of capability names that users |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1691 |
* must match to be included in results. Note that this is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1692 |
* an inclusive list: users must match *each* capability. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1693 |
* Does NOT work for capabilities not in the database or filtered |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1694 |
* via {@see 'map_meta_cap'}. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1695 |
* @type string[] $capability__in An array of capability names. Matched users must have at least one |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1696 |
* of these capabilities. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1697 |
* Does NOT work for capabilities not in the database or filtered |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1698 |
* via {@see 'map_meta_cap'}. Default empty array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1699 |
* @type string[] $capability__not_in An array of capability names to exclude. Users matching one or more |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1700 |
* of these capabilities will not be included in results. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
* Does NOT work for capabilities not in the database or filtered |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
* via {@see 'map_meta_cap'}. Default empty array. |
5 | 1703 |
* } |
16 | 1704 |
* @return string HTML dropdown list of users. |
0 | 1705 |
*/ |
1706 |
function wp_dropdown_users( $args = '' ) { |
|
1707 |
$defaults = array( |
|
9 | 1708 |
'show_option_all' => '', |
1709 |
'show_option_none' => '', |
|
1710 |
'hide_if_only_one_author' => '', |
|
1711 |
'orderby' => 'display_name', |
|
1712 |
'order' => 'ASC', |
|
1713 |
'include' => '', |
|
1714 |
'exclude' => '', |
|
1715 |
'multi' => 0, |
|
1716 |
'show' => 'display_name', |
|
1717 |
'echo' => 1, |
|
1718 |
'selected' => 0, |
|
1719 |
'name' => 'user', |
|
1720 |
'class' => '', |
|
1721 |
'id' => '', |
|
1722 |
'blog_id' => get_current_blog_id(), |
|
1723 |
'who' => '', |
|
1724 |
'include_selected' => false, |
|
1725 |
'option_none_value' => -1, |
|
1726 |
'role' => '', |
|
1727 |
'role__in' => array(), |
|
1728 |
'role__not_in' => array(), |
|
19 | 1729 |
'capability' => '', |
1730 |
'capability__in' => array(), |
|
1731 |
'capability__not_in' => array(), |
|
0 | 1732 |
); |
1733 |
||
1734 |
$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
1735 |
||
16 | 1736 |
$parsed_args = wp_parse_args( $args, $defaults ); |
1737 |
||
19 | 1738 |
$query_args = wp_array_slice_assoc( |
1739 |
$parsed_args, |
|
1740 |
array( |
|
1741 |
'blog_id', |
|
1742 |
'include', |
|
1743 |
'exclude', |
|
1744 |
'orderby', |
|
1745 |
'order', |
|
1746 |
'who', |
|
1747 |
'role', |
|
1748 |
'role__in', |
|
1749 |
'role__not_in', |
|
1750 |
'capability', |
|
1751 |
'capability__in', |
|
1752 |
'capability__not_in', |
|
1753 |
) |
|
1754 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1755 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1756 |
$fields = array( 'ID', 'user_login' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
|
16 | 1758 |
$show = ! empty( $parsed_args['show'] ) ? $parsed_args['show'] : 'display_name'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
if ( 'display_name_with_login' === $show ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1760 |
$fields[] = 'display_name'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
$fields[] = $show; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
$query_args['fields'] = $fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
|
16 | 1767 |
$show_option_all = $parsed_args['show_option_all']; |
1768 |
$show_option_none = $parsed_args['show_option_none']; |
|
1769 |
$option_none_value = $parsed_args['option_none_value']; |
|
0 | 1770 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
* Filters the query arguments for the list of users in the dropdown. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
* |
16 | 1776 |
* @param array $query_args The query arguments for get_users(). |
1777 |
* @param array $parsed_args The arguments passed to wp_dropdown_users() combined with the defaults. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
*/ |
16 | 1779 |
$query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $parsed_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
|
0 | 1781 |
$users = get_users( $query_args ); |
1782 |
||
1783 |
$output = ''; |
|
16 | 1784 |
if ( ! empty( $users ) && ( empty( $parsed_args['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
1785 |
$name = esc_attr( $parsed_args['name'] ); |
|
1786 |
if ( $parsed_args['multi'] && ! $parsed_args['id'] ) { |
|
0 | 1787 |
$id = ''; |
5 | 1788 |
} else { |
16 | 1789 |
$id = $parsed_args['id'] ? " id='" . esc_attr( $parsed_args['id'] ) . "'" : " id='$name'"; |
5 | 1790 |
} |
16 | 1791 |
$output = "<select name='{$name}'{$id} class='" . $parsed_args['class'] . "'>\n"; |
0 | 1792 |
|
5 | 1793 |
if ( $show_option_all ) { |
0 | 1794 |
$output .= "\t<option value='0'>$show_option_all</option>\n"; |
5 | 1795 |
} |
0 | 1796 |
|
1797 |
if ( $show_option_none ) { |
|
16 | 1798 |
$_selected = selected( $option_none_value, $parsed_args['selected'], false ); |
9 | 1799 |
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
0 | 1800 |
} |
1801 |
||
16 | 1802 |
if ( $parsed_args['include_selected'] && ( $parsed_args['selected'] > 0 ) ) { |
1803 |
$found_selected = false; |
|
1804 |
$parsed_args['selected'] = (int) $parsed_args['selected']; |
|
18 | 1805 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
foreach ( (array) $users as $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
$user->ID = (int) $user->ID; |
16 | 1808 |
if ( $user->ID === $parsed_args['selected'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
$found_selected = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1811 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
if ( ! $found_selected ) { |
18 | 1814 |
$selected_user = get_userdata( $parsed_args['selected'] ); |
1815 |
if ( $selected_user ) { |
|
1816 |
$users[] = $selected_user; |
|
1817 |
} |
|
5 | 1818 |
} |
0 | 1819 |
} |
1820 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
foreach ( (array) $users as $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
if ( 'display_name_with_login' === $show ) { |
16 | 1823 |
/* translators: 1: User's display name, 2: User login. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
$display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
} elseif ( ! empty( $user->$show ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
$display = $user->$show; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1827 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
$display = '(' . $user->user_login . ')'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1829 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1830 |
|
16 | 1831 |
$_selected = selected( $user->ID, $parsed_args['selected'], false ); |
9 | 1832 |
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
0 | 1833 |
} |
1834 |
||
9 | 1835 |
$output .= '</select>'; |
0 | 1836 |
} |
1837 |
||
5 | 1838 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1839 |
* Filters the wp_dropdown_users() HTML output. |
5 | 1840 |
* |
1841 |
* @since 2.3.0 |
|
1842 |
* |
|
1843 |
* @param string $output HTML output generated by wp_dropdown_users(). |
|
1844 |
*/ |
|
1845 |
$html = apply_filters( 'wp_dropdown_users', $output ); |
|
0 | 1846 |
|
16 | 1847 |
if ( $parsed_args['echo'] ) { |
5 | 1848 |
echo $html; |
1849 |
} |
|
1850 |
return $html; |
|
0 | 1851 |
} |
1852 |
||
1853 |
/** |
|
19 | 1854 |
* Sanitizes user field based on context. |
0 | 1855 |
* |
1856 |
* Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The |
|
1857 |
* 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display' |
|
1858 |
* when calling filters. |
|
1859 |
* |
|
1860 |
* @since 2.3.0 |
|
1861 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1862 |
* @param string $field The user Object field name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1863 |
* @param mixed $value The user Object value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1864 |
* @param int $user_id User ID. |
0 | 1865 |
* @param string $context How to sanitize user fields. Looks for 'raw', 'edit', 'db', 'display', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1866 |
* 'attribute' and 'js'. |
0 | 1867 |
* @return mixed Sanitized value. |
1868 |
*/ |
|
9 | 1869 |
function sanitize_user_field( $field, $value, $user_id, $context ) { |
1870 |
$int_fields = array( 'ID' ); |
|
16 | 1871 |
if ( in_array( $field, $int_fields, true ) ) { |
0 | 1872 |
$value = (int) $value; |
9 | 1873 |
} |
1874 |
||
16 | 1875 |
if ( 'raw' === $context ) { |
0 | 1876 |
return $value; |
9 | 1877 |
} |
1878 |
||
1879 |
if ( ! is_string( $value ) && ! is_numeric( $value ) ) { |
|
0 | 1880 |
return $value; |
9 | 1881 |
} |
0 | 1882 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1883 |
$prefixed = str_contains( $field, 'user_' ); |
0 | 1884 |
|
16 | 1885 |
if ( 'edit' === $context ) { |
0 | 1886 |
if ( $prefixed ) { |
5 | 1887 |
|
1888 |
/** This filter is documented in wp-includes/post.php */ |
|
1889 |
$value = apply_filters( "edit_{$field}", $value, $user_id ); |
|
0 | 1890 |
} else { |
5 | 1891 |
|
1892 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1893 |
* Filters a user field value in the 'edit' context. |
5 | 1894 |
* |
1895 |
* The dynamic portion of the hook name, `$field`, refers to the prefixed user |
|
1896 |
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
|
1897 |
* |
|
1898 |
* @since 2.9.0 |
|
1899 |
* |
|
1900 |
* @param mixed $value Value of the prefixed user field. |
|
1901 |
* @param int $user_id User ID. |
|
1902 |
*/ |
|
1903 |
$value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
|
0 | 1904 |
} |
1905 |
||
16 | 1906 |
if ( 'description' === $field ) { |
0 | 1907 |
$value = esc_html( $value ); // textarea_escaped? |
9 | 1908 |
} else { |
1909 |
$value = esc_attr( $value ); |
|
1910 |
} |
|
16 | 1911 |
} elseif ( 'db' === $context ) { |
0 | 1912 |
if ( $prefixed ) { |
5 | 1913 |
/** This filter is documented in wp-includes/post.php */ |
1914 |
$value = apply_filters( "pre_{$field}", $value ); |
|
0 | 1915 |
} else { |
5 | 1916 |
|
1917 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
* Filters the value of a user field in the 'db' context. |
5 | 1919 |
* |
1920 |
* The dynamic portion of the hook name, `$field`, refers to the prefixed user |
|
1921 |
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
|
9 | 1922 |
* |
5 | 1923 |
* @since 2.9.0 |
1924 |
* |
|
1925 |
* @param mixed $value Value of the prefixed user field. |
|
1926 |
*/ |
|
1927 |
$value = apply_filters( "pre_user_{$field}", $value ); |
|
0 | 1928 |
} |
1929 |
} else { |
|
1930 |
// Use display filters by default. |
|
5 | 1931 |
if ( $prefixed ) { |
1932 |
||
1933 |
/** This filter is documented in wp-includes/post.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
$value = apply_filters( "{$field}", $value, $user_id, $context ); |
5 | 1935 |
} else { |
1936 |
||
1937 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
* Filters the value of a user field in a standard context. |
5 | 1939 |
* |
1940 |
* The dynamic portion of the hook name, `$field`, refers to the prefixed user |
|
1941 |
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
|
1942 |
* |
|
1943 |
* @since 2.9.0 |
|
1944 |
* |
|
1945 |
* @param mixed $value The user object value to sanitize. |
|
1946 |
* @param int $user_id User ID. |
|
1947 |
* @param string $context The context to filter within. |
|
1948 |
*/ |
|
1949 |
$value = apply_filters( "user_{$field}", $value, $user_id, $context ); |
|
1950 |
} |
|
0 | 1951 |
} |
1952 |
||
16 | 1953 |
if ( 'user_url' === $field ) { |
9 | 1954 |
$value = esc_url( $value ); |
1955 |
} |
|
0 | 1956 |
|
16 | 1957 |
if ( 'attribute' === $context ) { |
5 | 1958 |
$value = esc_attr( $value ); |
16 | 1959 |
} elseif ( 'js' === $context ) { |
5 | 1960 |
$value = esc_js( $value ); |
1961 |
} |
|
18 | 1962 |
|
1963 |
// Restore the type for integer fields after esc_attr(). |
|
1964 |
if ( in_array( $field, $int_fields, true ) ) { |
|
1965 |
$value = (int) $value; |
|
1966 |
} |
|
1967 |
||
0 | 1968 |
return $value; |
1969 |
} |
|
1970 |
||
1971 |
/** |
|
19 | 1972 |
* Updates all user caches. |
0 | 1973 |
* |
1974 |
* @since 3.0.0 |
|
1975 |
* |
|
18 | 1976 |
* @param object|WP_User $user User object or database row to be cached |
1977 |
* @return void|false Void on success, false on failure. |
|
0 | 1978 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
function update_user_caches( $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
if ( $user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
if ( ! $user->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
$user = $user->data; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
|
9 | 1988 |
wp_cache_add( $user->ID, $user, 'users' ); |
1989 |
wp_cache_add( $user->user_login, $user->ID, 'userlogins' ); |
|
1990 |
wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1991 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1992 |
if ( ! empty( $user->user_email ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1993 |
wp_cache_add( $user->user_email, $user->ID, 'useremail' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1994 |
} |
0 | 1995 |
} |
1996 |
||
1997 |
/** |
|
19 | 1998 |
* Cleans all user caches. |
0 | 1999 |
* |
2000 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
* @since 4.4.0 'clean_user_cache' action was added. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2002 |
* @since 6.2.0 User metadata caches are now cleared. |
0 | 2003 |
* |
2004 |
* @param WP_User|int $user User object or ID to be cleaned from the cache |
|
2005 |
*/ |
|
2006 |
function clean_user_cache( $user ) { |
|
9 | 2007 |
if ( is_numeric( $user ) ) { |
0 | 2008 |
$user = new WP_User( $user ); |
9 | 2009 |
} |
2010 |
||
2011 |
if ( ! $user->exists() ) { |
|
0 | 2012 |
return; |
9 | 2013 |
} |
0 | 2014 |
|
2015 |
wp_cache_delete( $user->ID, 'users' ); |
|
2016 |
wp_cache_delete( $user->user_login, 'userlogins' ); |
|
2017 |
wp_cache_delete( $user->user_nicename, 'userslugs' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2019 |
if ( ! empty( $user->user_email ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2020 |
wp_cache_delete( $user->user_email, 'useremail' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2021 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2022 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2023 |
wp_cache_delete( $user->ID, 'user_meta' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2024 |
wp_cache_set_users_last_changed(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2025 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
* Fires immediately after the given user's cache is cleaned. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2030 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
* @param WP_User $user User object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
do_action( 'clean_user_cache', $user->ID, $user ); |
0 | 2035 |
} |
2036 |
||
2037 |
/** |
|
9 | 2038 |
* Determines whether the given username exists. |
2039 |
* |
|
2040 |
* For more information on this and similar theme functions, check out |
|
2041 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
2042 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 2043 |
* |
2044 |
* @since 2.0.0 |
|
2045 |
* |
|
18 | 2046 |
* @param string $username The username to check for existence. |
2047 |
* @return int|false The user ID on success, false on failure. |
|
0 | 2048 |
*/ |
2049 |
function username_exists( $username ) { |
|
9 | 2050 |
$user = get_user_by( 'login', $username ); |
2051 |
if ( $user ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
$user_id = $user->ID; |
0 | 2053 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
$user_id = false; |
0 | 2055 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
/** |
18 | 2058 |
* Filters whether the given username exists. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
* |
18 | 2062 |
* @param int|false $user_id The user ID associated with the username, |
2063 |
* or false if the username does not exist. |
|
2064 |
* @param string $username The username to check for existence. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2066 |
return apply_filters( 'username_exists', $user_id, $username ); |
0 | 2067 |
} |
2068 |
||
2069 |
/** |
|
9 | 2070 |
* Determines whether the given email exists. |
2071 |
* |
|
2072 |
* For more information on this and similar theme functions, check out |
|
2073 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
2074 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 2075 |
* |
2076 |
* @since 2.1.0 |
|
2077 |
* |
|
18 | 2078 |
* @param string $email The email to check for existence. |
2079 |
* @return int|false The user ID on success, false on failure. |
|
0 | 2080 |
*/ |
2081 |
function email_exists( $email ) { |
|
9 | 2082 |
$user = get_user_by( 'email', $email ); |
2083 |
if ( $user ) { |
|
18 | 2084 |
$user_id = $user->ID; |
2085 |
} else { |
|
2086 |
$user_id = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
} |
18 | 2088 |
|
2089 |
/** |
|
2090 |
* Filters whether the given email exists. |
|
2091 |
* |
|
2092 |
* @since 5.6.0 |
|
2093 |
* |
|
2094 |
* @param int|false $user_id The user ID associated with the email, |
|
2095 |
* or false if the email does not exist. |
|
2096 |
* @param string $email The email to check for existence. |
|
2097 |
*/ |
|
2098 |
return apply_filters( 'email_exists', $user_id, $email ); |
|
0 | 2099 |
} |
2100 |
||
2101 |
/** |
|
5 | 2102 |
* Checks whether a username is valid. |
0 | 2103 |
* |
2104 |
* @since 2.0.1 |
|
18 | 2105 |
* @since 4.4.0 Empty sanitized usernames are now considered invalid. |
0 | 2106 |
* |
2107 |
* @param string $username Username. |
|
18 | 2108 |
* @return bool Whether username given is valid. |
0 | 2109 |
*/ |
2110 |
function validate_username( $username ) { |
|
2111 |
$sanitized = sanitize_user( $username, true ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2112 |
$valid = ( $sanitized === $username && ! empty( $sanitized ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
|
5 | 2114 |
/** |
18 | 2115 |
* Filters whether the provided username is valid. |
5 | 2116 |
* |
2117 |
* @since 2.0.1 |
|
2118 |
* |
|
2119 |
* @param bool $valid Whether given username is valid. |
|
2120 |
* @param string $username Username to check. |
|
2121 |
*/ |
|
0 | 2122 |
return apply_filters( 'validate_username', $valid, $username ); |
2123 |
} |
|
2124 |
||
2125 |
/** |
|
19 | 2126 |
* Inserts a user into the database. |
0 | 2127 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2128 |
* Most of the `$userdata` array fields have filters associated with the values. Exceptions are |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
* 'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', |
16 | 2130 |
* 'user_registered', 'user_activation_key', 'spam', and 'role'. The filters have the prefix |
2131 |
* 'pre_user_' followed by the field name. An example using 'description' would have the filter |
|
2132 |
* called 'pre_user_description' that can be hooked into. |
|
0 | 2133 |
* |
5 | 2134 |
* @since 2.0.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2135 |
* @since 3.6.0 The `aim`, `jabber`, and `yim` fields were removed as default user contact |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2136 |
* methods for new installations. See wp_get_user_contact_methods(). |
19 | 2137 |
* @since 4.7.0 The `locale` field can be passed to `$userdata`. |
16 | 2138 |
* @since 5.3.0 The `user_activation_key` field can be passed to `$userdata`. |
2139 |
* @since 5.3.0 The `spam` field can be passed to `$userdata` (Multisite only). |
|
19 | 2140 |
* @since 5.9.0 The `meta_input` field can be passed to `$userdata` to allow addition of user meta data. |
5 | 2141 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2142 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 2143 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2144 |
* @param array|object|WP_User $userdata { |
5 | 2145 |
* An array, object, or WP_User object of user data arguments. |
0 | 2146 |
* |
16 | 2147 |
* @type int $ID User ID. If supplied, the user will be updated. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2148 |
* @type string $user_pass The plain-text user password for new users. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2149 |
* Hashed password for existing users. |
16 | 2150 |
* @type string $user_login The user's login username. |
2151 |
* @type string $user_nicename The URL-friendly user name. |
|
2152 |
* @type string $user_url The user URL. |
|
2153 |
* @type string $user_email The user email address. |
|
2154 |
* @type string $display_name The user's display name. |
|
2155 |
* Default is the user's username. |
|
2156 |
* @type string $nickname The user's nickname. |
|
2157 |
* Default is the user's username. |
|
2158 |
* @type string $first_name The user's first name. For new users, will be used |
|
2159 |
* to build the first part of the user's display name |
|
2160 |
* if `$display_name` is not specified. |
|
2161 |
* @type string $last_name The user's last name. For new users, will be used |
|
2162 |
* to build the second part of the user's display name |
|
2163 |
* if `$display_name` is not specified. |
|
2164 |
* @type string $description The user's biographical description. |
|
2165 |
* @type string $rich_editing Whether to enable the rich-editor for the user. |
|
2166 |
* Accepts 'true' or 'false' as a string literal, |
|
2167 |
* not boolean. Default 'true'. |
|
2168 |
* @type string $syntax_highlighting Whether to enable the rich code editor for the user. |
|
2169 |
* Accepts 'true' or 'false' as a string literal, |
|
2170 |
* not boolean. Default 'true'. |
|
2171 |
* @type string $comment_shortcuts Whether to enable comment moderation keyboard |
|
2172 |
* shortcuts for the user. Accepts 'true' or 'false' |
|
2173 |
* as a string literal, not boolean. Default 'false'. |
|
2174 |
* @type string $admin_color Admin color scheme for the user. Default 'fresh'. |
|
2175 |
* @type bool $use_ssl Whether the user should always access the admin over |
|
2176 |
* https. Default false. |
|
19 | 2177 |
* @type string $user_registered Date the user registered in UTC. Format is 'Y-m-d H:i:s'. |
16 | 2178 |
* @type string $user_activation_key Password reset key. Default empty. |
2179 |
* @type bool $spam Multisite only. Whether the user is marked as spam. |
|
2180 |
* Default false. |
|
2181 |
* @type string $show_admin_bar_front Whether to display the Admin Bar for the user |
|
2182 |
* on the site's front end. Accepts 'true' or 'false' |
|
2183 |
* as a string literal, not boolean. Default 'true'. |
|
2184 |
* @type string $role User's role. |
|
2185 |
* @type string $locale User's locale. Default empty. |
|
19 | 2186 |
* @type array $meta_input Array of custom user meta values keyed by meta key. |
2187 |
* Default empty. |
|
5 | 2188 |
* } |
2189 |
* @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not |
|
2190 |
* be created. |
|
0 | 2191 |
*/ |
2192 |
function wp_insert_user( $userdata ) { |
|
2193 |
global $wpdb; |
|
2194 |
||
5 | 2195 |
if ( $userdata instanceof stdClass ) { |
0 | 2196 |
$userdata = get_object_vars( $userdata ); |
5 | 2197 |
} elseif ( $userdata instanceof WP_User ) { |
0 | 2198 |
$userdata = $userdata->to_array(); |
5 | 2199 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
|
0 | 2201 |
// Are we updating or creating? |
5 | 2202 |
if ( ! empty( $userdata['ID'] ) ) { |
19 | 2203 |
$user_id = (int) $userdata['ID']; |
9 | 2204 |
$update = true; |
19 | 2205 |
$old_user_data = get_userdata( $user_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2207 |
if ( ! $old_user_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2210 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2211 |
// Slash current user email to compare it later with slashed new user email. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2212 |
$old_user_data->user_email = wp_slash( $old_user_data->user_email ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2213 |
|
16 | 2214 |
// Hashed in wp_update_user(), plaintext if called directly. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
$user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass; |
0 | 2216 |
} else { |
2217 |
$update = false; |
|
16 | 2218 |
// Hash the password. |
5 | 2219 |
$user_pass = wp_hash_password( $userdata['user_pass'] ); |
0 | 2220 |
} |
2221 |
||
5 | 2222 |
$sanitized_user_login = sanitize_user( $userdata['user_login'], true ); |
2223 |
||
2224 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2225 |
* Filters a username after it has been sanitized. |
5 | 2226 |
* |
2227 |
* This filter is called before the user is created or updated. |
|
2228 |
* |
|
2229 |
* @since 2.0.3 |
|
2230 |
* |
|
2231 |
* @param string $sanitized_user_login Username after it has been sanitized. |
|
2232 |
*/ |
|
2233 |
$pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); |
|
0 | 2234 |
|
16 | 2235 |
// Remove any non-printable chars from the login string to see if we have ended up with an empty username. |
5 | 2236 |
$user_login = trim( $pre_user_login ); |
0 | 2237 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
// user_login must be between 0 and 60 characters. |
5 | 2239 |
if ( empty( $user_login ) ) { |
9 | 2240 |
return new WP_Error( 'empty_user_login', __( 'Cannot create a user with an empty login name.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
} elseif ( mb_strlen( $user_login ) > 60 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); |
5 | 2243 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
|
5 | 2245 |
if ( ! $update && username_exists( $user_login ) ) { |
2246 |
return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); |
|
2247 |
} |
|
0 | 2248 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2249 |
/** |
16 | 2250 |
* Filters the list of disallowed usernames. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2253 |
* |
16 | 2254 |
* @param array $usernames Array of disallowed usernames. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2255 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2256 |
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2257 |
|
16 | 2258 |
if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2259 |
return new WP_Error( 'invalid_username', __( 'Sorry, that username is not allowed.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2260 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2261 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2262 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2263 |
* If a nicename is provided, remove unsafe user characters before using it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2264 |
* Otherwise build a nicename from the user_login. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2265 |
*/ |
5 | 2266 |
if ( ! empty( $userdata['user_nicename'] ) ) { |
2267 |
$user_nicename = sanitize_user( $userdata['user_nicename'], true ); |
|
2268 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
$user_nicename = mb_substr( $user_login, 0, 50 ); |
5 | 2270 |
} |
2271 |
||
2272 |
$user_nicename = sanitize_title( $user_nicename ); |
|
2273 |
||
2274 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
* Filters a user's nicename before the user is created or updated. |
5 | 2276 |
* |
2277 |
* @since 2.0.3 |
|
2278 |
* |
|
2279 |
* @param string $user_nicename The user's nicename. |
|
2280 |
*/ |
|
2281 |
$user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); |
|
2282 |
||
19 | 2283 |
if ( mb_strlen( $user_nicename ) > 50 ) { |
2284 |
return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) ); |
|
2285 |
} |
|
2286 |
||
16 | 2287 |
$user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) ); |
2288 |
||
2289 |
if ( $user_nicename_check ) { |
|
2290 |
$suffix = 2; |
|
2291 |
while ( $user_nicename_check ) { |
|
2292 |
// user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix. |
|
2293 |
$base_length = 49 - mb_strlen( $suffix ); |
|
2294 |
$alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix"; |
|
2295 |
$user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login ) ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2296 |
++$suffix; |
16 | 2297 |
} |
2298 |
$user_nicename = $alt_user_nicename; |
|
2299 |
} |
|
0 | 2300 |
|
5 | 2301 |
$raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email']; |
0 | 2302 |
|
5 | 2303 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2304 |
* Filters a user's email before the user is created or updated. |
5 | 2305 |
* |
2306 |
* @since 2.0.3 |
|
2307 |
* |
|
2308 |
* @param string $raw_user_email The user's email. |
|
2309 |
*/ |
|
2310 |
$user_email = apply_filters( 'pre_user_email', $raw_user_email ); |
|
0 | 2311 |
|
5 | 2312 |
/* |
2313 |
* If there is no update, just check for `email_exists`. If there is an update, |
|
18 | 2314 |
* check if current email and new email are the same, and check `email_exists` |
5 | 2315 |
* accordingly. |
2316 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) ) |
5 | 2318 |
&& ! defined( 'WP_IMPORTING' ) |
2319 |
&& email_exists( $user_email ) |
|
2320 |
) { |
|
2321 |
return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); |
|
2322 |
} |
|
16 | 2323 |
|
2324 |
$raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url']; |
|
2325 |
||
2326 |
/** |
|
2327 |
* Filters a user's URL before the user is created or updated. |
|
2328 |
* |
|
2329 |
* @since 2.0.3 |
|
2330 |
* |
|
2331 |
* @param string $raw_user_url The user's URL. |
|
2332 |
*/ |
|
2333 |
$user_url = apply_filters( 'pre_user_url', $raw_user_url ); |
|
2334 |
||
19 | 2335 |
if ( mb_strlen( $user_url ) > 100 ) { |
2336 |
return new WP_Error( 'user_url_too_long', __( 'User URL may not be longer than 100 characters.' ) ); |
|
2337 |
} |
|
2338 |
||
16 | 2339 |
$user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered']; |
2340 |
||
2341 |
$user_activation_key = empty( $userdata['user_activation_key'] ) ? '' : $userdata['user_activation_key']; |
|
2342 |
||
2343 |
if ( ! empty( $userdata['spam'] ) && ! is_multisite() ) { |
|
2344 |
return new WP_Error( 'no_spam', __( 'Sorry, marking a user as spam is only supported on Multisite.' ) ); |
|
2345 |
} |
|
2346 |
||
2347 |
$spam = empty( $userdata['spam'] ) ? 0 : (bool) $userdata['spam']; |
|
2348 |
||
2349 |
// Store values to save in user meta. |
|
2350 |
$meta = array(); |
|
2351 |
||
5 | 2352 |
$nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; |
0 | 2353 |
|
5 | 2354 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2355 |
* Filters a user's nickname before the user is created or updated. |
5 | 2356 |
* |
2357 |
* @since 2.0.3 |
|
2358 |
* |
|
2359 |
* @param string $nickname The user's nickname. |
|
2360 |
*/ |
|
2361 |
$meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname ); |
|
0 | 2362 |
|
5 | 2363 |
$first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name']; |
2364 |
||
2365 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
* Filters a user's first name before the user is created or updated. |
5 | 2367 |
* |
2368 |
* @since 2.0.3 |
|
2369 |
* |
|
2370 |
* @param string $first_name The user's first name. |
|
2371 |
*/ |
|
2372 |
$meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name ); |
|
0 | 2373 |
|
5 | 2374 |
$last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name']; |
2375 |
||
2376 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2377 |
* Filters a user's last name before the user is created or updated. |
5 | 2378 |
* |
2379 |
* @since 2.0.3 |
|
2380 |
* |
|
2381 |
* @param string $last_name The user's last name. |
|
2382 |
*/ |
|
2383 |
$meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name ); |
|
2384 |
||
2385 |
if ( empty( $userdata['display_name'] ) ) { |
|
2386 |
if ( $update ) { |
|
0 | 2387 |
$display_name = $user_login; |
5 | 2388 |
} elseif ( $meta['first_name'] && $meta['last_name'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2389 |
$display_name = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2390 |
/* translators: 1: User's first name, 2: Last name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2391 |
_x( '%1$s %2$s', 'Display name based on first name and last name' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2392 |
$meta['first_name'], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2393 |
$meta['last_name'] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2394 |
); |
5 | 2395 |
} elseif ( $meta['first_name'] ) { |
2396 |
$display_name = $meta['first_name']; |
|
2397 |
} elseif ( $meta['last_name'] ) { |
|
2398 |
$display_name = $meta['last_name']; |
|
2399 |
} else { |
|
0 | 2400 |
$display_name = $user_login; |
5 | 2401 |
} |
2402 |
} else { |
|
2403 |
$display_name = $userdata['display_name']; |
|
0 | 2404 |
} |
5 | 2405 |
|
2406 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
* Filters a user's display name before the user is created or updated. |
5 | 2408 |
* |
2409 |
* @since 2.0.3 |
|
2410 |
* |
|
2411 |
* @param string $display_name The user's display name. |
|
2412 |
*/ |
|
0 | 2413 |
$display_name = apply_filters( 'pre_user_display_name', $display_name ); |
2414 |
||
5 | 2415 |
$description = empty( $userdata['description'] ) ? '' : $userdata['description']; |
0 | 2416 |
|
5 | 2417 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* Filters a user's description before the user is created or updated. |
5 | 2419 |
* |
2420 |
* @since 2.0.3 |
|
2421 |
* |
|
2422 |
* @param string $description The user's description. |
|
2423 |
*/ |
|
2424 |
$meta['description'] = apply_filters( 'pre_user_description', $description ); |
|
0 | 2425 |
|
5 | 2426 |
$meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; |
2427 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2428 |
$meta['syntax_highlighting'] = empty( $userdata['syntax_highlighting'] ) ? 'true' : $userdata['syntax_highlighting']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2429 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2430 |
$meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
0 | 2431 |
|
9 | 2432 |
$admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color']; |
5 | 2433 |
$meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color ); |
0 | 2434 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2435 |
$meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? '0' : '1'; |
5 | 2436 |
|
2437 |
$meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; |
|
0 | 2438 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2439 |
$meta['locale'] = isset( $userdata['locale'] ) ? $userdata['locale'] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2440 |
|
16 | 2441 |
$compacted = compact( 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'user_activation_key', 'display_name' ); |
9 | 2442 |
$data = wp_unslash( $compacted ); |
0 | 2443 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2444 |
if ( ! $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2445 |
$data = $data + compact( 'user_login' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2446 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
|
16 | 2448 |
if ( is_multisite() ) { |
2449 |
$data = $data + compact( 'spam' ); |
|
2450 |
} |
|
2451 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2452 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2453 |
* Filters user data before the record is created or updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
* |
18 | 2455 |
* It only includes data in the users table, not any user metadata. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2456 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2457 |
* @since 4.9.0 |
19 | 2458 |
* @since 5.8.0 The `$userdata` parameter was added. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2459 |
* @since 6.8.0 The user's password is now hashed using bcrypt by default instead of phpass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2461 |
* @param array $data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
* Values and keys for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2464 |
* @type string $user_login The user's login. Only included if $update == false |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2465 |
* @type string $user_pass The user's password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2466 |
* @type string $user_email The user's email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
* @type string $user_url The user's url. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2468 |
* @type string $user_nicename The user's nice name. Defaults to a URL-safe version of user's login. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
* @type string $display_name The user's display name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2470 |
* @type string $user_registered MySQL timestamp describing the moment when the user registered. Defaults to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2471 |
* the current UTC timestamp. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2472 |
* } |
18 | 2473 |
* @param bool $update Whether the user is being updated rather than created. |
19 | 2474 |
* @param int|null $user_id ID of the user to be updated, or NULL if the user is being created. |
18 | 2475 |
* @param array $userdata The raw array of data passed to wp_insert_user(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2476 |
*/ |
19 | 2477 |
$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? $user_id : null ), $userdata ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
|
16 | 2479 |
if ( empty( $data ) || ! is_array( $data ) ) { |
2480 |
return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) ); |
|
2481 |
} |
|
2482 |
||
0 | 2483 |
if ( $update ) { |
16 | 2484 |
if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) { |
5 | 2485 |
$data['user_activation_key'] = ''; |
2486 |
} |
|
19 | 2487 |
$wpdb->update( $wpdb->users, $data, array( 'ID' => $user_id ) ); |
0 | 2488 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2489 |
$wpdb->insert( $wpdb->users, $data ); |
0 | 2490 |
$user_id = (int) $wpdb->insert_id; |
2491 |
} |
|
2492 |
||
2493 |
$user = new WP_User( $user_id ); |
|
2494 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2495 |
/** |
9 | 2496 |
* Filters a user's meta values and keys immediately after the user is created or updated |
2497 |
* and before any user meta is inserted or updated. |
|
2498 |
* |
|
2499 |
* Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. |
|
2500 |
* |
|
19 | 2501 |
* For custom meta fields, see the {@see 'insert_custom_user_meta'} filter. |
2502 |
* |
|
9 | 2503 |
* @since 4.4.0 |
19 | 2504 |
* @since 5.8.0 The `$userdata` parameter was added. |
9 | 2505 |
* |
2506 |
* @param array $meta { |
|
2507 |
* Default meta values and keys for the user. |
|
2508 |
* |
|
2509 |
* @type string $nickname The user's nickname. Default is the user's username. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2510 |
* @type string $first_name The user's first name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2511 |
* @type string $last_name The user's last name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2512 |
* @type string $description The user's description. |
16 | 2513 |
* @type string $rich_editing Whether to enable the rich-editor for the user. Default 'true'. |
2514 |
* @type string $syntax_highlighting Whether to enable the rich code editor for the user. Default 'true'. |
|
2515 |
* @type string $comment_shortcuts Whether to enable keyboard shortcuts for the user. Default 'false'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2516 |
* @type string $admin_color The color scheme for a user's admin screen. Default 'fresh'. |
16 | 2517 |
* @type int|bool $use_ssl Whether to force SSL on the user's admin area. 0|false if SSL |
2518 |
* is not forced. |
|
2519 |
* @type string $show_admin_bar_front Whether to show the admin bar on the front end for the user. |
|
2520 |
* Default 'true'. |
|
2521 |
* @type string $locale User's locale. Default empty. |
|
9 | 2522 |
* } |
18 | 2523 |
* @param WP_User $user User object. |
2524 |
* @param bool $update Whether the user is being updated rather than created. |
|
2525 |
* @param array $userdata The raw array of data passed to wp_insert_user(). |
|
9 | 2526 |
*/ |
18 | 2527 |
$meta = apply_filters( 'insert_user_meta', $meta, $user, $update, $userdata ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
|
19 | 2529 |
$custom_meta = array(); |
2530 |
if ( array_key_exists( 'meta_input', $userdata ) && is_array( $userdata['meta_input'] ) && ! empty( $userdata['meta_input'] ) ) { |
|
2531 |
$custom_meta = $userdata['meta_input']; |
|
2532 |
} |
|
2533 |
||
2534 |
/** |
|
2535 |
* Filters a user's custom meta values and keys immediately after the user is created or updated |
|
2536 |
* and before any user meta is inserted or updated. |
|
2537 |
* |
|
2538 |
* For non-custom meta fields, see the {@see 'insert_user_meta'} filter. |
|
2539 |
* |
|
2540 |
* @since 5.9.0 |
|
2541 |
* |
|
2542 |
* @param array $custom_meta Array of custom user meta values keyed by meta key. |
|
2543 |
* @param WP_User $user User object. |
|
2544 |
* @param bool $update Whether the user is being updated rather than created. |
|
2545 |
* @param array $userdata The raw array of data passed to wp_insert_user(). |
|
2546 |
*/ |
|
2547 |
$custom_meta = apply_filters( 'insert_custom_user_meta', $custom_meta, $user, $update, $userdata ); |
|
2548 |
||
2549 |
$meta = array_merge( $meta, $custom_meta ); |
|
2550 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2551 |
if ( $update ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2552 |
// Update user meta. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2553 |
foreach ( $meta as $key => $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2554 |
update_user_meta( $user_id, $key, $value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2555 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2556 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2557 |
// Add user meta. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2558 |
foreach ( $meta as $key => $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2559 |
add_user_meta( $user_id, $key, $value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2560 |
} |
5 | 2561 |
} |
2562 |
||
2563 |
foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) { |
|
2564 |
if ( isset( $userdata[ $key ] ) ) { |
|
2565 |
update_user_meta( $user_id, $key, $userdata[ $key ] ); |
|
2566 |
} |
|
0 | 2567 |
} |
2568 |
||
5 | 2569 |
if ( isset( $userdata['role'] ) ) { |
2570 |
$user->set_role( $userdata['role'] ); |
|
2571 |
} elseif ( ! $update ) { |
|
9 | 2572 |
$user->set_role( get_option( 'default_role' ) ); |
5 | 2573 |
} |
16 | 2574 |
|
2575 |
clean_user_cache( $user_id ); |
|
0 | 2576 |
|
5 | 2577 |
if ( $update ) { |
2578 |
/** |
|
2579 |
* Fires immediately after an existing user is updated. |
|
2580 |
* |
|
2581 |
* @since 2.0.0 |
|
19 | 2582 |
* @since 5.8.0 The `$userdata` parameter was added. |
5 | 2583 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2584 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2585 |
* @param WP_User $old_user_data Object containing user's data prior to update. |
18 | 2586 |
* @param array $userdata The raw array of data passed to wp_insert_user(). |
5 | 2587 |
*/ |
18 | 2588 |
do_action( 'profile_update', $user_id, $old_user_data, $userdata ); |
16 | 2589 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2590 |
if ( isset( $userdata['spam'] ) && $userdata['spam'] !== $old_user_data->spam ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2591 |
if ( '1' === $userdata['spam'] ) { |
16 | 2592 |
/** |
2593 |
* Fires after the user is marked as a SPAM user. |
|
2594 |
* |
|
2595 |
* @since 3.0.0 |
|
2596 |
* |
|
2597 |
* @param int $user_id ID of the user marked as SPAM. |
|
2598 |
*/ |
|
2599 |
do_action( 'make_spam_user', $user_id ); |
|
2600 |
} else { |
|
2601 |
/** |
|
2602 |
* Fires after the user is marked as a HAM user. Opposite of SPAM. |
|
2603 |
* |
|
2604 |
* @since 3.0.0 |
|
2605 |
* |
|
2606 |
* @param int $user_id ID of the user marked as HAM. |
|
2607 |
*/ |
|
2608 |
do_action( 'make_ham_user', $user_id ); |
|
2609 |
} |
|
2610 |
} |
|
5 | 2611 |
} else { |
2612 |
/** |
|
2613 |
* Fires immediately after a new user is registered. |
|
2614 |
* |
|
2615 |
* @since 1.5.0 |
|
19 | 2616 |
* @since 5.8.0 The `$userdata` parameter was added. |
5 | 2617 |
* |
18 | 2618 |
* @param int $user_id User ID. |
2619 |
* @param array $userdata The raw array of data passed to wp_insert_user(). |
|
5 | 2620 |
*/ |
18 | 2621 |
do_action( 'user_register', $user_id, $userdata ); |
5 | 2622 |
} |
0 | 2623 |
|
2624 |
return $user_id; |
|
2625 |
} |
|
2626 |
||
2627 |
/** |
|
19 | 2628 |
* Updates a user in the database. |
0 | 2629 |
* |
2630 |
* It is possible to update a user's password by specifying the 'user_pass' |
|
2631 |
* value in the $userdata parameter array. |
|
2632 |
* |
|
2633 |
* If current user's password is being updated, then the cookies will be |
|
2634 |
* cleared. |
|
2635 |
* |
|
2636 |
* @since 2.0.0 |
|
5 | 2637 |
* |
2638 |
* @see wp_insert_user() For what fields can be set in $userdata. |
|
0 | 2639 |
* |
9 | 2640 |
* @param array|object|WP_User $userdata An array of user data or a user object of type stdClass or WP_User. |
0 | 2641 |
* @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. |
2642 |
*/ |
|
9 | 2643 |
function wp_update_user( $userdata ) { |
5 | 2644 |
if ( $userdata instanceof stdClass ) { |
0 | 2645 |
$userdata = get_object_vars( $userdata ); |
5 | 2646 |
} elseif ( $userdata instanceof WP_User ) { |
0 | 2647 |
$userdata = $userdata->to_array(); |
5 | 2648 |
} |
0 | 2649 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2650 |
$userdata_raw = $userdata; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2651 |
|
19 | 2652 |
$user_id = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0; |
2653 |
if ( ! $user_id ) { |
|
5 | 2654 |
return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
2655 |
} |
|
0 | 2656 |
|
16 | 2657 |
// First, get all of the original fields. |
19 | 2658 |
$user_obj = get_userdata( $user_id ); |
5 | 2659 |
if ( ! $user_obj ) { |
0 | 2660 |
return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
5 | 2661 |
} |
0 | 2662 |
|
2663 |
$user = $user_obj->to_array(); |
|
2664 |
||
16 | 2665 |
// Add additional custom fields. |
0 | 2666 |
foreach ( _get_additional_user_keys( $user_obj ) as $key ) { |
19 | 2667 |
$user[ $key ] = get_user_meta( $user_id, $key, true ); |
0 | 2668 |
} |
2669 |
||
2670 |
// Escape data pulled from DB. |
|
2671 |
$user = add_magic_quotes( $user ); |
|
2672 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) { |
16 | 2674 |
// If password is changing, hash it now. |
9 | 2675 |
$plaintext_pass = $userdata['user_pass']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2676 |
$userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2678 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2679 |
* Filters whether to send the password change email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2680 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2681 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2683 |
* @see wp_insert_user() For `$user` and `$userdata` fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2684 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2685 |
* @param bool $send Whether to send the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2686 |
* @param array $user The original user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2687 |
* @param array $userdata The updated user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2688 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2689 |
$send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata ); |
0 | 2690 |
} |
2691 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2692 |
if ( isset( $userdata['user_email'] ) && $user['user_email'] !== $userdata['user_email'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2693 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2694 |
* Filters whether to send the email change email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2696 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2697 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2698 |
* @see wp_insert_user() For `$user` and `$userdata` fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2699 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
* @param bool $send Whether to send the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
* @param array $user The original user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
* @param array $userdata The updated user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2704 |
$send_email_change_email = apply_filters( 'send_email_change_email', true, $user, $userdata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2705 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2706 |
|
16 | 2707 |
clean_user_cache( $user_obj ); |
0 | 2708 |
|
2709 |
// Merge old and new fields with new fields overwriting old ones. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2710 |
$userdata = array_merge( $user, $userdata ); |
9 | 2711 |
$user_id = wp_insert_user( $userdata ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2712 |
|
19 | 2713 |
if ( is_wp_error( $user_id ) ) { |
2714 |
return $user_id; |
|
2715 |
} |
|
2716 |
||
2717 |
$blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
2718 |
||
2719 |
$switched_locale = false; |
|
2720 |
if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2721 |
$switched_locale = switch_to_user_locale( $user_id ); |
19 | 2722 |
} |
2723 |
||
2724 |
if ( ! empty( $send_password_change_email ) ) { |
|
2725 |
/* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
|
2726 |
$pass_change_text = __( |
|
2727 |
'Hi ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2728 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2729 |
This notice confirms that your password was changed on ###SITENAME###. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2731 |
If you did not change your password, please contact the Site Administrator at |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2732 |
###ADMIN_EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2733 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2734 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2735 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2736 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2737 |
All at ###SITENAME### |
9 | 2738 |
###SITEURL###' |
19 | 2739 |
); |
2740 |
||
2741 |
$pass_change_email = array( |
|
2742 |
'to' => $user['user_email'], |
|
2743 |
/* translators: Password change notification email subject. %s: Site title. */ |
|
2744 |
'subject' => __( '[%s] Password Changed' ), |
|
2745 |
'message' => $pass_change_text, |
|
2746 |
'headers' => '', |
|
2747 |
); |
|
2748 |
||
2749 |
/** |
|
2750 |
* Filters the contents of the email sent when the user's password is changed. |
|
2751 |
* |
|
2752 |
* @since 4.3.0 |
|
2753 |
* |
|
2754 |
* @param array $pass_change_email { |
|
2755 |
* Used to build wp_mail(). |
|
2756 |
* |
|
2757 |
* @type string $to The intended recipients. Add emails in a comma separated string. |
|
2758 |
* @type string $subject The subject of the email. |
|
2759 |
* @type string $message The content of the email. |
|
2760 |
* The following strings have a special meaning and will get replaced dynamically: |
|
2761 |
* - ###USERNAME### The current user's username. |
|
2762 |
* - ###ADMIN_EMAIL### The admin email in case this was unexpected. |
|
2763 |
* - ###EMAIL### The user's email address. |
|
2764 |
* - ###SITENAME### The name of the site. |
|
2765 |
* - ###SITEURL### The URL to the site. |
|
2766 |
* @type string $headers Headers. Add headers in a newline (\r\n) separated string. |
|
2767 |
* } |
|
2768 |
* @param array $user The original user array. |
|
2769 |
* @param array $userdata The updated user array. |
|
2770 |
*/ |
|
2771 |
$pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata ); |
|
2772 |
||
2773 |
$pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] ); |
|
2774 |
$pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] ); |
|
2775 |
$pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] ); |
|
2776 |
$pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] ); |
|
2777 |
$pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] ); |
|
2778 |
||
2779 |
wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] ); |
|
2780 |
} |
|
2781 |
||
2782 |
if ( ! empty( $send_email_change_email ) ) { |
|
2783 |
/* translators: Do not translate USERNAME, ADMIN_EMAIL, NEW_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
|
2784 |
$email_change_text = __( |
|
2785 |
'Hi ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2787 |
This notice confirms that your email address on ###SITENAME### was changed to ###NEW_EMAIL###. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2789 |
If you did not change your email, please contact the Site Administrator at |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2790 |
###ADMIN_EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2791 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2792 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2793 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2794 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2795 |
All at ###SITENAME### |
9 | 2796 |
###SITEURL###' |
19 | 2797 |
); |
2798 |
||
2799 |
$email_change_email = array( |
|
2800 |
'to' => $user['user_email'], |
|
2801 |
/* translators: Email change notification email subject. %s: Site title. */ |
|
2802 |
'subject' => __( '[%s] Email Changed' ), |
|
2803 |
'message' => $email_change_text, |
|
2804 |
'headers' => '', |
|
2805 |
); |
|
2806 |
||
2807 |
/** |
|
2808 |
* Filters the contents of the email sent when the user's email is changed. |
|
2809 |
* |
|
2810 |
* @since 4.3.0 |
|
2811 |
* |
|
2812 |
* @param array $email_change_email { |
|
2813 |
* Used to build wp_mail(). |
|
2814 |
* |
|
2815 |
* @type string $to The intended recipients. |
|
2816 |
* @type string $subject The subject of the email. |
|
2817 |
* @type string $message The content of the email. |
|
2818 |
* The following strings have a special meaning and will get replaced dynamically: |
|
2819 |
* - ###USERNAME### The current user's username. |
|
2820 |
* - ###ADMIN_EMAIL### The admin email in case this was unexpected. |
|
2821 |
* - ###NEW_EMAIL### The new email address. |
|
2822 |
* - ###EMAIL### The old email address. |
|
2823 |
* - ###SITENAME### The name of the site. |
|
2824 |
* - ###SITEURL### The URL to the site. |
|
2825 |
* @type string $headers Headers. |
|
2826 |
* } |
|
2827 |
* @param array $user The original user array. |
|
2828 |
* @param array $userdata The updated user array. |
|
2829 |
*/ |
|
2830 |
$email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata ); |
|
2831 |
||
2832 |
$email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] ); |
|
2833 |
$email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] ); |
|
2834 |
$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $userdata['user_email'], $email_change_email['message'] ); |
|
2835 |
$email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] ); |
|
2836 |
$email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] ); |
|
2837 |
$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); |
|
2838 |
||
2839 |
wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); |
|
2840 |
} |
|
2841 |
||
2842 |
if ( $switched_locale ) { |
|
2843 |
restore_previous_locale(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
} |
0 | 2845 |
|
2846 |
// Update the cookies if the password changed. |
|
2847 |
$current_user = wp_get_current_user(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2848 |
if ( $current_user->ID === $user_id ) { |
9 | 2849 |
if ( isset( $plaintext_pass ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2850 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2851 |
* Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2852 |
* If it's greater than this, then we know the user checked 'Remember Me' when they logged in. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2853 |
*/ |
9 | 2854 |
$logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
5 | 2855 |
/** This filter is documented in wp-includes/pluggable.php */ |
19 | 2856 |
$default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $user_id, false ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2857 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2858 |
wp_clear_auth_cookie(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2859 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2860 |
$remember = false; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2861 |
$token = ''; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2862 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2863 |
if ( false !== $logged_in_cookie ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2864 |
$token = $logged_in_cookie['token']; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2865 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2866 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2867 |
if ( false !== $logged_in_cookie && ( (int) $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ) { |
16 | 2868 |
$remember = true; |
2869 |
} |
|
5 | 2870 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2871 |
wp_set_auth_cookie( $user_id, $remember, '', $token ); |
0 | 2872 |
} |
2873 |
} |
|
2874 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2875 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2876 |
* Fires after the user has been updated and emails have been sent. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2877 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2878 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2879 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2880 |
* @param int $user_id The ID of the user that was just updated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2881 |
* @param array $userdata The array of user data that was updated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2882 |
* @param array $userdata_raw The unedited array of user data that was updated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2883 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2884 |
do_action( 'wp_update_user', $user_id, $userdata, $userdata_raw ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2885 |
|
0 | 2886 |
return $user_id; |
2887 |
} |
|
2888 |
||
2889 |
/** |
|
19 | 2890 |
* Provides a simpler way of inserting a user into the database. |
0 | 2891 |
* |
2892 |
* Creates a new user with just the username, password, and email. For more |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2893 |
* complex user creation use wp_insert_user() to specify more information. |
0 | 2894 |
* |
2895 |
* @since 2.0.0 |
|
16 | 2896 |
* |
2897 |
* @see wp_insert_user() More complete way to create a new user. |
|
0 | 2898 |
* |
2899 |
* @param string $username The user's username. |
|
2900 |
* @param string $password The user's password. |
|
5 | 2901 |
* @param string $email Optional. The user's email. Default empty. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2902 |
* @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2903 |
* be created. |
0 | 2904 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2905 |
function wp_create_user( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2906 |
$username, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2907 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2908 |
$password, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2909 |
$email = '' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2910 |
) { |
0 | 2911 |
$user_login = wp_slash( $username ); |
9 | 2912 |
$user_email = wp_slash( $email ); |
2913 |
$user_pass = $password; |
|
2914 |
||
2915 |
$userdata = compact( 'user_login', 'user_email', 'user_pass' ); |
|
2916 |
return wp_insert_user( $userdata ); |
|
0 | 2917 |
} |
2918 |
||
2919 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
* Returns a list of meta keys to be (maybe) populated in wp_update_user(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
* The list of keys returned via this function are dependent on the presence |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
* of those keys in the user meta data to be set. |
0 | 2924 |
* |
2925 |
* @since 3.3.0 |
|
2926 |
* @access private |
|
2927 |
* |
|
5 | 2928 |
* @param WP_User $user WP_User instance. |
16 | 2929 |
* @return string[] List of user keys to be populated in wp_update_user(). |
0 | 2930 |
*/ |
2931 |
function _get_additional_user_keys( $user ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
$keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' ); |
0 | 2933 |
return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); |
2934 |
} |
|
2935 |
||
2936 |
/** |
|
19 | 2937 |
* Sets up the user contact methods. |
0 | 2938 |
* |
2939 |
* Default contact methods were removed in 3.6. A filter dictates contact methods. |
|
2940 |
* |
|
2941 |
* @since 3.7.0 |
|
2942 |
* |
|
19 | 2943 |
* @param WP_User|null $user Optional. WP_User object. |
16 | 2944 |
* @return string[] Array of contact method labels keyed by contact method. |
0 | 2945 |
*/ |
2946 |
function wp_get_user_contact_methods( $user = null ) { |
|
2947 |
$methods = array(); |
|
2948 |
if ( get_site_option( 'initial_db_version' ) < 23588 ) { |
|
2949 |
$methods = array( |
|
2950 |
'aim' => __( 'AIM' ), |
|
2951 |
'yim' => __( 'Yahoo IM' ), |
|
9 | 2952 |
'jabber' => __( 'Jabber / Google Talk' ), |
0 | 2953 |
); |
2954 |
} |
|
2955 |
||
2956 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2957 |
* Filters the user contact methods. |
0 | 2958 |
* |
2959 |
* @since 2.9.0 |
|
2960 |
* |
|
19 | 2961 |
* @param string[] $methods Array of contact method labels keyed by contact method. |
2962 |
* @param WP_User|null $user WP_User object or null if none was provided. |
|
0 | 2963 |
*/ |
2964 |
return apply_filters( 'user_contactmethods', $methods, $user ); |
|
2965 |
} |
|
2966 |
||
2967 |
/** |
|
2968 |
* The old private function for setting up user contact methods. |
|
2969 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2970 |
* Use wp_get_user_contact_methods() instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
* |
0 | 2972 |
* @since 2.9.0 |
2973 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2974 |
* |
19 | 2975 |
* @param WP_User|null $user Optional. WP_User object. Default null. |
16 | 2976 |
* @return string[] Array of contact method labels keyed by contact method. |
0 | 2977 |
*/ |
2978 |
function _wp_get_user_contactmethods( $user = null ) { |
|
2979 |
return wp_get_user_contact_methods( $user ); |
|
2980 |
} |
|
2981 |
||
2982 |
/** |
|
5 | 2983 |
* Gets the text suggesting how to create strong passwords. |
2984 |
* |
|
2985 |
* @since 4.1.0 |
|
2986 |
* |
|
2987 |
* @return string The password hint text. |
|
2988 |
*/ |
|
2989 |
function wp_get_password_hint() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2990 |
$hint = __( 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' ); |
5 | 2991 |
|
2992 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2993 |
* Filters the text describing the site's password complexity policy. |
5 | 2994 |
* |
2995 |
* @since 4.1.0 |
|
2996 |
* |
|
2997 |
* @param string $hint The password hint text. |
|
2998 |
*/ |
|
2999 |
return apply_filters( 'password_hint', $hint ); |
|
3000 |
} |
|
3001 |
||
3002 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
* Creates, stores, then returns a password reset key for user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* @param WP_User $user User to retrieve password reset key for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3008 |
* @return string|WP_Error Password reset key on success. WP_Error on error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3009 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
function get_password_reset_key( $user ) { |
9 | 3011 |
if ( ! ( $user instanceof WP_User ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3012 |
return new WP_Error( 'invalidcombo', __( '<strong>Error:</strong> There is no account with that username or email address.' ) ); |
9 | 3013 |
} |
3014 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3015 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
* Fires before a new password is retrieved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
* Use the {@see 'retrieve_password'} hook instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3020 |
* @since 1.5.0 |
16 | 3021 |
* @deprecated 1.5.1 Misspelled. Use {@see 'retrieve_password'} hook instead. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3022 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3023 |
* @param string $user_login The user login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3024 |
*/ |
16 | 3025 |
do_action_deprecated( 'retreive_password', array( $user->user_login ), '1.5.1', 'retrieve_password' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3026 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3027 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3028 |
* Fires before a new password is retrieved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3029 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
* @since 1.5.1 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3032 |
* @param string $user_login The user login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3034 |
do_action( 'retrieve_password', $user->user_login ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3035 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3036 |
$password_reset_allowed = wp_is_password_reset_allowed_for_user( $user ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3037 |
if ( ! $password_reset_allowed ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user' ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3039 |
} elseif ( is_wp_error( $password_reset_allowed ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3040 |
return $password_reset_allowed; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3041 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3042 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3043 |
// Generate something random for a password reset key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3044 |
$key = wp_generate_password( 20, false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3045 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3046 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3047 |
* Fires when a password reset key is generated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3048 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3049 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3050 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3051 |
* @param string $user_login The username for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
* @param string $key The generated password reset key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3053 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3054 |
do_action( 'retrieve_password_key', $user->user_login, $key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3055 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3056 |
$hashed = time() . ':' . wp_fast_hash( $key ); |
16 | 3057 |
|
3058 |
$key_saved = wp_update_user( |
|
3059 |
array( |
|
3060 |
'ID' => $user->ID, |
|
3061 |
'user_activation_key' => $hashed, |
|
3062 |
) |
|
3063 |
); |
|
3064 |
||
3065 |
if ( is_wp_error( $key_saved ) ) { |
|
3066 |
return $key_saved; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3068 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3069 |
return $key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
/** |
19 | 3073 |
* Retrieves a user row based on password reset key and login. |
0 | 3074 |
* |
3075 |
* A key is considered 'expired' if it exactly matches the value of the |
|
3076 |
* user_activation_key field, rather than being matched after going through the |
|
3077 |
* hashing process. This field is now hashed; old values are no longer accepted |
|
3078 |
* but have a different WP_Error code so good user feedback can be provided. |
|
3079 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3082 |
* @param string $key The password reset key. |
0 | 3083 |
* @param string $login The user login. |
3084 |
* @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys. |
|
3085 |
*/ |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3086 |
function check_password_reset_key( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3087 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3088 |
$key, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3089 |
$login |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3090 |
) { |
9 | 3091 |
$key = preg_replace( '/[^a-z0-9]/i', '', $key ); |
3092 |
||
3093 |
if ( empty( $key ) || ! is_string( $key ) ) { |
|
3094 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
|
3095 |
} |
|
3096 |
||
3097 |
if ( empty( $login ) || ! is_string( $login ) ) { |
|
3098 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
|
3099 |
} |
|
0 | 3100 |
|
16 | 3101 |
$user = get_user_by( 'login', $login ); |
3102 |
||
3103 |
if ( ! $user ) { |
|
9 | 3104 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
3105 |
} |
|
0 | 3106 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3108 |
* Filters the expiration time of password reset keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3109 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3112 |
* @param int $expiration The expiration time in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3113 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
$expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3116 |
if ( str_contains( $user->user_activation_key, ':' ) ) { |
16 | 3117 |
list( $pass_request_time, $pass_key ) = explode( ':', $user->user_activation_key, 2 ); |
9 | 3118 |
$expiration_time = $pass_request_time + $expiration_duration; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
} else { |
16 | 3120 |
$pass_key = $user->user_activation_key; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
$expiration_time = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
if ( ! $pass_key ) { |
9 | 3125 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3128 |
$hash_is_correct = wp_verify_fast_hash( $key, $pass_key ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3129 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { |
16 | 3131 |
return $user; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3132 |
} elseif ( $hash_is_correct && $expiration_time ) { |
16 | 3133 |
// Key has an expiration time that's passed. |
9 | 3134 |
return new WP_Error( 'expired_key', __( 'Invalid key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3135 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
|
16 | 3137 |
if ( hash_equals( $user->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) { |
9 | 3138 |
$return = new WP_Error( 'expired_key', __( 'Invalid key.' ) ); |
16 | 3139 |
$user_id = $user->ID; |
0 | 3140 |
|
3141 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
* Filters the return value of check_password_reset_key() when an |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3143 |
* old-style key or an expired key is used. |
0 | 3144 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3145 |
* @since 3.7.0 Previously plain-text keys were stored in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3146 |
* @since 4.3.0 Previously key hashes were stored without an expiration time. |
0 | 3147 |
* |
3148 |
* @param WP_Error $return A WP_Error object denoting an expired key. |
|
3149 |
* Return a WP_User object to validate the key. |
|
3150 |
* @param int $user_id The matched user ID. |
|
3151 |
*/ |
|
3152 |
return apply_filters( 'password_reset_key_expired', $return, $user_id ); |
|
3153 |
} |
|
3154 |
||
9 | 3155 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
0 | 3156 |
} |
3157 |
||
3158 |
/** |
|
18 | 3159 |
* Handles sending a password retrieval email to a user. |
3160 |
* |
|
3161 |
* @since 2.5.0 |
|
3162 |
* @since 5.7.0 Added `$user_login` parameter. |
|
3163 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3164 |
* @global wpdb $wpdb WordPress database abstraction object. |
18 | 3165 |
* |
3166 |
* @param string $user_login Optional. Username to send a password retrieval email for. |
|
3167 |
* Defaults to `$_POST['user_login']` if not set. |
|
3168 |
* @return true|WP_Error True when finished, WP_Error object on error. |
|
3169 |
*/ |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3170 |
function retrieve_password( $user_login = '' ) { |
18 | 3171 |
$errors = new WP_Error(); |
3172 |
$user_data = false; |
|
3173 |
||
3174 |
// Use the passed $user_login if available, otherwise use $_POST['user_login']. |
|
3175 |
if ( ! $user_login && ! empty( $_POST['user_login'] ) ) { |
|
3176 |
$user_login = $_POST['user_login']; |
|
3177 |
} |
|
3178 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3179 |
$user_login = trim( wp_unslash( $user_login ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3180 |
|
18 | 3181 |
if ( empty( $user_login ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3182 |
$errors->add( 'empty_username', __( '<strong>Error:</strong> Please enter a username or email address.' ) ); |
18 | 3183 |
} elseif ( strpos( $user_login, '@' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3184 |
$user_data = get_user_by( 'email', $user_login ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3185 |
|
18 | 3186 |
if ( empty( $user_data ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3187 |
$user_data = get_user_by( 'login', $user_login ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3188 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3189 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3190 |
if ( empty( $user_data ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3191 |
$errors->add( 'invalid_email', __( '<strong>Error:</strong> There is no account with that username or email address.' ) ); |
18 | 3192 |
} |
3193 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3194 |
$user_data = get_user_by( 'login', $user_login ); |
18 | 3195 |
} |
3196 |
||
3197 |
/** |
|
3198 |
* Filters the user data during a password reset request. |
|
3199 |
* |
|
3200 |
* Allows, for example, custom validation using data other than username or email address. |
|
3201 |
* |
|
3202 |
* @since 5.7.0 |
|
3203 |
* |
|
3204 |
* @param WP_User|false $user_data WP_User object if found, false if the user does not exist. |
|
3205 |
* @param WP_Error $errors A WP_Error object containing any errors generated |
|
3206 |
* by using invalid credentials. |
|
3207 |
*/ |
|
3208 |
$user_data = apply_filters( 'lostpassword_user_data', $user_data, $errors ); |
|
3209 |
||
3210 |
/** |
|
3211 |
* Fires before errors are returned from a password reset request. |
|
3212 |
* |
|
3213 |
* @since 2.1.0 |
|
3214 |
* @since 4.4.0 Added the `$errors` parameter. |
|
3215 |
* @since 5.4.0 Added the `$user_data` parameter. |
|
3216 |
* |
|
3217 |
* @param WP_Error $errors A WP_Error object containing any errors generated |
|
3218 |
* by using invalid credentials. |
|
3219 |
* @param WP_User|false $user_data WP_User object if found, false if the user does not exist. |
|
3220 |
*/ |
|
3221 |
do_action( 'lostpassword_post', $errors, $user_data ); |
|
3222 |
||
3223 |
/** |
|
3224 |
* Filters the errors encountered on a password reset request. |
|
3225 |
* |
|
3226 |
* The filtered WP_Error object may, for example, contain errors for an invalid |
|
3227 |
* username or email address. A WP_Error object should always be returned, |
|
3228 |
* but may or may not contain errors. |
|
3229 |
* |
|
3230 |
* If any errors are present in $errors, this will abort the password reset request. |
|
3231 |
* |
|
3232 |
* @since 5.5.0 |
|
3233 |
* |
|
3234 |
* @param WP_Error $errors A WP_Error object containing any errors generated |
|
3235 |
* by using invalid credentials. |
|
3236 |
* @param WP_User|false $user_data WP_User object if found, false if the user does not exist. |
|
3237 |
*/ |
|
3238 |
$errors = apply_filters( 'lostpassword_errors', $errors, $user_data ); |
|
3239 |
||
3240 |
if ( $errors->has_errors() ) { |
|
3241 |
return $errors; |
|
3242 |
} |
|
3243 |
||
3244 |
if ( ! $user_data ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3245 |
$errors->add( 'invalidcombo', __( '<strong>Error:</strong> There is no account with that username or email address.' ) ); |
18 | 3246 |
return $errors; |
3247 |
} |
|
3248 |
||
19 | 3249 |
/** |
3250 |
* Filters whether to send the retrieve password email. |
|
3251 |
* |
|
3252 |
* Return false to disable sending the email. |
|
3253 |
* |
|
3254 |
* @since 6.0.0 |
|
3255 |
* |
|
3256 |
* @param bool $send Whether to send the email. |
|
3257 |
* @param string $user_login The username for the user. |
|
3258 |
* @param WP_User $user_data WP_User object. |
|
3259 |
*/ |
|
3260 |
if ( ! apply_filters( 'send_retrieve_password_email', true, $user_login, $user_data ) ) { |
|
3261 |
return true; |
|
3262 |
} |
|
3263 |
||
18 | 3264 |
// Redefining user_login ensures we return the right case in the email. |
3265 |
$user_login = $user_data->user_login; |
|
3266 |
$user_email = $user_data->user_email; |
|
3267 |
$key = get_password_reset_key( $user_data ); |
|
3268 |
||
3269 |
if ( is_wp_error( $key ) ) { |
|
3270 |
return $key; |
|
3271 |
} |
|
3272 |
||
3273 |
// Localize password reset message content for user. |
|
3274 |
$locale = get_user_locale( $user_data ); |
|
3275 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3276 |
$switched_locale = switch_to_user_locale( $user_data->ID ); |
18 | 3277 |
|
3278 |
if ( is_multisite() ) { |
|
3279 |
$site_name = get_network()->site_name; |
|
3280 |
} else { |
|
3281 |
/* |
|
3282 |
* The blogname option is escaped with esc_html on the way into the database |
|
3283 |
* in sanitize_option. We want to reverse this for the plain text arena of emails. |
|
3284 |
*/ |
|
3285 |
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
3286 |
} |
|
3287 |
||
3288 |
$message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n"; |
|
3289 |
/* translators: %s: Site name. */ |
|
3290 |
$message .= sprintf( __( 'Site Name: %s' ), $site_name ) . "\r\n\r\n"; |
|
3291 |
/* translators: %s: User login. */ |
|
3292 |
$message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n"; |
|
3293 |
$message .= __( 'If this was a mistake, ignore this email and nothing will happen.' ) . "\r\n\r\n"; |
|
3294 |
$message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n"; |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3295 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3296 |
/* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3297 |
* Since some user login names end in a period, this could produce ambiguous URLs that |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3298 |
* end in a period. To avoid the ambiguity, ensure that the login is not the last query |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3299 |
* arg in the URL. If moving it to the end, a trailing period will need to be escaped. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3300 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3301 |
* @see https://core.trac.wordpress.org/tickets/42957 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3302 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3303 |
$message .= network_site_url( 'wp-login.php?login=' . rawurlencode( $user_login ) . "&key=$key&action=rp", 'login' ) . '&wp_lang=' . $locale . "\r\n\r\n"; |
18 | 3304 |
|
3305 |
if ( ! is_user_logged_in() ) { |
|
3306 |
$requester_ip = $_SERVER['REMOTE_ADDR']; |
|
3307 |
if ( $requester_ip ) { |
|
3308 |
$message .= sprintf( |
|
3309 |
/* translators: %s: IP address of password reset requester. */ |
|
3310 |
__( 'This password reset request originated from the IP address %s.' ), |
|
3311 |
$requester_ip |
|
3312 |
) . "\r\n"; |
|
3313 |
} |
|
3314 |
} |
|
3315 |
||
3316 |
/* translators: Password reset notification email subject. %s: Site title. */ |
|
3317 |
$title = sprintf( __( '[%s] Password Reset' ), $site_name ); |
|
3318 |
||
3319 |
/** |
|
3320 |
* Filters the subject of the password reset email. |
|
3321 |
* |
|
3322 |
* @since 2.8.0 |
|
3323 |
* @since 4.4.0 Added the `$user_login` and `$user_data` parameters. |
|
3324 |
* |
|
3325 |
* @param string $title Email subject. |
|
3326 |
* @param string $user_login The username for the user. |
|
3327 |
* @param WP_User $user_data WP_User object. |
|
3328 |
*/ |
|
3329 |
$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data ); |
|
3330 |
||
3331 |
/** |
|
3332 |
* Filters the message body of the password reset mail. |
|
3333 |
* |
|
3334 |
* If the filtered message is empty, the password reset email will not be sent. |
|
3335 |
* |
|
3336 |
* @since 2.8.0 |
|
3337 |
* @since 4.1.0 Added `$user_login` and `$user_data` parameters. |
|
3338 |
* |
|
3339 |
* @param string $message Email message. |
|
3340 |
* @param string $key The activation key. |
|
3341 |
* @param string $user_login The username for the user. |
|
3342 |
* @param WP_User $user_data WP_User object. |
|
3343 |
*/ |
|
3344 |
$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data ); |
|
3345 |
||
19 | 3346 |
// Short-circuit on falsey $message value for backwards compatibility. |
3347 |
if ( ! $message ) { |
|
3348 |
return true; |
|
3349 |
} |
|
3350 |
||
3351 |
/* |
|
3352 |
* Wrap the single notification email arguments in an array |
|
3353 |
* to pass them to the retrieve_password_notification_email filter. |
|
3354 |
*/ |
|
3355 |
$defaults = array( |
|
3356 |
'to' => $user_email, |
|
3357 |
'subject' => $title, |
|
3358 |
'message' => $message, |
|
3359 |
'headers' => '', |
|
3360 |
); |
|
3361 |
||
3362 |
/** |
|
3363 |
* Filters the contents of the reset password notification email sent to the user. |
|
3364 |
* |
|
3365 |
* @since 6.0.0 |
|
3366 |
* |
|
3367 |
* @param array $defaults { |
|
3368 |
* The default notification email arguments. Used to build wp_mail(). |
|
3369 |
* |
|
3370 |
* @type string $to The intended recipient - user email address. |
|
3371 |
* @type string $subject The subject of the email. |
|
3372 |
* @type string $message The body of the email. |
|
3373 |
* @type string $headers The headers of the email. |
|
3374 |
* } |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3375 |
* @param string $key The activation key. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3376 |
* @param string $user_login The username for the user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3377 |
* @param WP_User $user_data WP_User object. |
19 | 3378 |
*/ |
3379 |
$notification_email = apply_filters( 'retrieve_password_notification_email', $defaults, $key, $user_login, $user_data ); |
|
3380 |
||
18 | 3381 |
if ( $switched_locale ) { |
3382 |
restore_previous_locale(); |
|
3383 |
} |
|
3384 |
||
19 | 3385 |
if ( is_array( $notification_email ) ) { |
3386 |
// Force key order and merge defaults in case any value is missing in the filtered array. |
|
3387 |
$notification_email = array_merge( $defaults, $notification_email ); |
|
3388 |
} else { |
|
3389 |
$notification_email = $defaults; |
|
3390 |
} |
|
3391 |
||
3392 |
list( $to, $subject, $message, $headers ) = array_values( $notification_email ); |
|
3393 |
||
3394 |
$subject = wp_specialchars_decode( $subject ); |
|
3395 |
||
3396 |
if ( ! wp_mail( $to, $subject, $message, $headers ) ) { |
|
18 | 3397 |
$errors->add( |
3398 |
'retrieve_password_email_failure', |
|
3399 |
sprintf( |
|
3400 |
/* translators: %s: Documentation URL. */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3401 |
__( '<strong>Error:</strong> The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3402 |
esc_url( __( 'https://wordpress.org/documentation/article/reset-your-password/' ) ) |
18 | 3403 |
) |
3404 |
); |
|
3405 |
return $errors; |
|
3406 |
} |
|
3407 |
||
3408 |
return true; |
|
3409 |
} |
|
3410 |
||
3411 |
/** |
|
0 | 3412 |
* Handles resetting the user's password. |
3413 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
* @param WP_User $user The user |
16 | 3417 |
* @param string $new_pass New password for the user in plaintext |
0 | 3418 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3419 |
function reset_password( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3420 |
$user, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3421 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3422 |
$new_pass |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3423 |
) { |
5 | 3424 |
/** |
3425 |
* Fires before the user's password is reset. |
|
3426 |
* |
|
3427 |
* @since 1.5.0 |
|
3428 |
* |
|
16 | 3429 |
* @param WP_User $user The user. |
3430 |
* @param string $new_pass New user password. |
|
5 | 3431 |
*/ |
0 | 3432 |
do_action( 'password_reset', $user, $new_pass ); |
3433 |
||
3434 |
wp_set_password( $new_pass, $user->ID ); |
|
18 | 3435 |
update_user_meta( $user->ID, 'default_password_nag', false ); |
0 | 3436 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3437 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3438 |
* Fires after the user's password is reset. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3439 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3440 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3441 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3442 |
* @param WP_User $user The user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3443 |
* @param string $new_pass New user password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3444 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3445 |
do_action( 'after_password_reset', $user, $new_pass ); |
0 | 3446 |
} |
3447 |
||
3448 |
/** |
|
3449 |
* Handles registering a new user. |
|
3450 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3451 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3452 |
* |
0 | 3453 |
* @param string $user_login User's username for logging in |
3454 |
* @param string $user_email User's email address to send password and add |
|
3455 |
* @return int|WP_Error Either user's ID or error on failure. |
|
3456 |
*/ |
|
3457 |
function register_new_user( $user_login, $user_email ) { |
|
3458 |
$errors = new WP_Error(); |
|
3459 |
||
3460 |
$sanitized_user_login = sanitize_user( $user_login ); |
|
5 | 3461 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
* Filters the email address of a user being registered. |
5 | 3463 |
* |
3464 |
* @since 2.1.0 |
|
3465 |
* |
|
3466 |
* @param string $user_email The email address of the new user. |
|
3467 |
*/ |
|
0 | 3468 |
$user_email = apply_filters( 'user_registration_email', $user_email ); |
3469 |
||
16 | 3470 |
// Check the username. |
3471 |
if ( '' === $sanitized_user_login ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3472 |
$errors->add( 'empty_username', __( '<strong>Error:</strong> Please enter a username.' ) ); |
0 | 3473 |
} elseif ( ! validate_username( $user_login ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3474 |
$errors->add( 'invalid_username', __( '<strong>Error:</strong> This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
0 | 3475 |
$sanitized_user_login = ''; |
3476 |
} elseif ( username_exists( $sanitized_user_login ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3477 |
$errors->add( 'username_exists', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3478 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3479 |
/** This filter is documented in wp-includes/user.php */ |
16 | 3480 |
$illegal_user_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
3481 |
if ( in_array( strtolower( $sanitized_user_login ), array_map( 'strtolower', $illegal_user_logins ), true ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3482 |
$errors->add( 'invalid_username', __( '<strong>Error:</strong> Sorry, that username is not allowed.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3483 |
} |
0 | 3484 |
} |
3485 |
||
16 | 3486 |
// Check the email address. |
3487 |
if ( '' === $user_email ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3488 |
$errors->add( 'empty_email', __( '<strong>Error:</strong> Please type your email address.' ) ); |
0 | 3489 |
} elseif ( ! is_email( $user_email ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3490 |
$errors->add( 'invalid_email', __( '<strong>Error:</strong> The email address is not correct.' ) ); |
0 | 3491 |
$user_email = ''; |
3492 |
} elseif ( email_exists( $user_email ) ) { |
|
19 | 3493 |
$errors->add( |
3494 |
'email_exists', |
|
3495 |
sprintf( |
|
3496 |
/* translators: %s: Link to the login page. */ |
|
3497 |
__( '<strong>Error:</strong> This email address is already registered. <a href="%s">Log in</a> with this address or choose another one.' ), |
|
3498 |
wp_login_url() |
|
3499 |
) |
|
3500 |
); |
|
0 | 3501 |
} |
3502 |
||
5 | 3503 |
/** |
3504 |
* Fires when submitting registration form data, before the user is created. |
|
3505 |
* |
|
3506 |
* @since 2.1.0 |
|
3507 |
* |
|
3508 |
* @param string $sanitized_user_login The submitted username after being sanitized. |
|
3509 |
* @param string $user_email The submitted email. |
|
3510 |
* @param WP_Error $errors Contains any errors with submitted username and email, |
|
3511 |
* e.g., an empty field, an invalid username or email, |
|
3512 |
* or an existing username or email. |
|
3513 |
*/ |
|
0 | 3514 |
do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); |
3515 |
||
5 | 3516 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
* Filters the errors encountered when a new user is being registered. |
5 | 3518 |
* |
3519 |
* The filtered WP_Error object may, for example, contain errors for an invalid |
|
16 | 3520 |
* or existing username or email address. A WP_Error object should always be returned, |
5 | 3521 |
* but may or may not contain errors. |
3522 |
* |
|
3523 |
* If any errors are present in $errors, this will abort the user's registration. |
|
3524 |
* |
|
3525 |
* @since 2.1.0 |
|
3526 |
* |
|
3527 |
* @param WP_Error $errors A WP_Error object containing any errors encountered |
|
3528 |
* during registration. |
|
3529 |
* @param string $sanitized_user_login User's username after it has been sanitized. |
|
3530 |
* @param string $user_email User's email. |
|
3531 |
*/ |
|
0 | 3532 |
$errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
3533 |
||
9 | 3534 |
if ( $errors->has_errors() ) { |
0 | 3535 |
return $errors; |
9 | 3536 |
} |
0 | 3537 |
|
3538 |
$user_pass = wp_generate_password( 12, false ); |
|
9 | 3539 |
$user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
0 | 3540 |
if ( ! $user_id || is_wp_error( $user_id ) ) { |
16 | 3541 |
$errors->add( |
3542 |
'registerfail', |
|
3543 |
sprintf( |
|
3544 |
/* translators: %s: Admin email address. */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3545 |
__( '<strong>Error:</strong> Could not register you… please contact the <a href="mailto:%s">site admin</a>!' ), |
16 | 3546 |
get_option( 'admin_email' ) |
3547 |
) |
|
3548 |
); |
|
0 | 3549 |
return $errors; |
3550 |
} |
|
3551 |
||
18 | 3552 |
update_user_meta( $user_id, 'default_password_nag', true ); // Set up the password change nag. |
0 | 3553 |
|
19 | 3554 |
if ( ! empty( $_COOKIE['wp_lang'] ) ) { |
3555 |
$wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] ); |
|
3556 |
if ( in_array( $wp_lang, get_available_languages(), true ) ) { |
|
3557 |
update_user_meta( $user_id, 'locale', $wp_lang ); // Set user locale if defined on registration. |
|
3558 |
} |
|
3559 |
} |
|
3560 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
* Fires after a new user registration has been recorded. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3563 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3565 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3566 |
* @param int $user_id ID of the newly registered user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3567 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3568 |
do_action( 'register_new_user', $user_id ); |
0 | 3569 |
|
3570 |
return $user_id; |
|
3571 |
} |
|
5 | 3572 |
|
3573 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3574 |
* Initiates email notifications related to the creation of new users. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3576 |
* Notifications are sent both to the site admin and to the newly created user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
* @since 4.6.0 Converted the `$notify` parameter to accept 'user' for sending |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
* notifications only to the user created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
* @param int $user_id ID of the newly created user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
* @param string $notify Optional. Type of notification that should happen. Accepts 'admin' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
* or an empty string (admin only), 'user', or 'both' (admin and user). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
* Default 'both'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
function wp_send_new_user_notifications( $user_id, $notify = 'both' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
wp_new_user_notification( $user_id, null, $notify ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
/** |
19 | 3592 |
* Retrieves the current session token from the logged_in cookie. |
5 | 3593 |
* |
3594 |
* @since 4.0.0 |
|
3595 |
* |
|
3596 |
* @return string Token. |
|
3597 |
*/ |
|
3598 |
function wp_get_session_token() { |
|
3599 |
$cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
3600 |
return ! empty( $cookie['token'] ) ? $cookie['token'] : ''; |
|
3601 |
} |
|
3602 |
||
3603 |
/** |
|
19 | 3604 |
* Retrieves a list of sessions for the current user. |
5 | 3605 |
* |
3606 |
* @since 4.0.0 |
|
16 | 3607 |
* |
5 | 3608 |
* @return array Array of sessions. |
3609 |
*/ |
|
3610 |
function wp_get_all_sessions() { |
|
3611 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
3612 |
return $manager->get_all(); |
|
3613 |
} |
|
3614 |
||
3615 |
/** |
|
19 | 3616 |
* Removes the current session token from the database. |
5 | 3617 |
* |
3618 |
* @since 4.0.0 |
|
3619 |
*/ |
|
3620 |
function wp_destroy_current_session() { |
|
3621 |
$token = wp_get_session_token(); |
|
3622 |
if ( $token ) { |
|
3623 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
3624 |
$manager->destroy( $token ); |
|
3625 |
} |
|
3626 |
} |
|
3627 |
||
3628 |
/** |
|
19 | 3629 |
* Removes all but the current session token for the current user for the database. |
5 | 3630 |
* |
3631 |
* @since 4.0.0 |
|
3632 |
*/ |
|
3633 |
function wp_destroy_other_sessions() { |
|
3634 |
$token = wp_get_session_token(); |
|
3635 |
if ( $token ) { |
|
3636 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
3637 |
$manager->destroy_others( $token ); |
|
3638 |
} |
|
3639 |
} |
|
3640 |
||
3641 |
/** |
|
19 | 3642 |
* Removes all session tokens for the current user from the database. |
5 | 3643 |
* |
3644 |
* @since 4.0.0 |
|
3645 |
*/ |
|
3646 |
function wp_destroy_all_sessions() { |
|
3647 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
3648 |
$manager->destroy_all(); |
|
3649 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
/** |
19 | 3652 |
* Gets the user IDs of all users with no role on this site. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
* @since 4.9.0 The `$site_id` parameter was added to support multisite. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3656 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3657 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3658 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
* @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site. |
16 | 3660 |
* @return string[] Array of user IDs as strings. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
function wp_get_users_with_no_role( $site_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3665 |
if ( ! $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3666 |
$site_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3667 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3668 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3669 |
$prefix = $wpdb->get_blog_prefix( $site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3671 |
if ( is_multisite() && get_current_blog_id() !== $site_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
switch_to_blog( $site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
$role_names = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
$role_names = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
|
9 | 3679 |
$regex = implode( '|', array_keys( $role_names ) ); |
3680 |
$regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); |
|
3681 |
$users = $wpdb->get_col( |
|
3682 |
$wpdb->prepare( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3683 |
"SELECT user_id |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3684 |
FROM $wpdb->usermeta |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3685 |
WHERE meta_key = '{$prefix}capabilities' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3686 |
AND meta_value NOT REGEXP %s", |
9 | 3687 |
$regex |
3688 |
) |
|
3689 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3690 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
return $users; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3692 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3693 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3694 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
* Retrieves the current user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
* Will set the current user, if the current user is not set. The current user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3698 |
* will be set to the logged-in person. If no user is logged-in, then it will |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
* set the current user to 0, which is invalid and won't have any permissions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3700 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3701 |
* This function is used by the pluggable functions wp_get_current_user() and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
* get_currentuserinfo(), the latter of which is deprecated but used for backward |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
* compatibility. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3704 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3705 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3707 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3708 |
* @see wp_get_current_user() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
* @global WP_User $current_user Checks if the current user is set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3711 |
* @return WP_User Current WP_User instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
function _wp_get_current_user() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3714 |
global $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3715 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
if ( ! empty( $current_user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
if ( $current_user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
|
16 | 3721 |
// Upgrade stdClass to WP_User. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
9 | 3723 |
$cur_id = $current_user->ID; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
$current_user = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
wp_set_current_user( $cur_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3727 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3728 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3729 |
// $current_user has a junk value. Force to WP_User with ID 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
$current_user = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3731 |
wp_set_current_user( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3732 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3733 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3734 |
|
9 | 3735 |
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3736 |
wp_set_current_user( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3737 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3739 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
* Filters the current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
* The default filters use this to determine the current user from the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
* request's cookies, if available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
* Returning a value of false will effectively short-circuit setting |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
* the current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
* @since 3.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
* |
18 | 3751 |
* @param int|false $user_id User ID if one has been determined, false otherwise. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3752 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
$user_id = apply_filters( 'determine_current_user', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
if ( ! $user_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
wp_set_current_user( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3756 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3759 |
wp_set_current_user( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3760 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3762 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3763 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3764 |
/** |
19 | 3765 |
* Sends a confirmation request email when a change of user email address is attempted. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3766 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3767 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
* @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
* @global WP_Error $errors WP_Error object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
function send_confirmation_on_profile_email() { |
9 | 3773 |
global $errors; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3774 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3775 |
$current_user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3776 |
if ( ! is_object( $errors ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3777 |
$errors = new WP_Error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3778 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3779 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3780 |
if ( $current_user->ID !== (int) $_POST['user_id'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3781 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3782 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3783 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3784 |
if ( $current_user->user_email !== $_POST['email'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3785 |
if ( ! is_email( $_POST['email'] ) ) { |
9 | 3786 |
$errors->add( |
3787 |
'user_email', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3788 |
__( '<strong>Error:</strong> The email address is not correct.' ), |
9 | 3789 |
array( |
3790 |
'form-field' => 'email', |
|
3791 |
) |
|
3792 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3795 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3796 |
|
9 | 3797 |
if ( email_exists( $_POST['email'] ) ) { |
3798 |
$errors->add( |
|
3799 |
'user_email', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3800 |
__( '<strong>Error:</strong> The email address is already used.' ), |
9 | 3801 |
array( |
3802 |
'form-field' => 'email', |
|
3803 |
) |
|
3804 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
delete_user_meta( $current_user->ID, '_new_email' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3806 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3809 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3810 |
$hash = md5( $_POST['email'] . time() . wp_rand() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
$new_user_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3812 |
'hash' => $hash, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3813 |
'newemail' => $_POST['email'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3814 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3815 |
update_user_meta( $current_user->ID, '_new_email', $new_user_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3816 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3817 |
$sitename = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3818 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3819 |
/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 3820 |
$email_text = __( |
3821 |
'Howdy ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
You recently requested to have the email address on your account changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
If this is correct, please click on the following link to change it: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
###ADMIN_URL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3828 |
You can safely ignore and delete this email if you do not want to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3829 |
take this action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3830 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3831 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3832 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3833 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3834 |
All at ###SITENAME### |
9 | 3835 |
###SITEURL###' |
3836 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3837 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3838 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3839 |
* Filters the text of the email sent when a change of user email address is attempted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3840 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3841 |
* The following strings have a special meaning and will get replaced dynamically: |
16 | 3842 |
* - ###USERNAME### The current user's username. |
3843 |
* - ###ADMIN_URL### The link to click on to confirm the email change. |
|
3844 |
* - ###EMAIL### The new email. |
|
3845 |
* - ###SITENAME### The name of the site. |
|
3846 |
* - ###SITEURL### The URL to the site. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3847 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3848 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3849 |
* @since 4.9.0 This filter is no longer Multisite specific. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3850 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3851 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3852 |
* @param array $new_user_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3853 |
* Data relating to the new user email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3854 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3855 |
* @type string $hash The secure hash used in the confirmation link URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3856 |
* @type string $newemail The proposed new email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3857 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3858 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3859 |
$content = apply_filters( 'new_user_email_content', $email_text, $new_user_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3860 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
$content = str_replace( '###USERNAME###', $current_user->user_login, $content ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3862 |
$content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'profile.php?newuseremail=' . $hash ) ), $content ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3863 |
$content = str_replace( '###EMAIL###', $_POST['email'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3864 |
$content = str_replace( '###SITENAME###', $sitename, $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3865 |
$content = str_replace( '###SITEURL###', home_url(), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
|
16 | 3867 |
/* translators: New email address notification email subject. %s: Site title. */ |
9 | 3868 |
wp_mail( $_POST['email'], sprintf( __( '[%s] Email Change Request' ), $sitename ), $content ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3870 |
$_POST['email'] = $current_user->user_email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3871 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3872 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3874 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3875 |
* Adds an admin notice alerting the user to check for confirmation request email |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3876 |
* after email address change. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3878 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
* @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
* |
19 | 3881 |
* @global string $pagenow The filename of the current screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3883 |
function new_user_email_admin_notice() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3884 |
global $pagenow; |
9 | 3885 |
|
3886 |
if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) ) { |
|
3887 |
$email = get_user_meta( get_current_user_id(), '_new_email', true ); |
|
3888 |
if ( $email ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3889 |
$message = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3890 |
/* translators: %s: New email address. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3891 |
__( 'Your email address has not been updated yet. Please check your inbox at %s for a confirmation email.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3892 |
'<code>' . esc_html( $email['newemail'] ) . '</code>' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3893 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3894 |
wp_admin_notice( $message, array( 'type' => 'info' ) ); |
9 | 3895 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3896 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3897 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3898 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3899 |
/** |
19 | 3900 |
* Gets all personal data request types. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3901 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3903 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3904 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3905 |
* @return string[] List of core privacy action types. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
function _wp_privacy_action_request_types() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
'export_personal_data', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
'remove_personal_data', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3912 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
* Registers the personal data exporter for users. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3919 |
* @param array[] $exporters An array of personal data exporters. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3920 |
* @return array[] An array of personal data exporters. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
function wp_register_user_personal_data_exporter( $exporters ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3923 |
$exporters['wordpress-user'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
'exporter_friendly_name' => __( 'WordPress User' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3925 |
'callback' => 'wp_user_personal_data_exporter', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3926 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3927 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3928 |
return $exporters; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3930 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
* Finds and exports personal data associated with an email address from the user and user_meta table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3934 |
* @since 4.9.6 |
16 | 3935 |
* @since 5.4.0 Added 'Community Events Location' group to the export data. |
3936 |
* @since 5.4.0 Added 'Session Tokens' group to the export data. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3937 |
* |
16 | 3938 |
* @param string $email_address The user's email address. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3939 |
* @return array { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3940 |
* An array of personal data. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3941 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3942 |
* @type array[] $data An array of personal data arrays. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3943 |
* @type bool $done Whether the exporter is finished. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3944 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3945 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
function wp_user_personal_data_exporter( $email_address ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3947 |
$email_address = trim( $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
$data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
$user = get_user_by( 'email', $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3952 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3953 |
if ( ! $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3954 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
'data' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
$user_meta = get_user_meta( $user->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
|
16 | 3962 |
$user_props_to_export = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3963 |
'ID' => __( 'User ID' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
'user_login' => __( 'User Login Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3965 |
'user_nicename' => __( 'User Nice Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3966 |
'user_email' => __( 'User Email' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
'user_url' => __( 'User URL' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
'user_registered' => __( 'User Registration Date' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
'display_name' => __( 'User Display Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3970 |
'nickname' => __( 'User Nickname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
'first_name' => __( 'User First Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
'last_name' => __( 'User Last Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
'description' => __( 'User Description' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
$user_data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
|
16 | 3978 |
foreach ( $user_props_to_export as $key => $name ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
$value = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3980 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
switch ( $key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
case 'ID': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
case 'user_login': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
case 'user_nicename': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
case 'user_email': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
case 'user_url': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3987 |
case 'user_registered': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
case 'display_name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3989 |
$value = $user->data->$key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3990 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
case 'nickname': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
case 'first_name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
case 'last_name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
case 'description': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
$value = $user_meta[ $key ][0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3999 |
if ( ! empty( $value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
$user_data_to_export[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4001 |
'name' => $name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4002 |
'value' => $value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4003 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4004 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4005 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4006 |
|
16 | 4007 |
// Get the list of reserved names. |
4008 |
$reserved_names = array_values( $user_props_to_export ); |
|
4009 |
||
4010 |
/** |
|
19 | 4011 |
* Filters the user's profile data for the privacy exporter. |
16 | 4012 |
* |
4013 |
* @since 5.4.0 |
|
4014 |
* |
|
4015 |
* @param array $additional_user_profile_data { |
|
4016 |
* An array of name-value pairs of additional user data items. Default empty array. |
|
4017 |
* |
|
4018 |
* @type string $name The user-facing name of an item name-value pair,e.g. 'IP Address'. |
|
4019 |
* @type string $value The user-facing value of an item data pair, e.g. '50.60.70.0'. |
|
4020 |
* } |
|
4021 |
* @param WP_User $user The user whose data is being exported. |
|
4022 |
* @param string[] $reserved_names An array of reserved names. Any item in `$additional_user_data` |
|
4023 |
* that uses one of these for its `name` will not be included in the export. |
|
4024 |
*/ |
|
4025 |
$_extra_data = apply_filters( 'wp_privacy_additional_user_profile_data', array(), $user, $reserved_names ); |
|
4026 |
||
4027 |
if ( is_array( $_extra_data ) && ! empty( $_extra_data ) ) { |
|
4028 |
// Remove items that use reserved names. |
|
4029 |
$extra_data = array_filter( |
|
4030 |
$_extra_data, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4031 |
static function ( $item ) use ( $reserved_names ) { |
16 | 4032 |
return ! in_array( $item['name'], $reserved_names, true ); |
4033 |
} |
|
4034 |
); |
|
4035 |
||
4036 |
if ( count( $extra_data ) !== count( $_extra_data ) ) { |
|
4037 |
_doing_it_wrong( |
|
4038 |
__FUNCTION__, |
|
4039 |
sprintf( |
|
4040 |
/* translators: %s: wp_privacy_additional_user_profile_data */ |
|
4041 |
__( 'Filter %s returned items with reserved names.' ), |
|
4042 |
'<code>wp_privacy_additional_user_profile_data</code>' |
|
4043 |
), |
|
4044 |
'5.4.0' |
|
4045 |
); |
|
4046 |
} |
|
4047 |
||
4048 |
if ( ! empty( $extra_data ) ) { |
|
4049 |
$user_data_to_export = array_merge( $user_data_to_export, $extra_data ); |
|
4050 |
} |
|
4051 |
} |
|
4052 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4053 |
$data_to_export[] = array( |
16 | 4054 |
'group_id' => 'user', |
4055 |
'group_label' => __( 'User' ), |
|
4056 |
'group_description' => __( 'User’s profile data.' ), |
|
4057 |
'item_id' => "user-{$user->ID}", |
|
4058 |
'data' => $user_data_to_export, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4059 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4060 |
|
16 | 4061 |
if ( isset( $user_meta['community-events-location'] ) ) { |
4062 |
$location = maybe_unserialize( $user_meta['community-events-location'][0] ); |
|
4063 |
||
4064 |
$location_props_to_export = array( |
|
4065 |
'description' => __( 'City' ), |
|
4066 |
'country' => __( 'Country' ), |
|
4067 |
'latitude' => __( 'Latitude' ), |
|
4068 |
'longitude' => __( 'Longitude' ), |
|
4069 |
'ip' => __( 'IP' ), |
|
4070 |
); |
|
4071 |
||
4072 |
$location_data_to_export = array(); |
|
4073 |
||
4074 |
foreach ( $location_props_to_export as $key => $name ) { |
|
4075 |
if ( ! empty( $location[ $key ] ) ) { |
|
4076 |
$location_data_to_export[] = array( |
|
4077 |
'name' => $name, |
|
4078 |
'value' => $location[ $key ], |
|
4079 |
); |
|
4080 |
} |
|
4081 |
} |
|
4082 |
||
4083 |
$data_to_export[] = array( |
|
4084 |
'group_id' => 'community-events-location', |
|
4085 |
'group_label' => __( 'Community Events Location' ), |
|
4086 |
'group_description' => __( 'User’s location data used for the Community Events in the WordPress Events and News dashboard widget.' ), |
|
4087 |
'item_id' => "community-events-location-{$user->ID}", |
|
4088 |
'data' => $location_data_to_export, |
|
4089 |
); |
|
4090 |
} |
|
4091 |
||
4092 |
if ( isset( $user_meta['session_tokens'] ) ) { |
|
4093 |
$session_tokens = maybe_unserialize( $user_meta['session_tokens'][0] ); |
|
4094 |
||
4095 |
$session_tokens_props_to_export = array( |
|
4096 |
'expiration' => __( 'Expiration' ), |
|
4097 |
'ip' => __( 'IP' ), |
|
4098 |
'ua' => __( 'User Agent' ), |
|
4099 |
'login' => __( 'Last Login' ), |
|
4100 |
); |
|
4101 |
||
4102 |
foreach ( $session_tokens as $token_key => $session_token ) { |
|
4103 |
$session_tokens_data_to_export = array(); |
|
4104 |
||
4105 |
foreach ( $session_tokens_props_to_export as $key => $name ) { |
|
4106 |
if ( ! empty( $session_token[ $key ] ) ) { |
|
4107 |
$value = $session_token[ $key ]; |
|
4108 |
if ( in_array( $key, array( 'expiration', 'login' ), true ) ) { |
|
4109 |
$value = date_i18n( 'F d, Y H:i A', $value ); |
|
4110 |
} |
|
4111 |
$session_tokens_data_to_export[] = array( |
|
4112 |
'name' => $name, |
|
4113 |
'value' => $value, |
|
4114 |
); |
|
4115 |
} |
|
4116 |
} |
|
4117 |
||
4118 |
$data_to_export[] = array( |
|
4119 |
'group_id' => 'session-tokens', |
|
4120 |
'group_label' => __( 'Session Tokens' ), |
|
4121 |
'group_description' => __( 'User’s Session Tokens data.' ), |
|
4122 |
'item_id' => "session-tokens-{$user->ID}-{$token_key}", |
|
4123 |
'data' => $session_tokens_data_to_export, |
|
4124 |
); |
|
4125 |
} |
|
4126 |
} |
|
4127 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4128 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4129 |
'data' => $data_to_export, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4130 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4131 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4132 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4133 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4134 |
/** |
19 | 4135 |
* Updates log when privacy request is confirmed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4136 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4137 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4138 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4139 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4140 |
* @param int $request_id ID of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4141 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4142 |
function _wp_privacy_account_request_confirmed( $request_id ) { |
16 | 4143 |
$request = wp_get_user_request( $request_id ); |
9 | 4144 |
|
4145 |
if ( ! $request ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4146 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4147 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4148 |
|
9 | 4149 |
if ( ! in_array( $request->status, array( 'request-pending', 'request-failed' ), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4150 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4151 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4153 |
update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() ); |
9 | 4154 |
wp_update_post( |
4155 |
array( |
|
4156 |
'ID' => $request_id, |
|
4157 |
'post_status' => 'request-confirmed', |
|
4158 |
) |
|
4159 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4160 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4161 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4162 |
/** |
19 | 4163 |
* Notifies the site administrator via email when a request is confirmed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4164 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4165 |
* Without this, the admin would have to manually check the site to see if any |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4166 |
* action was needed on their part yet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4167 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4168 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4169 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4170 |
* @param int $request_id The ID of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4171 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4172 |
function _wp_privacy_send_request_confirmation_notification( $request_id ) { |
16 | 4173 |
$request = wp_get_user_request( $request_id ); |
9 | 4174 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4175 |
if ( ! ( $request instanceof WP_User_Request ) || 'request-confirmed' !== $request->status ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4176 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4177 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4178 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4179 |
$already_notified = (bool) get_post_meta( $request_id, '_wp_admin_notified', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4180 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4181 |
if ( $already_notified ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4182 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4183 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4184 |
|
16 | 4185 |
if ( 'export_personal_data' === $request->action_name ) { |
4186 |
$manage_url = admin_url( 'export-personal-data.php' ); |
|
4187 |
} elseif ( 'remove_personal_data' === $request->action_name ) { |
|
4188 |
$manage_url = admin_url( 'erase-personal-data.php' ); |
|
4189 |
} |
|
9 | 4190 |
$action_description = wp_user_request_action_description( $request->action_name ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4191 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4192 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4193 |
* Filters the recipient of the data request confirmation notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4194 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4195 |
* In a Multisite environment, this will default to the email address of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4196 |
* network admin because, by default, single site admins do not have the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4197 |
* capabilities required to process requests. Some networks may wish to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4198 |
* delegate those capabilities to a single-site admin, or a dedicated person |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4199 |
* responsible for managing privacy requests. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4200 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4201 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4202 |
* |
9 | 4203 |
* @param string $admin_email The email address of the notification recipient. |
4204 |
* @param WP_User_Request $request The request that is initiating the notification. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4205 |
*/ |
9 | 4206 |
$admin_email = apply_filters( 'user_request_confirmed_email_to', get_site_option( 'admin_email' ), $request ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4207 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4208 |
$email_data = array( |
9 | 4209 |
'request' => $request, |
4210 |
'user_email' => $request->email, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
'description' => $action_description, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4212 |
'manage_url' => $manage_url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4213 |
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
'siteurl' => home_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
'admin_email' => $admin_email, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4216 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4217 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4218 |
$subject = sprintf( |
9 | 4219 |
/* translators: Privacy data request confirmed notification email subject. 1: Site title, 2: Name of the confirmed action. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4220 |
__( '[%1$s] Action Confirmed: %2$s' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4221 |
$email_data['sitename'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4222 |
$action_description |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4223 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4224 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4225 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4226 |
* Filters the subject of the user request confirmation email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4227 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4228 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4229 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4230 |
* @param string $subject The email subject. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4231 |
* @param string $sitename The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4232 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4233 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4234 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4235 |
* @type WP_User_Request $request User request object. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4236 |
* @type string $user_email The email address confirming a request. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4237 |
* @type string $description Description of the action being performed so the user knows what the email is for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4238 |
* @type string $manage_url The link to click manage privacy requests of this type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4239 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4240 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4241 |
* @type string $admin_email The administrator email receiving the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4242 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4243 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4244 |
$subject = apply_filters( 'user_request_confirmed_email_subject', $subject, $email_data['sitename'], $email_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4245 |
|
18 | 4246 |
/* translators: Do not translate SITENAME, USER_EMAIL, DESCRIPTION, MANAGE_URL, SITEURL; those are placeholders. */ |
4247 |
$content = __( |
|
4248 |
'Howdy, |
|
4249 |
||
4250 |
A user data privacy request has been confirmed on ###SITENAME###: |
|
4251 |
||
4252 |
User: ###USER_EMAIL### |
|
4253 |
Request: ###DESCRIPTION### |
|
4254 |
||
4255 |
You can view and manage these data privacy requests here: |
|
4256 |
||
4257 |
###MANAGE_URL### |
|
4258 |
||
4259 |
Regards, |
|
4260 |
All at ###SITENAME### |
|
4261 |
###SITEURL###' |
|
4262 |
); |
|
4263 |
||
4264 |
/** |
|
4265 |
* Filters the body of the user request confirmation email. |
|
4266 |
* |
|
4267 |
* The email is sent to an administrator when a user request is confirmed. |
|
4268 |
* |
|
4269 |
* The following strings have a special meaning and will get replaced dynamically: |
|
4270 |
* |
|
4271 |
* ###SITENAME### The name of the site. |
|
4272 |
* ###USER_EMAIL### The user email for the request. |
|
4273 |
* ###DESCRIPTION### Description of the action being performed so the user knows what the email is for. |
|
4274 |
* ###MANAGE_URL### The URL to manage requests. |
|
4275 |
* ###SITEURL### The URL to the site. |
|
4276 |
* |
|
4277 |
* @since 4.9.6 |
|
4278 |
* @deprecated 5.8.0 Use {@see 'user_request_confirmed_email_content'} instead. |
|
4279 |
* For user erasure fulfillment email content |
|
4280 |
* use {@see 'user_erasure_fulfillment_email_content'} instead. |
|
4281 |
* |
|
4282 |
* @param string $content The email content. |
|
4283 |
* @param array $email_data { |
|
4284 |
* Data relating to the account action email. |
|
4285 |
* |
|
4286 |
* @type WP_User_Request $request User request object. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4287 |
* @type string $user_email The email address confirming a request. |
18 | 4288 |
* @type string $description Description of the action being performed |
4289 |
* so the user knows what the email is for. |
|
4290 |
* @type string $manage_url The link to click manage privacy requests of this type. |
|
4291 |
* @type string $sitename The site name sending the mail. |
|
4292 |
* @type string $siteurl The site URL sending the mail. |
|
4293 |
* @type string $admin_email The administrator email receiving the mail. |
|
4294 |
* } |
|
4295 |
*/ |
|
4296 |
$content = apply_filters_deprecated( |
|
4297 |
'user_confirmed_action_email_content', |
|
4298 |
array( $content, $email_data ), |
|
4299 |
'5.8.0', |
|
4300 |
sprintf( |
|
4301 |
/* translators: 1 & 2: Deprecation replacement options. */ |
|
4302 |
__( '%1$s or %2$s' ), |
|
4303 |
'user_request_confirmed_email_content', |
|
4304 |
'user_erasure_fulfillment_email_content' |
|
4305 |
) |
|
4306 |
); |
|
4307 |
||
4308 |
/** |
|
4309 |
* Filters the body of the user request confirmation email. |
|
4310 |
* |
|
4311 |
* The email is sent to an administrator when a user request is confirmed. |
|
4312 |
* The following strings have a special meaning and will get replaced dynamically: |
|
4313 |
* |
|
4314 |
* ###SITENAME### The name of the site. |
|
4315 |
* ###USER_EMAIL### The user email for the request. |
|
4316 |
* ###DESCRIPTION### Description of the action being performed so the user knows what the email is for. |
|
4317 |
* ###MANAGE_URL### The URL to manage requests. |
|
4318 |
* ###SITEURL### The URL to the site. |
|
4319 |
* |
|
4320 |
* @since 5.8.0 |
|
4321 |
* |
|
4322 |
* @param string $content The email content. |
|
4323 |
* @param array $email_data { |
|
4324 |
* Data relating to the account action email. |
|
4325 |
* |
|
4326 |
* @type WP_User_Request $request User request object. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4327 |
* @type string $user_email The email address confirming a request. |
18 | 4328 |
* @type string $description Description of the action being performed so the user knows what the email is for. |
4329 |
* @type string $manage_url The link to click manage privacy requests of this type. |
|
4330 |
* @type string $sitename The site name sending the mail. |
|
4331 |
* @type string $siteurl The site URL sending the mail. |
|
4332 |
* @type string $admin_email The administrator email receiving the mail. |
|
4333 |
* } |
|
4334 |
*/ |
|
4335 |
$content = apply_filters( 'user_request_confirmed_email_content', $content, $email_data ); |
|
4336 |
||
4337 |
$content = str_replace( '###SITENAME###', $email_data['sitename'], $content ); |
|
4338 |
$content = str_replace( '###USER_EMAIL###', $email_data['user_email'], $content ); |
|
4339 |
$content = str_replace( '###DESCRIPTION###', $email_data['description'], $content ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4340 |
$content = str_replace( '###MANAGE_URL###', sanitize_url( $email_data['manage_url'] ), $content ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4341 |
$content = str_replace( '###SITEURL###', sanitize_url( $email_data['siteurl'] ), $content ); |
18 | 4342 |
|
16 | 4343 |
$headers = ''; |
4344 |
||
4345 |
/** |
|
4346 |
* Filters the headers of the user request confirmation email. |
|
4347 |
* |
|
4348 |
* @since 5.4.0 |
|
4349 |
* |
|
4350 |
* @param string|array $headers The email headers. |
|
4351 |
* @param string $subject The email subject. |
|
4352 |
* @param string $content The email content. |
|
4353 |
* @param int $request_id The request ID. |
|
4354 |
* @param array $email_data { |
|
4355 |
* Data relating to the account action email. |
|
4356 |
* |
|
4357 |
* @type WP_User_Request $request User request object. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4358 |
* @type string $user_email The email address confirming a request. |
16 | 4359 |
* @type string $description Description of the action being performed so the user knows what the email is for. |
4360 |
* @type string $manage_url The link to click manage privacy requests of this type. |
|
4361 |
* @type string $sitename The site name sending the mail. |
|
4362 |
* @type string $siteurl The site URL sending the mail. |
|
4363 |
* @type string $admin_email The administrator email receiving the mail. |
|
4364 |
* } |
|
4365 |
*/ |
|
4366 |
$headers = apply_filters( 'user_request_confirmed_email_headers', $headers, $subject, $content, $request_id, $email_data ); |
|
4367 |
||
4368 |
$email_sent = wp_mail( $email_data['admin_email'], $subject, $content, $headers ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4369 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4370 |
if ( $email_sent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4371 |
update_post_meta( $request_id, '_wp_admin_notified', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4372 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4373 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4374 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4375 |
/** |
19 | 4376 |
* Notifies the user when their erasure request is fulfilled. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4377 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4378 |
* Without this, the user would never know if their data was actually erased. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4379 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4380 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4381 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4382 |
* @param int $request_id The privacy request post ID associated with this request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4383 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4384 |
function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) { |
16 | 4385 |
$request = wp_get_user_request( $request_id ); |
9 | 4386 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4387 |
if ( ! ( $request instanceof WP_User_Request ) || 'request-completed' !== $request->status ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4388 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4389 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4391 |
$already_notified = (bool) get_post_meta( $request_id, '_wp_user_notified', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4392 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4393 |
if ( $already_notified ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4394 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4395 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4396 |
|
9 | 4397 |
// Localize message content for user; fallback to site default for visitors. |
4398 |
if ( ! empty( $request->user_id ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4399 |
$switched_locale = switch_to_user_locale( $request->user_id ); |
9 | 4400 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4401 |
$switched_locale = switch_to_locale( get_locale() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4402 |
} |
9 | 4403 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4404 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4405 |
* Filters the recipient of the data erasure fulfillment notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4406 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4407 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4408 |
* |
9 | 4409 |
* @param string $user_email The email address of the notification recipient. |
4410 |
* @param WP_User_Request $request The request that is initiating the notification. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4411 |
*/ |
9 | 4412 |
$user_email = apply_filters( 'user_erasure_fulfillment_email_to', $request->email, $request ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4413 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4414 |
$email_data = array( |
9 | 4415 |
'request' => $request, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4416 |
'message_recipient' => $user_email, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4417 |
'privacy_policy_url' => get_privacy_policy_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4418 |
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4419 |
'siteurl' => home_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4420 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4421 |
|
9 | 4422 |
$subject = sprintf( |
16 | 4423 |
/* translators: Erasure request fulfilled notification email subject. %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4424 |
__( '[%s] Erasure Request Fulfilled' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4425 |
$email_data['sitename'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4426 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4427 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4428 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4429 |
* Filters the subject of the email sent when an erasure request is completed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4430 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4431 |
* @since 4.9.8 |
18 | 4432 |
* @deprecated 5.8.0 Use {@see 'user_erasure_fulfillment_email_subject'} instead. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4433 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4434 |
* @param string $subject The email subject. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4435 |
* @param string $sitename The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4436 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4437 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4438 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4439 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4440 |
* @type string $message_recipient The address that the email will be sent to. Defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4441 |
* to the value of `$request->email`, but can be changed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4442 |
* by the `user_erasure_fulfillment_email_to` filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4443 |
* @type string $privacy_policy_url Privacy policy URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4444 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4445 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4446 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4447 |
*/ |
18 | 4448 |
$subject = apply_filters_deprecated( |
4449 |
'user_erasure_complete_email_subject', |
|
4450 |
array( $subject, $email_data['sitename'], $email_data ), |
|
4451 |
'5.8.0', |
|
4452 |
'user_erasure_fulfillment_email_subject' |
|
4453 |
); |
|
4454 |
||
4455 |
/** |
|
4456 |
* Filters the subject of the email sent when an erasure request is completed. |
|
4457 |
* |
|
4458 |
* @since 5.8.0 |
|
4459 |
* |
|
4460 |
* @param string $subject The email subject. |
|
4461 |
* @param string $sitename The name of the site. |
|
4462 |
* @param array $email_data { |
|
4463 |
* Data relating to the account action email. |
|
4464 |
* |
|
4465 |
* @type WP_User_Request $request User request object. |
|
4466 |
* @type string $message_recipient The address that the email will be sent to. Defaults |
|
4467 |
* to the value of `$request->email`, but can be changed |
|
4468 |
* by the `user_erasure_fulfillment_email_to` filter. |
|
4469 |
* @type string $privacy_policy_url Privacy policy URL. |
|
4470 |
* @type string $sitename The site name sending the mail. |
|
4471 |
* @type string $siteurl The site URL sending the mail. |
|
4472 |
* } |
|
4473 |
*/ |
|
4474 |
$subject = apply_filters( 'user_erasure_fulfillment_email_subject', $subject, $email_data['sitename'], $email_data ); |
|
4475 |
||
4476 |
/* translators: Do not translate SITENAME, SITEURL; those are placeholders. */ |
|
4477 |
$content = __( |
|
4478 |
'Howdy, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4479 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4480 |
Your request to erase your personal data on ###SITENAME### has been completed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4481 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4482 |
If you have any follow-up questions or concerns, please contact the site administrator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4483 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4484 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4485 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4486 |
###SITEURL###' |
18 | 4487 |
); |
4488 |
||
4489 |
if ( ! empty( $email_data['privacy_policy_url'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4490 |
/* translators: Do not translate SITENAME, SITEURL, PRIVACY_POLICY_URL; those are placeholders. */ |
18 | 4491 |
$content = __( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4492 |
'Howdy, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4493 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4494 |
Your request to erase your personal data on ###SITENAME### has been completed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4495 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4496 |
If you have any follow-up questions or concerns, please contact the site administrator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4497 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4498 |
For more information, you can also read our privacy policy: ###PRIVACY_POLICY_URL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4499 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4500 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4501 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4502 |
###SITEURL###' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4503 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4504 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4505 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4506 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4507 |
* Filters the body of the data erasure fulfillment notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4508 |
* |
18 | 4509 |
* The email is sent to a user when their data erasure request is fulfilled |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4510 |
* by an administrator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4511 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4512 |
* The following strings have a special meaning and will get replaced dynamically: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4514 |
* ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4515 |
* ###PRIVACY_POLICY_URL### Privacy policy page URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4516 |
* ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4517 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4518 |
* @since 4.9.6 |
18 | 4519 |
* @deprecated 5.8.0 Use {@see 'user_erasure_fulfillment_email_content'} instead. |
4520 |
* For user request confirmation email content |
|
4521 |
* use {@see 'user_request_confirmed_email_content'} instead. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4522 |
* |
18 | 4523 |
* @param string $content The email content. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4524 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4525 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4526 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4527 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4528 |
* @type string $message_recipient The address that the email will be sent to. Defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4529 |
* to the value of `$request->email`, but can be changed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4530 |
* by the `user_erasure_fulfillment_email_to` filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4531 |
* @type string $privacy_policy_url Privacy policy URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4532 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4533 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4534 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4535 |
*/ |
18 | 4536 |
$content = apply_filters_deprecated( |
4537 |
'user_confirmed_action_email_content', |
|
4538 |
array( $content, $email_data ), |
|
4539 |
'5.8.0', |
|
4540 |
sprintf( |
|
4541 |
/* translators: 1 & 2: Deprecation replacement options. */ |
|
4542 |
__( '%1$s or %2$s' ), |
|
4543 |
'user_erasure_fulfillment_email_content', |
|
4544 |
'user_request_confirmed_email_content' |
|
4545 |
) |
|
4546 |
); |
|
4547 |
||
4548 |
/** |
|
4549 |
* Filters the body of the data erasure fulfillment notification. |
|
4550 |
* |
|
4551 |
* The email is sent to a user when their data erasure request is fulfilled |
|
4552 |
* by an administrator. |
|
4553 |
* |
|
4554 |
* The following strings have a special meaning and will get replaced dynamically: |
|
4555 |
* |
|
4556 |
* ###SITENAME### The name of the site. |
|
4557 |
* ###PRIVACY_POLICY_URL### Privacy policy page URL. |
|
4558 |
* ###SITEURL### The URL to the site. |
|
4559 |
* |
|
4560 |
* @since 5.8.0 |
|
4561 |
* |
|
4562 |
* @param string $content The email content. |
|
4563 |
* @param array $email_data { |
|
4564 |
* Data relating to the account action email. |
|
4565 |
* |
|
4566 |
* @type WP_User_Request $request User request object. |
|
4567 |
* @type string $message_recipient The address that the email will be sent to. Defaults |
|
4568 |
* to the value of `$request->email`, but can be changed |
|
4569 |
* by the `user_erasure_fulfillment_email_to` filter. |
|
4570 |
* @type string $privacy_policy_url Privacy policy URL. |
|
4571 |
* @type string $sitename The site name sending the mail. |
|
4572 |
* @type string $siteurl The site URL sending the mail. |
|
4573 |
* } |
|
4574 |
*/ |
|
4575 |
$content = apply_filters( 'user_erasure_fulfillment_email_content', $content, $email_data ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4576 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4577 |
$content = str_replace( '###SITENAME###', $email_data['sitename'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4578 |
$content = str_replace( '###PRIVACY_POLICY_URL###', $email_data['privacy_policy_url'], $content ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4579 |
$content = str_replace( '###SITEURL###', sanitize_url( $email_data['siteurl'] ), $content ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4580 |
|
16 | 4581 |
$headers = ''; |
4582 |
||
4583 |
/** |
|
4584 |
* Filters the headers of the data erasure fulfillment notification. |
|
4585 |
* |
|
4586 |
* @since 5.4.0 |
|
18 | 4587 |
* @deprecated 5.8.0 Use {@see 'user_erasure_fulfillment_email_headers'} instead. |
16 | 4588 |
* |
4589 |
* @param string|array $headers The email headers. |
|
4590 |
* @param string $subject The email subject. |
|
4591 |
* @param string $content The email content. |
|
4592 |
* @param int $request_id The request ID. |
|
4593 |
* @param array $email_data { |
|
4594 |
* Data relating to the account action email. |
|
4595 |
* |
|
4596 |
* @type WP_User_Request $request User request object. |
|
4597 |
* @type string $message_recipient The address that the email will be sent to. Defaults |
|
4598 |
* to the value of `$request->email`, but can be changed |
|
4599 |
* by the `user_erasure_fulfillment_email_to` filter. |
|
4600 |
* @type string $privacy_policy_url Privacy policy URL. |
|
4601 |
* @type string $sitename The site name sending the mail. |
|
4602 |
* @type string $siteurl The site URL sending the mail. |
|
4603 |
* } |
|
4604 |
*/ |
|
18 | 4605 |
$headers = apply_filters_deprecated( |
4606 |
'user_erasure_complete_email_headers', |
|
4607 |
array( $headers, $subject, $content, $request_id, $email_data ), |
|
4608 |
'5.8.0', |
|
4609 |
'user_erasure_fulfillment_email_headers' |
|
4610 |
); |
|
4611 |
||
4612 |
/** |
|
4613 |
* Filters the headers of the data erasure fulfillment notification. |
|
4614 |
* |
|
4615 |
* @since 5.8.0 |
|
4616 |
* |
|
4617 |
* @param string|array $headers The email headers. |
|
4618 |
* @param string $subject The email subject. |
|
4619 |
* @param string $content The email content. |
|
4620 |
* @param int $request_id The request ID. |
|
4621 |
* @param array $email_data { |
|
4622 |
* Data relating to the account action email. |
|
4623 |
* |
|
4624 |
* @type WP_User_Request $request User request object. |
|
4625 |
* @type string $message_recipient The address that the email will be sent to. Defaults |
|
4626 |
* to the value of `$request->email`, but can be changed |
|
4627 |
* by the `user_erasure_fulfillment_email_to` filter. |
|
4628 |
* @type string $privacy_policy_url Privacy policy URL. |
|
4629 |
* @type string $sitename The site name sending the mail. |
|
4630 |
* @type string $siteurl The site URL sending the mail. |
|
4631 |
* } |
|
4632 |
*/ |
|
4633 |
$headers = apply_filters( 'user_erasure_fulfillment_email_headers', $headers, $subject, $content, $request_id, $email_data ); |
|
16 | 4634 |
|
4635 |
$email_sent = wp_mail( $user_email, $subject, $content, $headers ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4636 |
|
9 | 4637 |
if ( $switched_locale ) { |
4638 |
restore_previous_locale(); |
|
4639 |
} |
|
4640 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4641 |
if ( $email_sent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4642 |
update_post_meta( $request_id, '_wp_user_notified', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4643 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4644 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4645 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4646 |
/** |
19 | 4647 |
* Returns request confirmation message HTML. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4648 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4649 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4650 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4651 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4652 |
* @param int $request_id The request ID being confirmed. |
16 | 4653 |
* @return string The confirmation message. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4654 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4655 |
function _wp_privacy_account_request_confirmed_message( $request_id ) { |
16 | 4656 |
$request = wp_get_user_request( $request_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4657 |
|
9 | 4658 |
$message = '<p class="success">' . __( 'Action has been confirmed.' ) . '</p>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4659 |
$message .= '<p>' . __( 'The site administrator has been notified and will fulfill your request as soon as possible.' ) . '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4660 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4661 |
if ( $request && in_array( $request->action_name, _wp_privacy_action_request_types(), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4662 |
if ( 'export_personal_data' === $request->action_name ) { |
9 | 4663 |
$message = '<p class="success">' . __( 'Thanks for confirming your export request.' ) . '</p>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4664 |
$message .= '<p>' . __( 'The site administrator has been notified. You will receive a link to download your export via email when they fulfill your request.' ) . '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4665 |
} elseif ( 'remove_personal_data' === $request->action_name ) { |
9 | 4666 |
$message = '<p class="success">' . __( 'Thanks for confirming your erasure request.' ) . '</p>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4667 |
$message .= '<p>' . __( 'The site administrator has been notified. You will receive an email confirmation when they erase your data.' ) . '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4668 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4669 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4670 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4671 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4672 |
* Filters the message displayed to a user when they confirm a data request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4673 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4674 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4675 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4676 |
* @param string $message The message to the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4677 |
* @param int $request_id The ID of the request being confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4678 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4679 |
$message = apply_filters( 'user_request_action_confirmed_message', $message, $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4680 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4681 |
return $message; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4682 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4683 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4684 |
/** |
19 | 4685 |
* Creates and logs a user request to perform a specific action. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4686 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4687 |
* Requests are stored inside a post type named `user_request` since they can apply to both |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4688 |
* users on the site, or guests without a user account. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4689 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4690 |
* @since 4.9.6 |
18 | 4691 |
* @since 5.7.0 Added the `$status` parameter. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4692 |
* |
18 | 4693 |
* @param string $email_address User email address. This can be the address of a registered |
4694 |
* or non-registered user. |
|
4695 |
* @param string $action_name Name of the action that is being confirmed. Required. |
|
4696 |
* @param array $request_data Misc data you want to send with the verification request and pass |
|
4697 |
* to the actions once the request is confirmed. |
|
4698 |
* @param string $status Optional request status (pending or confirmed). Default 'pending'. |
|
4699 |
* @return int|WP_Error Returns the request ID if successful, or a WP_Error object on failure. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4700 |
*/ |
18 | 4701 |
function wp_create_user_request( $email_address = '', $action_name = '', $request_data = array(), $status = 'pending' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4702 |
$email_address = sanitize_email( $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4703 |
$action_name = sanitize_key( $action_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4704 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4705 |
if ( ! is_email( $email_address ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4706 |
return new WP_Error( 'invalid_email', __( 'Invalid email address.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4707 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4708 |
|
18 | 4709 |
if ( ! in_array( $action_name, _wp_privacy_action_request_types(), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4710 |
return new WP_Error( 'invalid_action', __( 'Invalid action name.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4711 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4712 |
|
18 | 4713 |
if ( ! in_array( $status, array( 'pending', 'confirmed' ), true ) ) { |
4714 |
return new WP_Error( 'invalid_status', __( 'Invalid request status.' ) ); |
|
4715 |
} |
|
4716 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4717 |
$user = get_user_by( 'email', $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4718 |
$user_id = $user && ! is_wp_error( $user ) ? $user->ID : 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4719 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4720 |
// Check for duplicates. |
9 | 4721 |
$requests_query = new WP_Query( |
4722 |
array( |
|
4723 |
'post_type' => 'user_request', |
|
16 | 4724 |
'post_name__in' => array( $action_name ), // Action name stored in post_name column. |
4725 |
'title' => $email_address, // Email address stored in post_title column. |
|
9 | 4726 |
'post_status' => array( |
4727 |
'request-pending', |
|
4728 |
'request-confirmed', |
|
4729 |
), |
|
4730 |
'fields' => 'ids', |
|
4731 |
) |
|
4732 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4733 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4734 |
if ( $requests_query->found_posts ) { |
18 | 4735 |
return new WP_Error( 'duplicate_request', __( 'An incomplete personal data request for this email address already exists.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4736 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4737 |
|
9 | 4738 |
$request_id = wp_insert_post( |
4739 |
array( |
|
4740 |
'post_author' => $user_id, |
|
4741 |
'post_name' => $action_name, |
|
4742 |
'post_title' => $email_address, |
|
4743 |
'post_content' => wp_json_encode( $request_data ), |
|
18 | 4744 |
'post_status' => 'request-' . $status, |
9 | 4745 |
'post_type' => 'user_request', |
4746 |
'post_date' => current_time( 'mysql', false ), |
|
4747 |
'post_date_gmt' => current_time( 'mysql', true ), |
|
4748 |
), |
|
4749 |
true |
|
4750 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4752 |
return $request_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4753 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4754 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4755 |
/** |
19 | 4756 |
* Gets action description from the name and return a string. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4757 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4758 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4759 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4760 |
* @param string $action_name Action name of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4761 |
* @return string Human readable action name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4762 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4763 |
function wp_user_request_action_description( $action_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4764 |
switch ( $action_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4765 |
case 'export_personal_data': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4766 |
$description = __( 'Export Personal Data' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4767 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4768 |
case 'remove_personal_data': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4769 |
$description = __( 'Erase Personal Data' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4770 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4771 |
default: |
16 | 4772 |
/* translators: %s: Action name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4773 |
$description = sprintf( __( 'Confirm the "%s" action' ), $action_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4774 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4775 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4776 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4777 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4778 |
* Filters the user action description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4779 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4780 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4781 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4782 |
* @param string $description The default description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4783 |
* @param string $action_name The name of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4784 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4785 |
return apply_filters( 'user_request_action_description', $description, $action_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4786 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4787 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4788 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4789 |
* Send a confirmation request email to confirm an action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4790 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4791 |
* If the request is not already pending, it will be updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4792 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4793 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4794 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4795 |
* @param string $request_id ID of the request created via wp_create_user_request(). |
18 | 4796 |
* @return true|WP_Error True on success, `WP_Error` on failure. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4797 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4798 |
function wp_send_user_request( $request_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4799 |
$request_id = absint( $request_id ); |
16 | 4800 |
$request = wp_get_user_request( $request_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4801 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4802 |
if ( ! $request ) { |
18 | 4803 |
return new WP_Error( 'invalid_request', __( 'Invalid personal data request.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4804 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4805 |
|
9 | 4806 |
// Localize message content for user; fallback to site default for visitors. |
4807 |
if ( ! empty( $request->user_id ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4808 |
$switched_locale = switch_to_user_locale( $request->user_id ); |
9 | 4809 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4810 |
$switched_locale = switch_to_locale( get_locale() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4811 |
} |
9 | 4812 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4813 |
$email_data = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4814 |
'request' => $request, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4815 |
'email' => $request->email, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4816 |
'description' => wp_user_request_action_description( $request->action_name ), |
9 | 4817 |
'confirm_url' => add_query_arg( |
4818 |
array( |
|
4819 |
'action' => 'confirmaction', |
|
4820 |
'request_id' => $request_id, |
|
4821 |
'confirm_key' => wp_generate_user_request_key( $request_id ), |
|
4822 |
), |
|
4823 |
wp_login_url() |
|
4824 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4825 |
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4826 |
'siteurl' => home_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4827 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4828 |
|
18 | 4829 |
/* translators: Confirm privacy data request notification email subject. 1: Site title, 2: Name of the action. */ |
4830 |
$subject = sprintf( __( '[%1$s] Confirm Action: %2$s' ), $email_data['sitename'], $email_data['description'] ); |
|
4831 |
||
4832 |
/** |
|
4833 |
* Filters the subject of the email sent when an account action is attempted. |
|
4834 |
* |
|
4835 |
* @since 4.9.6 |
|
4836 |
* |
|
4837 |
* @param string $subject The email subject. |
|
4838 |
* @param string $sitename The name of the site. |
|
4839 |
* @param array $email_data { |
|
4840 |
* Data relating to the account action email. |
|
4841 |
* |
|
4842 |
* @type WP_User_Request $request User request object. |
|
4843 |
* @type string $email The email address this is being sent to. |
|
4844 |
* @type string $description Description of the action being performed so the user knows what the email is for. |
|
4845 |
* @type string $confirm_url The link to click on to confirm the account action. |
|
4846 |
* @type string $sitename The site name sending the mail. |
|
4847 |
* @type string $siteurl The site URL sending the mail. |
|
4848 |
* } |
|
4849 |
*/ |
|
4850 |
$subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data ); |
|
4851 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4852 |
/* translators: Do not translate DESCRIPTION, CONFIRM_URL, SITENAME, SITEURL: those are placeholders. */ |
18 | 4853 |
$content = __( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4854 |
'Howdy, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4855 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4856 |
A request has been made to perform the following action on your account: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4857 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4858 |
###DESCRIPTION### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4859 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4860 |
To confirm this, please click on the following link: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4861 |
###CONFIRM_URL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4862 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4863 |
You can safely ignore and delete this email if you do not want to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4864 |
take this action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4865 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4866 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4867 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4868 |
###SITEURL###' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4869 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4870 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4871 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4872 |
* Filters the text of the email sent when an account action is attempted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4873 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4874 |
* The following strings have a special meaning and will get replaced dynamically: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4875 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4876 |
* ###DESCRIPTION### Description of the action being performed so the user knows what the email is for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4877 |
* ###CONFIRM_URL### The link to click on to confirm the account action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4878 |
* ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4879 |
* ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4880 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4881 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4882 |
* |
18 | 4883 |
* @param string $content Text in the email. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4884 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4885 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4886 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4887 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4888 |
* @type string $email The email address this is being sent to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4889 |
* @type string $description Description of the action being performed so the user knows what the email is for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4890 |
* @type string $confirm_url The link to click on to confirm the account action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4891 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4892 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4893 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4894 |
*/ |
18 | 4895 |
$content = apply_filters( 'user_request_action_email_content', $content, $email_data ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4896 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4897 |
$content = str_replace( '###DESCRIPTION###', $email_data['description'], $content ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4898 |
$content = str_replace( '###CONFIRM_URL###', sanitize_url( $email_data['confirm_url'] ), $content ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4899 |
$content = str_replace( '###EMAIL###', $email_data['email'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4900 |
$content = str_replace( '###SITENAME###', $email_data['sitename'], $content ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4901 |
$content = str_replace( '###SITEURL###', sanitize_url( $email_data['siteurl'] ), $content ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4902 |
|
16 | 4903 |
$headers = ''; |
4904 |
||
4905 |
/** |
|
4906 |
* Filters the headers of the email sent when an account action is attempted. |
|
4907 |
* |
|
4908 |
* @since 5.4.0 |
|
4909 |
* |
|
4910 |
* @param string|array $headers The email headers. |
|
4911 |
* @param string $subject The email subject. |
|
4912 |
* @param string $content The email content. |
|
4913 |
* @param int $request_id The request ID. |
|
4914 |
* @param array $email_data { |
|
4915 |
* Data relating to the account action email. |
|
4916 |
* |
|
4917 |
* @type WP_User_Request $request User request object. |
|
4918 |
* @type string $email The email address this is being sent to. |
|
4919 |
* @type string $description Description of the action being performed so the user knows what the email is for. |
|
4920 |
* @type string $confirm_url The link to click on to confirm the account action. |
|
4921 |
* @type string $sitename The site name sending the mail. |
|
4922 |
* @type string $siteurl The site URL sending the mail. |
|
4923 |
* } |
|
4924 |
*/ |
|
4925 |
$headers = apply_filters( 'user_request_action_email_headers', $headers, $subject, $content, $request_id, $email_data ); |
|
4926 |
||
4927 |
$email_sent = wp_mail( $email_data['email'], $subject, $content, $headers ); |
|
9 | 4928 |
|
4929 |
if ( $switched_locale ) { |
|
4930 |
restore_previous_locale(); |
|
4931 |
} |
|
4932 |
||
4933 |
if ( ! $email_sent ) { |
|
4934 |
return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export confirmation email.' ) ); |
|
4935 |
} |
|
4936 |
||
4937 |
return true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4938 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4939 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4940 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4941 |
* Returns a confirmation key for a user action and stores the hashed version for future comparison. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4942 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4943 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4944 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4945 |
* @param int $request_id Request ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4946 |
* @return string Confirmation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4947 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4948 |
function wp_generate_user_request_key( $request_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4949 |
// Generate something random for a confirmation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4950 |
$key = wp_generate_password( 20, false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4951 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4952 |
// Save the key, hashed. |
9 | 4953 |
wp_update_post( |
4954 |
array( |
|
4955 |
'ID' => $request_id, |
|
4956 |
'post_status' => 'request-pending', |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4957 |
'post_password' => wp_fast_hash( $key ), |
9 | 4958 |
) |
4959 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4960 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4961 |
return $key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4962 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4963 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4964 |
/** |
19 | 4965 |
* Validates a user request by comparing the key with the request's key. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4966 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4967 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4968 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4969 |
* @param string $request_id ID of the request being confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4970 |
* @param string $key Provided key to validate. |
18 | 4971 |
* @return true|WP_Error True on success, WP_Error on failure. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4972 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4973 |
function wp_validate_user_request_key( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4974 |
$request_id, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4975 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4976 |
$key |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4977 |
) { |
18 | 4978 |
$request_id = absint( $request_id ); |
4979 |
$request = wp_get_user_request( $request_id ); |
|
4980 |
$saved_key = $request->confirm_key; |
|
4981 |
$key_request_time = $request->modified_timestamp; |
|
4982 |
||
4983 |
if ( ! $request || ! $saved_key || ! $key_request_time ) { |
|
4984 |
return new WP_Error( 'invalid_request', __( 'Invalid personal data request.' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4985 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4986 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4987 |
if ( ! in_array( $request->status, array( 'request-pending', 'request-failed' ), true ) ) { |
18 | 4988 |
return new WP_Error( 'expired_request', __( 'This personal data request has expired.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4989 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4990 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4991 |
if ( empty( $key ) ) { |
18 | 4992 |
return new WP_Error( 'missing_key', __( 'The confirmation key is missing from this personal data request.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4993 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4994 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4995 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4996 |
* Filters the expiration time of confirm keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4997 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4998 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4999 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5000 |
* @param int $expiration The expiration time in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5001 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5002 |
$expiration_duration = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5003 |
$expiration_time = $key_request_time + $expiration_duration; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5004 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5005 |
if ( ! wp_verify_fast_hash( $key, $saved_key ) ) { |
18 | 5006 |
return new WP_Error( 'invalid_key', __( 'The confirmation key is invalid for this personal data request.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5007 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5008 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5009 |
if ( ! $expiration_time || time() > $expiration_time ) { |
18 | 5010 |
return new WP_Error( 'expired_key', __( 'The confirmation key has expired for this personal data request.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5011 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5012 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5013 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5014 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5015 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5016 |
/** |
19 | 5017 |
* Returns the user request object for the specified request ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5018 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5019 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5020 |
* |
16 | 5021 |
* @param int $request_id The ID of the user request. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5022 |
* @return WP_User_Request|false |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5023 |
*/ |
16 | 5024 |
function wp_get_user_request( $request_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5025 |
$request_id = absint( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5026 |
$post = get_post( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5027 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5028 |
if ( ! $post || 'user_request' !== $post->post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5029 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5030 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5031 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5032 |
return new WP_User_Request( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5033 |
} |
18 | 5034 |
|
5035 |
/** |
|
19 | 5036 |
* Checks if Application Passwords is supported. |
5037 |
* |
|
5038 |
* Application Passwords is supported only by sites using SSL or local environments |
|
5039 |
* but may be made available using the {@see 'wp_is_application_passwords_available'} filter. |
|
5040 |
* |
|
5041 |
* @since 5.9.0 |
|
5042 |
* |
|
5043 |
* @return bool |
|
5044 |
*/ |
|
5045 |
function wp_is_application_passwords_supported() { |
|
5046 |
return is_ssl() || 'local' === wp_get_environment_type(); |
|
5047 |
} |
|
5048 |
||
5049 |
/** |
|
18 | 5050 |
* Checks if Application Passwords is globally available. |
5051 |
* |
|
5052 |
* By default, Application Passwords is available to all sites using SSL or to local environments. |
|
19 | 5053 |
* Use the {@see 'wp_is_application_passwords_available'} filter to adjust its availability. |
18 | 5054 |
* |
5055 |
* @since 5.6.0 |
|
5056 |
* |
|
5057 |
* @return bool |
|
5058 |
*/ |
|
5059 |
function wp_is_application_passwords_available() { |
|
5060 |
/** |
|
5061 |
* Filters whether Application Passwords is available. |
|
5062 |
* |
|
5063 |
* @since 5.6.0 |
|
5064 |
* |
|
5065 |
* @param bool $available True if available, false otherwise. |
|
5066 |
*/ |
|
19 | 5067 |
return apply_filters( 'wp_is_application_passwords_available', wp_is_application_passwords_supported() ); |
18 | 5068 |
} |
5069 |
||
5070 |
/** |
|
5071 |
* Checks if Application Passwords is available for a specific user. |
|
5072 |
* |
|
5073 |
* By default all users can use Application Passwords. Use {@see 'wp_is_application_passwords_available_for_user'} |
|
5074 |
* to restrict availability to certain users. |
|
5075 |
* |
|
5076 |
* @since 5.6.0 |
|
5077 |
* |
|
5078 |
* @param int|WP_User $user The user to check. |
|
5079 |
* @return bool |
|
5080 |
*/ |
|
5081 |
function wp_is_application_passwords_available_for_user( $user ) { |
|
5082 |
if ( ! wp_is_application_passwords_available() ) { |
|
5083 |
return false; |
|
5084 |
} |
|
5085 |
||
5086 |
if ( ! is_object( $user ) ) { |
|
5087 |
$user = get_userdata( $user ); |
|
5088 |
} |
|
5089 |
||
5090 |
if ( ! $user || ! $user->exists() ) { |
|
5091 |
return false; |
|
5092 |
} |
|
5093 |
||
5094 |
/** |
|
5095 |
* Filters whether Application Passwords is available for a specific user. |
|
5096 |
* |
|
5097 |
* @since 5.6.0 |
|
5098 |
* |
|
5099 |
* @param bool $available True if available, false otherwise. |
|
5100 |
* @param WP_User $user The user to check. |
|
5101 |
*/ |
|
5102 |
return apply_filters( 'wp_is_application_passwords_available_for_user', true, $user ); |
|
5103 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5104 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5105 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5106 |
* Registers the user meta property for persisted preferences. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5107 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5108 |
* This property is used to store user preferences across page reloads and is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5109 |
* currently used by the block editor for preferences like 'fullscreenMode' and |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5110 |
* 'fixedToolbar'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5111 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5112 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5113 |
* @access private |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5114 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5115 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5116 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5117 |
function wp_register_persisted_preferences_meta() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5118 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5119 |
* Create a meta key that incorporates the blog prefix so that each site |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5120 |
* on a multisite can have distinct user preferences. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5121 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5122 |
global $wpdb; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5123 |
$meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5124 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5125 |
register_meta( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5126 |
'user', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5127 |
$meta_key, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5128 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5129 |
'type' => 'object', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5130 |
'single' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5131 |
'show_in_rest' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5132 |
'name' => 'persisted_preferences', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5133 |
'type' => 'object', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5134 |
'schema' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5135 |
'type' => 'object', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5136 |
'context' => array( 'edit' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5137 |
'properties' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5138 |
'_modified' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5139 |
'description' => __( 'The date and time the preferences were updated.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5140 |
'type' => 'string', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5141 |
'format' => 'date-time', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5142 |
'readonly' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5143 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5144 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5145 |
'additionalProperties' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5146 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5147 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5148 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5149 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5150 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5151 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5152 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5153 |
* Sets the last changed time for the 'users' cache group. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5154 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5155 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5156 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5157 |
function wp_cache_set_users_last_changed() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5158 |
wp_cache_set_last_changed( 'users' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5159 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5160 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5161 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5162 |
* Checks if password reset is allowed for a specific user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5163 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5164 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5165 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5166 |
* @param int|WP_User $user The user to check. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5167 |
* @return bool|WP_Error True if allowed, false or WP_Error otherwise. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5168 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5169 |
function wp_is_password_reset_allowed_for_user( $user ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5170 |
if ( ! is_object( $user ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5171 |
$user = get_userdata( $user ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5172 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5173 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5174 |
if ( ! $user || ! $user->exists() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5175 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5176 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5177 |
$allow = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5178 |
if ( is_multisite() && is_user_spammy( $user ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5179 |
$allow = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5180 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5181 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5182 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5183 |
* Filters whether to allow a password to be reset. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5184 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5185 |
* @since 2.7.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5186 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5187 |
* @param bool $allow Whether to allow the password to be reset. Default true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5188 |
* @param int $user_id The ID of the user attempting to reset a password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5189 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5190 |
return apply_filters( 'allow_password_reset', $allow, $user->ID ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5191 |
} |