author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
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 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
* |
5 | 29 |
* @param array $credentials Optional. User info in order to sign on. |
30 |
* @param string|bool $secure_cookie Optional. Whether to use secure cookie. |
|
31 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
|
0 | 32 |
*/ |
5 | 33 |
function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
9 | 34 |
if ( empty( $credentials ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
$credentials = array(); // Back-compat for plugins passing an empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
|
9 | 37 |
if ( ! empty( $_POST['log'] ) ) { |
0 | 38 |
$credentials['user_login'] = $_POST['log']; |
9 | 39 |
} |
40 |
if ( ! empty( $_POST['pwd'] ) ) { |
|
0 | 41 |
$credentials['user_password'] = $_POST['pwd']; |
9 | 42 |
} |
43 |
if ( ! empty( $_POST['rememberme'] ) ) { |
|
0 | 44 |
$credentials['remember'] = $_POST['rememberme']; |
9 | 45 |
} |
0 | 46 |
} |
47 |
||
9 | 48 |
if ( ! empty( $credentials['remember'] ) ) { |
0 | 49 |
$credentials['remember'] = true; |
9 | 50 |
} else { |
0 | 51 |
$credentials['remember'] = false; |
9 | 52 |
} |
0 | 53 |
|
5 | 54 |
/** |
55 |
* Fires before the user is authenticated. |
|
56 |
* |
|
57 |
* The variables passed to the callbacks are passed by reference, |
|
58 |
* and can be modified by callback functions. |
|
59 |
* |
|
60 |
* @since 1.5.1 |
|
61 |
* |
|
62 |
* @todo Decide whether to deprecate the wp_authenticate action. |
|
63 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* @param string $user_login Username (passed by reference). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* @param string $user_password User password (passed by reference). |
5 | 66 |
*/ |
67 |
do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
|
0 | 68 |
|
9 | 69 |
if ( '' === $secure_cookie ) { |
0 | 70 |
$secure_cookie = is_ssl(); |
9 | 71 |
} |
0 | 72 |
|
5 | 73 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* Filters whether to use a secure sign-on cookie. |
5 | 75 |
* |
76 |
* @since 3.1.0 |
|
77 |
* |
|
78 |
* @param bool $secure_cookie Whether to use a secure sign-on cookie. |
|
79 |
* @param array $credentials { |
|
9 | 80 |
* Array of entered sign-on data. |
81 |
* |
|
82 |
* @type string $user_login Username. |
|
83 |
* @type string $user_password Password entered. |
|
5 | 84 |
* @type bool $remember Whether to 'remember' the user. Increases the time |
85 |
* that the cookie will be kept. Default false. |
|
9 | 86 |
* } |
5 | 87 |
*/ |
88 |
$secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
|
0 | 89 |
|
90 |
global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie |
|
91 |
$auth_secure_cookie = $secure_cookie; |
|
92 |
||
9 | 93 |
add_filter( 'authenticate', 'wp_authenticate_cookie', 30, 3 ); |
94 |
||
95 |
$user = wp_authenticate( $credentials['user_login'], $credentials['user_password'] ); |
|
96 |
||
97 |
if ( is_wp_error( $user ) ) { |
|
0 | 98 |
return $user; |
99 |
} |
|
100 |
||
9 | 101 |
wp_set_auth_cookie( $user->ID, $credentials['remember'], $secure_cookie ); |
5 | 102 |
/** |
103 |
* Fires after the user has successfully logged in. |
|
104 |
* |
|
105 |
* @since 1.5.0 |
|
106 |
* |
|
107 |
* @param string $user_login Username. |
|
108 |
* @param WP_User $user WP_User object of the logged-in user. |
|
109 |
*/ |
|
110 |
do_action( 'wp_login', $user->user_login, $user ); |
|
0 | 111 |
return $user; |
112 |
} |
|
113 |
||
114 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
* Authenticate a user, confirming the username and password are valid. |
5 | 116 |
* |
117 |
* @since 2.8.0 |
|
118 |
* |
|
119 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
|
120 |
* @param string $username Username for authentication. |
|
121 |
* @param string $password Password for authentication. |
|
122 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
|
0 | 123 |
*/ |
9 | 124 |
function wp_authenticate_username_password( $user, $username, $password ) { |
5 | 125 |
if ( $user instanceof WP_User ) { |
126 |
return $user; |
|
127 |
} |
|
0 | 128 |
|
9 | 129 |
if ( empty( $username ) || empty( $password ) ) { |
130 |
if ( is_wp_error( $user ) ) { |
|
0 | 131 |
return $user; |
9 | 132 |
} |
0 | 133 |
|
134 |
$error = new WP_Error(); |
|
135 |
||
9 | 136 |
if ( empty( $username ) ) { |
137 |
$error->add( 'empty_username', __( '<strong>ERROR</strong>: The username field is empty.' ) ); |
|
138 |
} |
|
139 |
||
140 |
if ( empty( $password ) ) { |
|
141 |
$error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) ); |
|
142 |
} |
|
0 | 143 |
|
144 |
return $error; |
|
145 |
} |
|
146 |
||
9 | 147 |
$user = get_user_by( 'login', $username ); |
148 |
||
149 |
if ( ! $user ) { |
|
150 |
return new WP_Error( |
|
151 |
'invalid_username', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
__( '<strong>ERROR</strong>: Invalid username.' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
' <a href="' . wp_lostpassword_url() . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
__( 'Lost your password?' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
'</a>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
} |
0 | 158 |
|
5 | 159 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* Filters whether the given user can be authenticated with the provided $password. |
5 | 161 |
* |
162 |
* @since 2.5.0 |
|
163 |
* |
|
164 |
* @param WP_User|WP_Error $user WP_User or WP_Error object if a previous |
|
165 |
* callback failed authentication. |
|
166 |
* @param string $password Password to check against the user. |
|
167 |
*/ |
|
168 |
$user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
9 | 169 |
if ( is_wp_error( $user ) ) { |
0 | 170 |
return $user; |
9 | 171 |
} |
0 | 172 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
9 | 174 |
return new WP_Error( |
175 |
'incorrect_password', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
/* translators: %s: user name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
__( '<strong>ERROR</strong>: The password you entered for the username %s is incorrect.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
'<strong>' . $username . '</strong>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
' <a href="' . wp_lostpassword_url() . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
__( 'Lost your password?' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
'</a>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* Authenticates a user using the email and password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* @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
|
196 |
* callback failed authentication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* @param string $email Email address for authentication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* @param string $password Password for authentication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* @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
|
200 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
function wp_authenticate_email_password( $user, $email, $password ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
if ( $user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
if ( empty( $email ) || empty( $password ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
if ( is_wp_error( $user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
$error = new WP_Error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
if ( empty( $email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
$error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
if ( empty( $password ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
$error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
return $error; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
if ( ! is_email( $email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
$user = get_user_by( 'email', $email ); |
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 |
if ( ! $user ) { |
9 | 231 |
return new WP_Error( |
232 |
'invalid_email', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
__( '<strong>ERROR</strong>: Invalid email address.' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
' <a href="' . wp_lostpassword_url() . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
__( 'Lost your password?' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
'</a>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
/** This filter is documented in wp-includes/user.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
$user = apply_filters( 'wp_authenticate_user', $user, $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
if ( is_wp_error( $user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
return $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
9 | 248 |
return new WP_Error( |
249 |
'incorrect_password', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
/* translators: %s: email address */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
__( '<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
'<strong>' . $email . '</strong>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
' <a href="' . wp_lostpassword_url() . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
__( 'Lost your password?' ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
'</a>' |
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 |
} |
0 | 260 |
|
261 |
return $user; |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Authenticate the user using the WordPress auth cookie. |
|
5 | 266 |
* |
267 |
* @since 2.8.0 |
|
268 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
* @global string $auth_secure_cookie |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
* |
5 | 271 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
272 |
* @param string $username Username. If not empty, cancels the cookie authentication. |
|
273 |
* @param string $password Password. If not empty, cancels the cookie authentication. |
|
274 |
* @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
|
0 | 275 |
*/ |
9 | 276 |
function wp_authenticate_cookie( $user, $username, $password ) { |
5 | 277 |
if ( $user instanceof WP_User ) { |
278 |
return $user; |
|
279 |
} |
|
0 | 280 |
|
9 | 281 |
if ( empty( $username ) && empty( $password ) ) { |
0 | 282 |
$user_id = wp_validate_auth_cookie(); |
9 | 283 |
if ( $user_id ) { |
284 |
return new WP_User( $user_id ); |
|
285 |
} |
|
0 | 286 |
|
287 |
global $auth_secure_cookie; |
|
288 |
||
9 | 289 |
if ( $auth_secure_cookie ) { |
0 | 290 |
$auth_cookie = SECURE_AUTH_COOKIE; |
9 | 291 |
} else { |
0 | 292 |
$auth_cookie = AUTH_COOKIE; |
9 | 293 |
} |
294 |
||
295 |
if ( ! empty( $_COOKIE[ $auth_cookie ] ) ) { |
|
296 |
return new WP_Error( 'expired_session', __( 'Please log in again.' ) ); |
|
297 |
} |
|
0 | 298 |
|
299 |
// If the cookie is not set, be silent. |
|
300 |
} |
|
301 |
||
302 |
return $user; |
|
303 |
} |
|
304 |
||
305 |
/** |
|
5 | 306 |
* For Multisite blogs, check if the authenticated user has been marked as a |
0 | 307 |
* spammer, or if the user's primary blog has been marked as spam. |
308 |
* |
|
309 |
* @since 3.7.0 |
|
5 | 310 |
* |
311 |
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
|
312 |
* @return WP_User|WP_Error WP_User on success, WP_Error if the user is considered a spammer. |
|
0 | 313 |
*/ |
314 |
function wp_authenticate_spam_check( $user ) { |
|
5 | 315 |
if ( $user instanceof WP_User && is_multisite() ) { |
316 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* Filters whether the user has been marked as a spammer. |
5 | 318 |
* |
319 |
* @since 3.7.0 |
|
320 |
* |
|
321 |
* @param bool $spammed Whether the user is considered a spammer. |
|
322 |
* @param WP_User $user User to check against. |
|
323 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
$spammed = apply_filters( 'check_is_user_spammed', is_user_spammy( $user ), $user ); |
0 | 325 |
|
9 | 326 |
if ( $spammed ) { |
0 | 327 |
return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
9 | 328 |
} |
0 | 329 |
} |
330 |
return $user; |
|
331 |
} |
|
332 |
||
333 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* Validates the logged-in cookie. |
5 | 335 |
* |
336 |
* Checks the logged-in cookie if the previous auth cookie could not be |
|
337 |
* validated and parsed. |
|
338 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* This is a callback for the {@see 'determine_current_user'} filter, rather than API. |
5 | 340 |
* |
341 |
* @since 3.9.0 |
|
342 |
* |
|
343 |
* @param int|bool $user_id The user ID (or false) as received from the |
|
344 |
* determine_current_user filter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
* @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
|
346 |
* an earlier filter callback is received, that value is returned. |
5 | 347 |
*/ |
348 |
function wp_validate_logged_in_cookie( $user_id ) { |
|
349 |
if ( $user_id ) { |
|
350 |
return $user_id; |
|
351 |
} |
|
352 |
||
9 | 353 |
if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { |
5 | 354 |
return false; |
355 |
} |
|
356 |
||
9 | 357 |
return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' ); |
5 | 358 |
} |
359 |
||
360 |
/** |
|
0 | 361 |
* Number of posts user has written. |
362 |
* |
|
363 |
* @since 3.0.0 |
|
5 | 364 |
* @since 4.1.0 Added `$post_type` argument. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* @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
|
366 |
* of post types to `$post_type`. |
5 | 367 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 369 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
* @param int $userid User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* @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
|
372 |
* @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
|
373 |
* @return string Number of posts the user has written in this post type. |
0 | 374 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
function count_user_posts( $userid, $post_type = 'post', $public_only = false ) { |
0 | 376 |
global $wpdb; |
377 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
$where = get_posts_by_author_sql( $post_type, true, $userid, $public_only ); |
0 | 379 |
|
380 |
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
|
381 |
||
5 | 382 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* Filters the number of posts a user has written. |
5 | 384 |
* |
385 |
* @since 2.7.0 |
|
386 |
* @since 4.1.0 Added `$post_type` argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* @since 4.3.1 Added `$public_only` argument. |
5 | 388 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* @param int $count The user's post count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* @param int $userid User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* @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
|
392 |
* @param bool $public_only Whether to limit counted posts to public posts. |
5 | 393 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only ); |
0 | 395 |
} |
396 |
||
397 |
/** |
|
398 |
* Number of posts written by a list of users. |
|
399 |
* |
|
400 |
* @since 3.0.0 |
|
401 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
* @param array $users Array of user IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* @param string|array $post_type Optional. Single post type or array of post types to check. Defaults to 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
0 | 407 |
* @return array Amount of posts each user has written. |
408 |
*/ |
|
409 |
function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
|
410 |
global $wpdb; |
|
411 |
||
412 |
$count = array(); |
|
9 | 413 |
if ( empty( $users ) || ! is_array( $users ) ) { |
0 | 414 |
return $count; |
9 | 415 |
} |
0 | 416 |
|
417 |
$userlist = implode( ',', array_map( 'absint', $users ) ); |
|
9 | 418 |
$where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
0 | 419 |
|
420 |
$result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
|
421 |
foreach ( $result as $row ) { |
|
422 |
$count[ $row[0] ] = $row[1]; |
|
423 |
} |
|
424 |
||
425 |
foreach ( $users as $id ) { |
|
9 | 426 |
if ( ! isset( $count[ $id ] ) ) { |
0 | 427 |
$count[ $id ] = 0; |
9 | 428 |
} |
0 | 429 |
} |
430 |
||
431 |
return $count; |
|
432 |
} |
|
433 |
||
434 |
// |
|
435 |
// User option functions |
|
436 |
// |
|
437 |
||
438 |
/** |
|
439 |
* Get the current user's ID |
|
440 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* @since MU (3.0.0) |
0 | 442 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
* @return int The current user's ID, or 0 if no user is logged in. |
0 | 444 |
*/ |
445 |
function get_current_user_id() { |
|
9 | 446 |
if ( ! function_exists( 'wp_get_current_user' ) ) { |
0 | 447 |
return 0; |
9 | 448 |
} |
0 | 449 |
$user = wp_get_current_user(); |
450 |
return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
|
451 |
} |
|
452 |
||
453 |
/** |
|
454 |
* Retrieve user option that can be either per Site or per Network. |
|
455 |
* |
|
456 |
* If the user ID is not given, then the current user will be used instead. If |
|
457 |
* the user ID is given, then the user data will be retrieved. The filter for |
|
458 |
* the result, will also pass the original option name and finally the user data |
|
459 |
* object as the third parameter. |
|
460 |
* |
|
461 |
* The option will first check for the per site name and then the per Network name. |
|
462 |
* |
|
463 |
* @since 2.0.0 |
|
5 | 464 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 466 |
* |
5 | 467 |
* @param string $option User option name. |
468 |
* @param int $user Optional. User ID. |
|
469 |
* @param string $deprecated Use get_option() to check for an option in the options table. |
|
470 |
* @return mixed User option value on success, false on failure. |
|
0 | 471 |
*/ |
472 |
function get_user_option( $option, $user = 0, $deprecated = '' ) { |
|
473 |
global $wpdb; |
|
474 |
||
9 | 475 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
_deprecated_argument( __FUNCTION__, '3.0.0' ); |
9 | 477 |
} |
478 |
||
479 |
if ( empty( $user ) ) { |
|
0 | 480 |
$user = get_current_user_id(); |
9 | 481 |
} |
482 |
||
483 |
if ( ! $user = get_userdata( $user ) ) { |
|
0 | 484 |
return false; |
9 | 485 |
} |
0 | 486 |
|
487 |
$prefix = $wpdb->get_blog_prefix(); |
|
9 | 488 |
if ( $user->has_prop( $prefix . $option ) ) { // Blog specific |
0 | 489 |
$result = $user->get( $prefix . $option ); |
9 | 490 |
} elseif ( $user->has_prop( $option ) ) { // User specific and cross-blog |
0 | 491 |
$result = $user->get( $option ); |
9 | 492 |
} else { |
0 | 493 |
$result = false; |
9 | 494 |
} |
0 | 495 |
|
5 | 496 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* Filters a specific user option value. |
5 | 498 |
* |
499 |
* The dynamic portion of the hook name, `$option`, refers to the user option name. |
|
500 |
* |
|
501 |
* @since 2.5.0 |
|
502 |
* |
|
503 |
* @param mixed $result Value for the user's option. |
|
504 |
* @param string $option Name of the option being retrieved. |
|
505 |
* @param WP_User $user WP_User object of the user whose option is being retrieved. |
|
506 |
*/ |
|
507 |
return apply_filters( "get_user_option_{$option}", $result, $option, $user ); |
|
0 | 508 |
} |
509 |
||
510 |
/** |
|
511 |
* Update user option with global blog capability. |
|
512 |
* |
|
513 |
* User options are just like user metadata except that they have support for |
|
514 |
* global blog options. If the 'global' parameter is false, which it is by default |
|
515 |
* it will prepend the WordPress table prefix to the option name. |
|
516 |
* |
|
517 |
* Deletes the user option if $newvalue is empty. |
|
518 |
* |
|
519 |
* @since 2.0.0 |
|
520 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 522 |
* |
523 |
* @param int $user_id User ID. |
|
0 | 524 |
* @param string $option_name User option name. |
5 | 525 |
* @param mixed $newvalue User option value. |
526 |
* @param bool $global Optional. Whether option name is global or blog specific. |
|
527 |
* Default false (blog specific). |
|
528 |
* @return int|bool User meta ID if the option didn't exist, true on successful update, |
|
529 |
* false on failure. |
|
0 | 530 |
*/ |
531 |
function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
|
532 |
global $wpdb; |
|
533 |
||
9 | 534 |
if ( ! $global ) { |
0 | 535 |
$option_name = $wpdb->get_blog_prefix() . $option_name; |
9 | 536 |
} |
0 | 537 |
|
538 |
return update_user_meta( $user_id, $option_name, $newvalue ); |
|
539 |
} |
|
540 |
||
541 |
/** |
|
542 |
* Delete user option with global blog capability. |
|
543 |
* |
|
544 |
* User options are just like user metadata except that they have support for |
|
545 |
* global blog options. If the 'global' parameter is false, which it is by default |
|
546 |
* it will prepend the WordPress table prefix to the option name. |
|
547 |
* |
|
548 |
* @since 3.0.0 |
|
5 | 549 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 551 |
* |
5 | 552 |
* @param int $user_id User ID |
0 | 553 |
* @param string $option_name User option name. |
5 | 554 |
* @param bool $global Optional. Whether option name is global or blog specific. |
555 |
* Default false (blog specific). |
|
556 |
* @return bool True on success, false on failure. |
|
0 | 557 |
*/ |
558 |
function delete_user_option( $user_id, $option_name, $global = false ) { |
|
559 |
global $wpdb; |
|
560 |
||
9 | 561 |
if ( ! $global ) { |
0 | 562 |
$option_name = $wpdb->get_blog_prefix() . $option_name; |
9 | 563 |
} |
0 | 564 |
return delete_user_meta( $user_id, $option_name ); |
565 |
} |
|
566 |
||
567 |
/** |
|
568 |
* Retrieve list of users matching criteria. |
|
569 |
* |
|
570 |
* @since 3.1.0 |
|
5 | 571 |
* |
572 |
* @see WP_User_Query |
|
0 | 573 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
* @param array $args Optional. Arguments to retrieve users. See WP_User_Query::prepare_query(). |
5 | 575 |
* for more information on accepted arguments. |
0 | 576 |
* @return array List of users. |
577 |
*/ |
|
578 |
function get_users( $args = array() ) { |
|
579 |
||
9 | 580 |
$args = wp_parse_args( $args ); |
0 | 581 |
$args['count_total'] = false; |
582 |
||
9 | 583 |
$user_search = new WP_User_Query( $args ); |
0 | 584 |
|
585 |
return (array) $user_search->get_results(); |
|
586 |
} |
|
587 |
||
588 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* Get the sites a user belongs to. |
0 | 590 |
* |
591 |
* @since 3.0.0 |
|
9 | 592 |
* @since 4.7.0 Converted to use `get_sites()`. |
0 | 593 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 595 |
* |
596 |
* @param int $user_id User ID |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
* @param bool $all Whether to retrieve all sites, or only sites that are not |
5 | 598 |
* marked as deleted, archived, or spam. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
* @return array A list of the user's sites. An empty array if the user doesn't exist |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
* or belongs to no sites. |
0 | 601 |
*/ |
602 |
function get_blogs_of_user( $user_id, $all = false ) { |
|
603 |
global $wpdb; |
|
604 |
||
605 |
$user_id = (int) $user_id; |
|
606 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
// Logged out users can't have sites |
9 | 608 |
if ( empty( $user_id ) ) { |
0 | 609 |
return array(); |
9 | 610 |
} |
0 | 611 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* 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
|
614 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* Passing a non-null value to the filter will effectively short circuit |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* get_blogs_of_user(), returning that value instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* @param null|array $sites An array of site objects of which the user is a member. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @param bool $all Whether the returned array should contain all sites, including |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* those marked 'deleted', 'archived', or 'spam'. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
$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
|
626 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
if ( null !== $sites ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
return $sites; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
|
0 | 631 |
$keys = get_user_meta( $user_id ); |
9 | 632 |
if ( empty( $keys ) ) { |
0 | 633 |
return array(); |
9 | 634 |
} |
0 | 635 |
|
636 |
if ( ! is_multisite() ) { |
|
9 | 637 |
$site_id = get_current_blog_id(); |
638 |
$sites = array( $site_id => new stdClass ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
$sites[ $site_id ]->userblog_id = $site_id; |
9 | 640 |
$sites[ $site_id ]->blogname = get_option( 'blogname' ); |
641 |
$sites[ $site_id ]->domain = ''; |
|
642 |
$sites[ $site_id ]->path = ''; |
|
643 |
$sites[ $site_id ]->site_id = 1; |
|
644 |
$sites[ $site_id ]->siteurl = get_option( 'siteurl' ); |
|
645 |
$sites[ $site_id ]->archived = 0; |
|
646 |
$sites[ $site_id ]->spam = 0; |
|
647 |
$sites[ $site_id ]->deleted = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
return $sites; |
0 | 649 |
} |
650 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
$site_ids = array(); |
0 | 652 |
|
653 |
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
|
654 |
$site_ids[] = 1; |
0 | 655 |
unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); |
656 |
} |
|
657 |
||
658 |
$keys = array_keys( $keys ); |
|
659 |
||
660 |
foreach ( $keys as $key ) { |
|
9 | 661 |
if ( 'capabilities' !== substr( $key, -12 ) ) { |
0 | 662 |
continue; |
9 | 663 |
} |
664 |
if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) { |
|
0 | 665 |
continue; |
9 | 666 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
$site_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
9 | 668 |
if ( ! is_numeric( $site_id ) ) { |
0 | 669 |
continue; |
9 | 670 |
} |
0 | 671 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
$site_ids[] = (int) $site_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
$sites = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
if ( ! empty( $site_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
$args = array( |
9 | 679 |
'number' => '', |
680 |
'site__in' => $site_ids, |
|
681 |
'update_site_meta_cache' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
if ( ! $all ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
$args['archived'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
$args['spam'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
$args['deleted'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
$_sites = get_sites( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
foreach ( $_sites as $site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
$sites[ $site->id ] = (object) array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
'userblog_id' => $site->id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
'blogname' => $site->blogname, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
'domain' => $site->domain, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
'path' => $site->path, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
'site_id' => $site->network_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
'siteurl' => $site->siteurl, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
'archived' => $site->archived, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
'mature' => $site->mature, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
'spam' => $site->spam, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
'deleted' => $site->deleted, |
0 | 703 |
); |
704 |
} |
|
705 |
} |
|
706 |
||
5 | 707 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
* Filters the list of sites a user belongs to. |
5 | 709 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
* @since MU (3.0.0) |
5 | 711 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
* @param array $sites An array of site objects belonging to the user. |
5 | 713 |
* @param int $user_id User ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
* @param bool $all Whether the returned sites array should contain all sites, including |
5 | 715 |
* those marked 'deleted', 'archived', or 'spam'. Default false. |
716 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
return apply_filters( 'get_blogs_of_user', $sites, $user_id, $all ); |
0 | 718 |
} |
719 |
||
720 |
/** |
|
721 |
* Find out whether a user is a member of a given blog. |
|
722 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 726 |
* |
727 |
* @param int $user_id Optional. The unique ID of the user. Defaults to the current user. |
|
728 |
* @param int $blog_id Optional. ID of the blog to check. Defaults to the current site. |
|
729 |
* @return bool |
|
730 |
*/ |
|
731 |
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
|
732 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
|
0 | 734 |
$user_id = (int) $user_id; |
735 |
$blog_id = (int) $blog_id; |
|
736 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
if ( empty( $user_id ) ) { |
0 | 738 |
$user_id = get_current_user_id(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
// Technically not needed, but does save calls to get_site and get_user_meta |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
// in the event that the function is called when a user isn't logged in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
if ( empty( $user_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
$user = get_userdata( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
if ( ! $user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
if ( empty( $blog_id ) ) { |
0 | 757 |
$blog_id = get_current_blog_id(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
$blog = get_site( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
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
|
763 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
$keys = get_user_meta( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
if ( empty( $keys ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
// no underscore before capabilities in $base_capabilities_key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
$base_capabilities_key = $wpdb->base_prefix . 'capabilities'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
$site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
if ( isset( $keys[ $base_capabilities_key ] ) && $blog_id == 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
if ( isset( $keys[ $site_capabilities_key ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
return false; |
0 | 784 |
} |
785 |
||
786 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
* Adds meta data to a user. |
0 | 788 |
* |
789 |
* @since 3.0.0 |
|
790 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
* @param string $meta_key Metadata name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
* @param mixed $meta_value Metadata value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
* @param bool $unique Optional. Whether the same key should not be added. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* @return int|false Meta ID on success, false on failure. |
0 | 796 |
*/ |
9 | 797 |
function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) { |
798 |
return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique ); |
|
0 | 799 |
} |
800 |
||
801 |
/** |
|
802 |
* Remove metadata matching criteria from a user. |
|
803 |
* |
|
804 |
* You can match based on the key, or key and value. Removing based on key and |
|
805 |
* value, will keep from removing duplicate metadata with the same key. It also |
|
806 |
* allows removing all metadata matching key, if needed. |
|
807 |
* |
|
808 |
* @since 3.0.0 |
|
5 | 809 |
* @link https://codex.wordpress.org/Function_Reference/delete_user_meta |
0 | 810 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* @param int $user_id User ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
* @param string $meta_key Metadata name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
* @param mixed $meta_value Optional. Metadata value. |
0 | 814 |
* @return bool True on success, false on failure. |
815 |
*/ |
|
9 | 816 |
function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { |
817 |
return delete_metadata( 'user', $user_id, $meta_key, $meta_value ); |
|
0 | 818 |
} |
819 |
||
820 |
/** |
|
821 |
* Retrieve user meta field for a user. |
|
822 |
* |
|
823 |
* @since 3.0.0 |
|
5 | 824 |
* @link https://codex.wordpress.org/Function_Reference/get_user_meta |
0 | 825 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* @param bool $single Whether to return a single value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. |
0 | 830 |
*/ |
9 | 831 |
function get_user_meta( $user_id, $key = '', $single = false ) { |
832 |
return get_metadata( 'user', $user_id, $key, $single ); |
|
0 | 833 |
} |
834 |
||
835 |
/** |
|
836 |
* Update user meta field based on user ID. |
|
837 |
* |
|
838 |
* Use the $prev_value parameter to differentiate between meta fields with the |
|
839 |
* same key and user ID. |
|
840 |
* |
|
841 |
* If the meta field for the user does not exist, it will be added. |
|
842 |
* |
|
843 |
* @since 3.0.0 |
|
5 | 844 |
* @link https://codex.wordpress.org/Function_Reference/update_user_meta |
0 | 845 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
* @param string $meta_key Metadata key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
* @param mixed $meta_value Metadata value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
* @param mixed $prev_value Optional. Previous value to check before removing. |
5 | 850 |
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
0 | 851 |
*/ |
9 | 852 |
function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { |
853 |
return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value ); |
|
0 | 854 |
} |
855 |
||
856 |
/** |
|
857 |
* Count number of users who have each of the user roles. |
|
858 |
* |
|
859 |
* Assumes there are neither duplicated nor orphaned capabilities meta_values. |
|
860 |
* Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query() |
|
861 |
* Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users. |
|
862 |
* Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257. |
|
863 |
* |
|
864 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
* @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
|
866 |
* @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
|
867 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
* @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
|
871 |
* Accepts either 'time' or 'memory'. Default 'time'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
* @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site. |
0 | 873 |
* @return array Includes a grand total and an array of counts indexed by role strings. |
874 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
function count_users( $strategy = 'time', $site_id = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
global $wpdb; |
0 | 877 |
|
878 |
// Initialize |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
if ( ! $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
$site_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
} |
9 | 882 |
|
883 |
/** |
|
884 |
* Filter the user count before queries are run. Return a non-null value to cause count_users() |
|
885 |
* to return early. |
|
886 |
* |
|
887 |
* @since 5.1.0 |
|
888 |
* |
|
889 |
* @param null|string $result Default null. |
|
890 |
* @param string $strategy Optional. The computational strategy to use when counting the users. |
|
891 |
* Accepts either 'time' or 'memory'. Default 'time'. |
|
892 |
* @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site. |
|
893 |
*/ |
|
894 |
$pre = apply_filters( 'pre_count_users', null, $strategy, $site_id ); |
|
895 |
||
896 |
if ( null !== $pre ) { |
|
897 |
return $pre; |
|
898 |
} |
|
899 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
$blog_prefix = $wpdb->get_blog_prefix( $site_id ); |
9 | 901 |
$result = array(); |
0 | 902 |
|
903 |
if ( 'time' == $strategy ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
if ( is_multisite() && $site_id != get_current_blog_id() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
switch_to_blog( $site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
$avail_roles = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
$avail_roles = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
} |
0 | 911 |
|
912 |
// Build a CPU-intensive query that will return concise information. |
|
913 |
$select_count = array(); |
|
914 |
foreach ( $avail_roles as $this_role => $name ) { |
|
9 | 915 |
$select_count[] = $wpdb->prepare( 'COUNT(NULLIF(`meta_value` LIKE %s, false))', '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%' ); |
0 | 916 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
$select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))"; |
9 | 918 |
$select_count = implode( ', ', $select_count ); |
0 | 919 |
|
920 |
// Add the meta_value index to the selection list, then run the query. |
|
9 | 921 |
$row = $wpdb->get_row( |
922 |
" |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
SELECT {$select_count}, COUNT(*) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
FROM {$wpdb->usermeta} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
INNER JOIN {$wpdb->users} ON user_id = ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
WHERE meta_key = '{$blog_prefix}capabilities' |
9 | 927 |
", |
928 |
ARRAY_N |
|
929 |
); |
|
0 | 930 |
|
931 |
// Run the previous loop again to associate results with role names. |
|
9 | 932 |
$col = 0; |
0 | 933 |
$role_counts = array(); |
934 |
foreach ( $avail_roles as $this_role => $name ) { |
|
9 | 935 |
$count = (int) $row[ $col++ ]; |
936 |
if ( $count > 0 ) { |
|
937 |
$role_counts[ $this_role ] = $count; |
|
0 | 938 |
} |
939 |
} |
|
940 |
||
9 | 941 |
$role_counts['none'] = (int) $row[ $col++ ]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
|
0 | 943 |
// Get the meta_value index from the end of the result set. |
9 | 944 |
$total_users = (int) $row[ $col ]; |
0 | 945 |
|
946 |
$result['total_users'] = $total_users; |
|
947 |
$result['avail_roles'] =& $role_counts; |
|
948 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
$avail_roles = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
'none' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
|
9 | 953 |
$users_of_blog = $wpdb->get_col( |
954 |
" |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
SELECT meta_value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
FROM {$wpdb->usermeta} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
INNER JOIN {$wpdb->users} ON user_id = ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
WHERE meta_key = '{$blog_prefix}capabilities' |
9 | 959 |
" |
960 |
); |
|
0 | 961 |
|
962 |
foreach ( $users_of_blog as $caps_meta ) { |
|
9 | 963 |
$b_roles = maybe_unserialize( $caps_meta ); |
964 |
if ( ! is_array( $b_roles ) ) { |
|
0 | 965 |
continue; |
9 | 966 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
if ( empty( $b_roles ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
$avail_roles['none']++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
} |
0 | 970 |
foreach ( $b_roles as $b_role => $val ) { |
9 | 971 |
if ( isset( $avail_roles[ $b_role ] ) ) { |
972 |
$avail_roles[ $b_role ]++; |
|
0 | 973 |
} else { |
9 | 974 |
$avail_roles[ $b_role ] = 1; |
0 | 975 |
} |
976 |
} |
|
977 |
} |
|
978 |
||
979 |
$result['total_users'] = count( $users_of_blog ); |
|
980 |
$result['avail_roles'] =& $avail_roles; |
|
981 |
} |
|
982 |
||
983 |
return $result; |
|
984 |
} |
|
985 |
||
986 |
// |
|
987 |
// Private helper functions |
|
988 |
// |
|
989 |
||
990 |
/** |
|
991 |
* Set up global user vars. |
|
992 |
* |
|
993 |
* Used by wp_set_current_user() for back compat. Might be deprecated in the future. |
|
994 |
* |
|
995 |
* @since 2.0.4 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @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
|
998 |
* @global WP_User $userdata User data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
* @global int $user_level The level of the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* @global int $user_ID The ID of the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
* @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
|
1002 |
* @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
|
1003 |
* @global string $user_identity The display name of the user |
0 | 1004 |
* |
9 | 1005 |
* @param int $for_user_id Optional. User ID to set up global data. Default 0. |
0 | 1006 |
*/ |
9 | 1007 |
function setup_userdata( $for_user_id = 0 ) { |
0 | 1008 |
global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
1009 |
||
9 | 1010 |
if ( ! $for_user_id ) { |
0 | 1011 |
$for_user_id = get_current_user_id(); |
9 | 1012 |
} |
0 | 1013 |
$user = get_userdata( $for_user_id ); |
1014 |
||
1015 |
if ( ! $user ) { |
|
9 | 1016 |
$user_ID = 0; |
0 | 1017 |
$user_level = 0; |
9 | 1018 |
$userdata = null; |
0 | 1019 |
$user_login = $user_email = $user_url = $user_identity = ''; |
1020 |
return; |
|
1021 |
} |
|
1022 |
||
9 | 1023 |
$user_ID = (int) $user->ID; |
1024 |
$user_level = (int) $user->user_level; |
|
1025 |
$userdata = $user; |
|
1026 |
$user_login = $user->user_login; |
|
1027 |
$user_email = $user->user_email; |
|
1028 |
$user_url = $user->user_url; |
|
0 | 1029 |
$user_identity = $user->display_name; |
1030 |
} |
|
1031 |
||
1032 |
/** |
|
1033 |
* Create dropdown HTML content of users. |
|
1034 |
* |
|
1035 |
* The content can either be displayed, which it is by default or retrieved by |
|
1036 |
* setting the 'echo' argument. The 'include' and 'exclude' arguments do not |
|
1037 |
* need to be used; all users will be displayed in that case. Only one can be |
|
1038 |
* used, either 'include' or 'exclude', but not both. |
|
1039 |
* |
|
1040 |
* The available arguments are as follows: |
|
1041 |
* |
|
1042 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
* @since 4.5.0 Added the 'display_name_with_login' value for 'show'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
* @since 4.7.0 Added the `$role`, `$role__in`, and `$role__not_in` parameters. |
5 | 1045 |
* |
1046 |
* @param array|string $args { |
|
1047 |
* 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
|
1048 |
* See WP_User_Query::prepare_query() for additional available arguments. |
0 | 1049 |
* |
5 | 1050 |
* @type string $show_option_all Text to show as the drop-down default (all). |
1051 |
* Default empty. |
|
1052 |
* @type string $show_option_none Text to show as the drop-down default when no |
|
1053 |
* users were found. Default empty. |
|
1054 |
* @type int|string $option_none_value Value to use for $show_option_non when no users |
|
1055 |
* were found. Default -1. |
|
1056 |
* @type string $hide_if_only_one_author Whether to skip generating the drop-down |
|
1057 |
* if only one user was found. Default empty. |
|
1058 |
* @type string $orderby Field to order found users by. Accepts user fields. |
|
1059 |
* Default 'display_name'. |
|
1060 |
* @type string $order Whether to order users in ascending or descending |
|
1061 |
* order. Accepts 'ASC' (ascending) or 'DESC' (descending). |
|
1062 |
* Default 'ASC'. |
|
1063 |
* @type array|string $include Array or comma-separated list of user IDs to include. |
|
1064 |
* Default empty. |
|
1065 |
* @type array|string $exclude Array or comma-separated list of user IDs to exclude. |
|
1066 |
* Default empty. |
|
1067 |
* @type bool|int $multi Whether to skip the ID attribute on the 'select' element. |
|
1068 |
* Accepts 1|true or 0|false. Default 0|false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* @type string $show User data to display. If the selected item is empty |
5 | 1070 |
* then the 'user_login' will be displayed in parentheses. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
* Accepts any user field, or 'display_name_with_login' to show |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
* the display name with user_login in parentheses. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
* Default 'display_name'. |
5 | 1074 |
* @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo) |
1075 |
* or 0|false (return). Default 1|true. |
|
1076 |
* @type int $selected Which user ID should be selected. Default 0. |
|
1077 |
* @type bool $include_selected Whether to always include the selected user ID in the drop- |
|
1078 |
* down. Default false. |
|
1079 |
* @type string $name Name attribute of select element. Default 'user'. |
|
1080 |
* @type string $id ID attribute of the select element. Default is the value of $name. |
|
1081 |
* @type string $class Class attribute of the select element. Default empty. |
|
1082 |
* @type int $blog_id ID of blog (Multisite only). Default is ID of the current blog. |
|
1083 |
* @type string $who Which type of users to query. Accepts only an empty string or |
|
1084 |
* 'authors'. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
* @type string|array $role An array or a comma-separated list of role names that users must |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
* match to be included in results. Note that this is an inclusive |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
* list: users must match *each* role. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
* @type array $role__in An array of role names. Matched users must have at least one of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
* these roles. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
* @type array $role__not_in An array of role names to exclude. Users matching one or more of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
* these roles will not be included in results. Default empty array. |
5 | 1092 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
* @return string String of HTML content. |
0 | 1094 |
*/ |
1095 |
function wp_dropdown_users( $args = '' ) { |
|
1096 |
$defaults = array( |
|
9 | 1097 |
'show_option_all' => '', |
1098 |
'show_option_none' => '', |
|
1099 |
'hide_if_only_one_author' => '', |
|
1100 |
'orderby' => 'display_name', |
|
1101 |
'order' => 'ASC', |
|
1102 |
'include' => '', |
|
1103 |
'exclude' => '', |
|
1104 |
'multi' => 0, |
|
1105 |
'show' => 'display_name', |
|
1106 |
'echo' => 1, |
|
1107 |
'selected' => 0, |
|
1108 |
'name' => 'user', |
|
1109 |
'class' => '', |
|
1110 |
'id' => '', |
|
1111 |
'blog_id' => get_current_blog_id(), |
|
1112 |
'who' => '', |
|
1113 |
'include_selected' => false, |
|
1114 |
'option_none_value' => -1, |
|
1115 |
'role' => '', |
|
1116 |
'role__in' => array(), |
|
1117 |
'role__not_in' => array(), |
|
0 | 1118 |
); |
1119 |
||
1120 |
$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
1121 |
||
1122 |
$r = wp_parse_args( $args, $defaults ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
$query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who', 'role', 'role__in', 'role__not_in' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
$fields = array( 'ID', 'user_login' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
$show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
if ( 'display_name_with_login' === $show ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
$fields[] = 'display_name'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
$fields[] = $show; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
$query_args['fields'] = $fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
|
9 | 1137 |
$show_option_all = $r['show_option_all']; |
1138 |
$show_option_none = $r['show_option_none']; |
|
5 | 1139 |
$option_none_value = $r['option_none_value']; |
0 | 1140 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* 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
|
1143 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
* @param array $query_args The query arguments for get_users(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
* @param array $r The arguments passed to wp_dropdown_users() combined with the defaults. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
$query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
|
0 | 1151 |
$users = get_users( $query_args ); |
1152 |
||
1153 |
$output = ''; |
|
5 | 1154 |
if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
1155 |
$name = esc_attr( $r['name'] ); |
|
1156 |
if ( $r['multi'] && ! $r['id'] ) { |
|
0 | 1157 |
$id = ''; |
5 | 1158 |
} else { |
1159 |
$id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
1160 |
} |
|
1161 |
$output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
|
0 | 1162 |
|
5 | 1163 |
if ( $show_option_all ) { |
0 | 1164 |
$output .= "\t<option value='0'>$show_option_all</option>\n"; |
5 | 1165 |
} |
0 | 1166 |
|
1167 |
if ( $show_option_none ) { |
|
5 | 1168 |
$_selected = selected( $option_none_value, $r['selected'], false ); |
9 | 1169 |
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
0 | 1170 |
} |
1171 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
$found_selected = false; |
9 | 1174 |
$r['selected'] = (int) $r['selected']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
foreach ( (array) $users as $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
$user->ID = (int) $user->ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
if ( $user->ID === $r['selected'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
$found_selected = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
} |
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 |
if ( ! $found_selected ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
$users[] = get_userdata( $r['selected'] ); |
5 | 1184 |
} |
0 | 1185 |
} |
1186 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
foreach ( (array) $users as $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
if ( 'display_name_with_login' === $show ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
/* translators: 1: display name, 2: user_login */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
$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
|
1191 |
} elseif ( ! empty( $user->$show ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
$display = $user->$show; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
$display = '(' . $user->user_login . ')'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
|
5 | 1197 |
$_selected = selected( $user->ID, $r['selected'], false ); |
9 | 1198 |
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
0 | 1199 |
} |
1200 |
||
9 | 1201 |
$output .= '</select>'; |
0 | 1202 |
} |
1203 |
||
5 | 1204 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* Filters the wp_dropdown_users() HTML output. |
5 | 1206 |
* |
1207 |
* @since 2.3.0 |
|
1208 |
* |
|
1209 |
* @param string $output HTML output generated by wp_dropdown_users(). |
|
1210 |
*/ |
|
1211 |
$html = apply_filters( 'wp_dropdown_users', $output ); |
|
0 | 1212 |
|
5 | 1213 |
if ( $r['echo'] ) { |
1214 |
echo $html; |
|
1215 |
} |
|
1216 |
return $html; |
|
0 | 1217 |
} |
1218 |
||
1219 |
/** |
|
1220 |
* Sanitize user field based on context. |
|
1221 |
* |
|
1222 |
* Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The |
|
1223 |
* 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display' |
|
1224 |
* when calling filters. |
|
1225 |
* |
|
1226 |
* @since 2.3.0 |
|
1227 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
* @param string $field The user Object field name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
* @param mixed $value The user Object value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
* @param int $user_id User ID. |
0 | 1231 |
* @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
|
1232 |
* 'attribute' and 'js'. |
0 | 1233 |
* @return mixed Sanitized value. |
1234 |
*/ |
|
9 | 1235 |
function sanitize_user_field( $field, $value, $user_id, $context ) { |
1236 |
$int_fields = array( 'ID' ); |
|
1237 |
if ( in_array( $field, $int_fields ) ) { |
|
0 | 1238 |
$value = (int) $value; |
9 | 1239 |
} |
1240 |
||
1241 |
if ( 'raw' == $context ) { |
|
0 | 1242 |
return $value; |
9 | 1243 |
} |
1244 |
||
1245 |
if ( ! is_string( $value ) && ! is_numeric( $value ) ) { |
|
0 | 1246 |
return $value; |
9 | 1247 |
} |
0 | 1248 |
|
1249 |
$prefixed = false !== strpos( $field, 'user_' ); |
|
1250 |
||
1251 |
if ( 'edit' == $context ) { |
|
1252 |
if ( $prefixed ) { |
|
5 | 1253 |
|
1254 |
/** This filter is documented in wp-includes/post.php */ |
|
1255 |
$value = apply_filters( "edit_{$field}", $value, $user_id ); |
|
0 | 1256 |
} else { |
5 | 1257 |
|
1258 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* Filters a user field value in the 'edit' context. |
5 | 1260 |
* |
1261 |
* The dynamic portion of the hook name, `$field`, refers to the prefixed user |
|
1262 |
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
|
1263 |
* |
|
1264 |
* @since 2.9.0 |
|
1265 |
* |
|
1266 |
* @param mixed $value Value of the prefixed user field. |
|
1267 |
* @param int $user_id User ID. |
|
1268 |
*/ |
|
1269 |
$value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
|
0 | 1270 |
} |
1271 |
||
9 | 1272 |
if ( 'description' == $field ) { |
0 | 1273 |
$value = esc_html( $value ); // textarea_escaped? |
9 | 1274 |
} else { |
1275 |
$value = esc_attr( $value ); |
|
1276 |
} |
|
5 | 1277 |
} elseif ( 'db' == $context ) { |
0 | 1278 |
if ( $prefixed ) { |
5 | 1279 |
/** This filter is documented in wp-includes/post.php */ |
1280 |
$value = apply_filters( "pre_{$field}", $value ); |
|
0 | 1281 |
} else { |
5 | 1282 |
|
1283 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* Filters the value of a user field in the 'db' context. |
5 | 1285 |
* |
1286 |
* The dynamic portion of the hook name, `$field`, refers to the prefixed user |
|
1287 |
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
|
9 | 1288 |
* |
5 | 1289 |
* @since 2.9.0 |
1290 |
* |
|
1291 |
* @param mixed $value Value of the prefixed user field. |
|
1292 |
*/ |
|
1293 |
$value = apply_filters( "pre_user_{$field}", $value ); |
|
0 | 1294 |
} |
1295 |
} else { |
|
1296 |
// Use display filters by default. |
|
5 | 1297 |
if ( $prefixed ) { |
1298 |
||
1299 |
/** 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
|
1300 |
$value = apply_filters( "{$field}", $value, $user_id, $context ); |
5 | 1301 |
} else { |
1302 |
||
1303 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
* Filters the value of a user field in a standard context. |
5 | 1305 |
* |
1306 |
* The dynamic portion of the hook name, `$field`, refers to the prefixed user |
|
1307 |
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
|
1308 |
* |
|
1309 |
* @since 2.9.0 |
|
1310 |
* |
|
1311 |
* @param mixed $value The user object value to sanitize. |
|
1312 |
* @param int $user_id User ID. |
|
1313 |
* @param string $context The context to filter within. |
|
1314 |
*/ |
|
1315 |
$value = apply_filters( "user_{$field}", $value, $user_id, $context ); |
|
1316 |
} |
|
0 | 1317 |
} |
1318 |
||
9 | 1319 |
if ( 'user_url' == $field ) { |
1320 |
$value = esc_url( $value ); |
|
1321 |
} |
|
0 | 1322 |
|
5 | 1323 |
if ( 'attribute' == $context ) { |
1324 |
$value = esc_attr( $value ); |
|
1325 |
} elseif ( 'js' == $context ) { |
|
1326 |
$value = esc_js( $value ); |
|
1327 |
} |
|
0 | 1328 |
return $value; |
1329 |
} |
|
1330 |
||
1331 |
/** |
|
1332 |
* Update all user caches |
|
1333 |
* |
|
1334 |
* @since 3.0.0 |
|
1335 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
* @param WP_User $user User object to be cached |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
* @return bool|null Returns false on failure. |
0 | 1338 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
function update_user_caches( $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
if ( $user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
if ( ! $user->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
$user = $user->data; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
|
9 | 1348 |
wp_cache_add( $user->ID, $user, 'users' ); |
1349 |
wp_cache_add( $user->user_login, $user->ID, 'userlogins' ); |
|
1350 |
wp_cache_add( $user->user_email, $user->ID, 'useremail' ); |
|
1351 |
wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' ); |
|
0 | 1352 |
} |
1353 |
||
1354 |
/** |
|
1355 |
* Clean all user caches |
|
1356 |
* |
|
1357 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
* @since 4.4.0 'clean_user_cache' action was added. |
0 | 1359 |
* |
1360 |
* @param WP_User|int $user User object or ID to be cleaned from the cache |
|
1361 |
*/ |
|
1362 |
function clean_user_cache( $user ) { |
|
9 | 1363 |
if ( is_numeric( $user ) ) { |
0 | 1364 |
$user = new WP_User( $user ); |
9 | 1365 |
} |
1366 |
||
1367 |
if ( ! $user->exists() ) { |
|
0 | 1368 |
return; |
9 | 1369 |
} |
0 | 1370 |
|
1371 |
wp_cache_delete( $user->ID, 'users' ); |
|
1372 |
wp_cache_delete( $user->user_login, 'userlogins' ); |
|
1373 |
wp_cache_delete( $user->user_email, 'useremail' ); |
|
1374 |
wp_cache_delete( $user->user_nicename, 'userslugs' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
* 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
|
1378 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
* @param WP_User $user User object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
do_action( 'clean_user_cache', $user->ID, $user ); |
0 | 1385 |
} |
1386 |
||
1387 |
/** |
|
9 | 1388 |
* Determines whether the given username exists. |
1389 |
* |
|
1390 |
* For more information on this and similar theme functions, check out |
|
1391 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1392 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 1393 |
* |
1394 |
* @since 2.0.0 |
|
1395 |
* |
|
1396 |
* @param string $username Username. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
* @return int|false The user's ID on success, and false on failure. |
0 | 1398 |
*/ |
1399 |
function username_exists( $username ) { |
|
9 | 1400 |
$user = get_user_by( 'login', $username ); |
1401 |
if ( $user ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
$user_id = $user->ID; |
0 | 1403 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
$user_id = false; |
0 | 1405 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
* Filters whether the given username exists or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
* @param int|false $user_id The user's ID on success, and false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
* @param string $username Username to check. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
return apply_filters( 'username_exists', $user_id, $username ); |
0 | 1416 |
} |
1417 |
||
1418 |
/** |
|
9 | 1419 |
* Determines whether the given email exists. |
1420 |
* |
|
1421 |
* For more information on this and similar theme functions, check out |
|
1422 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1423 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 1424 |
* |
1425 |
* @since 2.1.0 |
|
1426 |
* |
|
1427 |
* @param string $email Email. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
* @return int|false The user's ID on success, and false on failure. |
0 | 1429 |
*/ |
1430 |
function email_exists( $email ) { |
|
9 | 1431 |
$user = get_user_by( 'email', $email ); |
1432 |
if ( $user ) { |
|
0 | 1433 |
return $user->ID; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
} |
0 | 1435 |
return false; |
1436 |
} |
|
1437 |
||
1438 |
/** |
|
5 | 1439 |
* Checks whether a username is valid. |
0 | 1440 |
* |
1441 |
* @since 2.0.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
* @since 4.4.0 Empty sanitized usernames are now considered invalid |
0 | 1443 |
* |
1444 |
* @param string $username Username. |
|
1445 |
* @return bool Whether username given is valid |
|
1446 |
*/ |
|
1447 |
function validate_username( $username ) { |
|
1448 |
$sanitized = sanitize_user( $username, true ); |
|
9 | 1449 |
$valid = ( $sanitized == $username && ! empty( $sanitized ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
|
5 | 1451 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1452 |
* Filters whether the provided username is valid or not. |
5 | 1453 |
* |
1454 |
* @since 2.0.1 |
|
1455 |
* |
|
1456 |
* @param bool $valid Whether given username is valid. |
|
1457 |
* @param string $username Username to check. |
|
1458 |
*/ |
|
0 | 1459 |
return apply_filters( 'validate_username', $valid, $username ); |
1460 |
} |
|
1461 |
||
1462 |
/** |
|
5 | 1463 |
* Insert a user into the database. |
0 | 1464 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
* 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
|
1466 |
* 'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
* 'user_registered', and 'role'. The filters have the prefix 'pre_user_' followed by the field |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
* name. An example using 'description' would have the filter called, 'pre_user_description' that |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
* can be hooked into. |
0 | 1470 |
* |
5 | 1471 |
* @since 2.0.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
* @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
|
1473 |
* methods for new installations. See wp_get_user_contact_methods(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
* @since 4.7.0 The user's locale can be passed to `$userdata`. |
5 | 1475 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 1477 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
* @param array|object|WP_User $userdata { |
5 | 1479 |
* An array, object, or WP_User object of user data arguments. |
0 | 1480 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
* @type int $ID User ID. If supplied, the user will be updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
* @type string $user_pass The plain-text user password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
* @type string $user_login The user's login username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
* @type string $user_nicename The URL-friendly user name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
* @type string $user_url The user URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
* @type string $user_email The user email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
* @type string $display_name The user's display name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
* Default is the user's username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
* @type string $nickname The user's nickname. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
* Default is the user's username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
* @type string $first_name The user's first name. For new users, will be used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
* to build the first part of the user's display name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
* if `$display_name` is not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
* @type string $last_name The user's last name. For new users, will be used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
* to build the second part of the user's display name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
* if `$display_name` is not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
* @type string $description The user's biographical description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
* @type string|bool $rich_editing Whether to enable the rich-editor for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
* False if not empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
* @type string|bool $syntax_highlighting Whether to enable the rich code editor for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
* False if not empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1502 |
* @type string|bool $comment_shortcuts Whether to enable comment moderation keyboard |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1503 |
* shortcuts for the user. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
* @type string $admin_color Admin color scheme for the user. Default 'fresh'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
* @type bool $use_ssl Whether the user should always access the admin over |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
* https. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1507 |
* @type string $user_registered Date the user registered. Format is 'Y-m-d H:i:s'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1508 |
* @type string|bool $show_admin_bar_front Whether to display the Admin Bar for the user on the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
* site's front end. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1510 |
* @type string $role User's role. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
* @type string $locale User's locale. Default empty. |
5 | 1512 |
* } |
1513 |
* @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not |
|
1514 |
* be created. |
|
0 | 1515 |
*/ |
1516 |
function wp_insert_user( $userdata ) { |
|
1517 |
global $wpdb; |
|
1518 |
||
5 | 1519 |
if ( $userdata instanceof stdClass ) { |
0 | 1520 |
$userdata = get_object_vars( $userdata ); |
5 | 1521 |
} elseif ( $userdata instanceof WP_User ) { |
0 | 1522 |
$userdata = $userdata->to_array(); |
5 | 1523 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
|
0 | 1525 |
// Are we updating or creating? |
5 | 1526 |
if ( ! empty( $userdata['ID'] ) ) { |
9 | 1527 |
$ID = (int) $userdata['ID']; |
1528 |
$update = true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1529 |
$old_user_data = get_userdata( $ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1531 |
if ( ! $old_user_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
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
|
1533 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
|
5 | 1535 |
// 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
|
1536 |
$user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass; |
0 | 1537 |
} else { |
1538 |
$update = false; |
|
1539 |
// Hash the password |
|
5 | 1540 |
$user_pass = wp_hash_password( $userdata['user_pass'] ); |
0 | 1541 |
} |
1542 |
||
5 | 1543 |
$sanitized_user_login = sanitize_user( $userdata['user_login'], true ); |
1544 |
||
1545 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
* Filters a username after it has been sanitized. |
5 | 1547 |
* |
1548 |
* This filter is called before the user is created or updated. |
|
1549 |
* |
|
1550 |
* @since 2.0.3 |
|
1551 |
* |
|
1552 |
* @param string $sanitized_user_login Username after it has been sanitized. |
|
1553 |
*/ |
|
1554 |
$pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); |
|
0 | 1555 |
|
1556 |
//Remove any non-printable chars from the login string to see if we have ended up with an empty username |
|
5 | 1557 |
$user_login = trim( $pre_user_login ); |
0 | 1558 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
// user_login must be between 0 and 60 characters. |
5 | 1560 |
if ( empty( $user_login ) ) { |
9 | 1561 |
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
|
1562 |
} elseif ( mb_strlen( $user_login ) > 60 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); |
5 | 1564 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
|
5 | 1566 |
if ( ! $update && username_exists( $user_login ) ) { |
1567 |
return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); |
|
1568 |
} |
|
0 | 1569 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
* Filters the list of blacklisted usernames. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
* @param array $usernames Array of blacklisted usernames. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
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
|
1581 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1584 |
* 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
|
1585 |
* Otherwise build a nicename from the user_login. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
*/ |
5 | 1587 |
if ( ! empty( $userdata['user_nicename'] ) ) { |
1588 |
$user_nicename = sanitize_user( $userdata['user_nicename'], true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
if ( mb_strlen( $user_nicename ) > 50 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
} |
5 | 1592 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
$user_nicename = mb_substr( $user_login, 0, 50 ); |
5 | 1594 |
} |
1595 |
||
1596 |
$user_nicename = sanitize_title( $user_nicename ); |
|
1597 |
||
1598 |
// Store values to save in user meta. |
|
1599 |
$meta = array(); |
|
0 | 1600 |
|
5 | 1601 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
* Filters a user's nicename before the user is created or updated. |
5 | 1603 |
* |
1604 |
* @since 2.0.3 |
|
1605 |
* |
|
1606 |
* @param string $user_nicename The user's nicename. |
|
1607 |
*/ |
|
1608 |
$user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); |
|
1609 |
||
1610 |
$raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url']; |
|
0 | 1611 |
|
5 | 1612 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1613 |
* Filters a user's URL before the user is created or updated. |
5 | 1614 |
* |
1615 |
* @since 2.0.3 |
|
1616 |
* |
|
1617 |
* @param string $raw_user_url The user's URL. |
|
1618 |
*/ |
|
1619 |
$user_url = apply_filters( 'pre_user_url', $raw_user_url ); |
|
0 | 1620 |
|
5 | 1621 |
$raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email']; |
0 | 1622 |
|
5 | 1623 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
* Filters a user's email before the user is created or updated. |
5 | 1625 |
* |
1626 |
* @since 2.0.3 |
|
1627 |
* |
|
1628 |
* @param string $raw_user_email The user's email. |
|
1629 |
*/ |
|
1630 |
$user_email = apply_filters( 'pre_user_email', $raw_user_email ); |
|
0 | 1631 |
|
5 | 1632 |
/* |
1633 |
* If there is no update, just check for `email_exists`. If there is an update, |
|
1634 |
* check if current email and new email are the same, or not, and check `email_exists` |
|
1635 |
* accordingly. |
|
1636 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) ) |
5 | 1638 |
&& ! defined( 'WP_IMPORTING' ) |
1639 |
&& email_exists( $user_email ) |
|
1640 |
) { |
|
1641 |
return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); |
|
1642 |
} |
|
1643 |
$nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; |
|
0 | 1644 |
|
5 | 1645 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
* Filters a user's nickname before the user is created or updated. |
5 | 1647 |
* |
1648 |
* @since 2.0.3 |
|
1649 |
* |
|
1650 |
* @param string $nickname The user's nickname. |
|
1651 |
*/ |
|
1652 |
$meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname ); |
|
0 | 1653 |
|
5 | 1654 |
$first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name']; |
1655 |
||
1656 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
* Filters a user's first name before the user is created or updated. |
5 | 1658 |
* |
1659 |
* @since 2.0.3 |
|
1660 |
* |
|
1661 |
* @param string $first_name The user's first name. |
|
1662 |
*/ |
|
1663 |
$meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name ); |
|
0 | 1664 |
|
5 | 1665 |
$last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name']; |
1666 |
||
1667 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
* Filters a user's last name before the user is created or updated. |
5 | 1669 |
* |
1670 |
* @since 2.0.3 |
|
1671 |
* |
|
1672 |
* @param string $last_name The user's last name. |
|
1673 |
*/ |
|
1674 |
$meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name ); |
|
1675 |
||
1676 |
if ( empty( $userdata['display_name'] ) ) { |
|
1677 |
if ( $update ) { |
|
0 | 1678 |
$display_name = $user_login; |
5 | 1679 |
} elseif ( $meta['first_name'] && $meta['last_name'] ) { |
0 | 1680 |
/* translators: 1: first name, 2: last name */ |
5 | 1681 |
$display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] ); |
1682 |
} elseif ( $meta['first_name'] ) { |
|
1683 |
$display_name = $meta['first_name']; |
|
1684 |
} elseif ( $meta['last_name'] ) { |
|
1685 |
$display_name = $meta['last_name']; |
|
1686 |
} else { |
|
0 | 1687 |
$display_name = $user_login; |
5 | 1688 |
} |
1689 |
} else { |
|
1690 |
$display_name = $userdata['display_name']; |
|
0 | 1691 |
} |
5 | 1692 |
|
1693 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1694 |
* Filters a user's display name before the user is created or updated. |
5 | 1695 |
* |
1696 |
* @since 2.0.3 |
|
1697 |
* |
|
1698 |
* @param string $display_name The user's display name. |
|
1699 |
*/ |
|
0 | 1700 |
$display_name = apply_filters( 'pre_user_display_name', $display_name ); |
1701 |
||
5 | 1702 |
$description = empty( $userdata['description'] ) ? '' : $userdata['description']; |
0 | 1703 |
|
5 | 1704 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
* Filters a user's description before the user is created or updated. |
5 | 1706 |
* |
1707 |
* @since 2.0.3 |
|
1708 |
* |
|
1709 |
* @param string $description The user's description. |
|
1710 |
*/ |
|
1711 |
$meta['description'] = apply_filters( 'pre_user_description', $description ); |
|
0 | 1712 |
|
5 | 1713 |
$meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; |
1714 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
$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
|
1716 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1717 |
$meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
0 | 1718 |
|
9 | 1719 |
$admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color']; |
5 | 1720 |
$meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color ); |
0 | 1721 |
|
5 | 1722 |
$meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl']; |
0 | 1723 |
|
5 | 1724 |
$user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered']; |
1725 |
||
1726 |
$meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; |
|
0 | 1727 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
$meta['locale'] = isset( $userdata['locale'] ) ? $userdata['locale'] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
|
9 | 1730 |
$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 ) ); |
0 | 1731 |
|
1732 |
if ( $user_nicename_check ) { |
|
1733 |
$suffix = 2; |
|
9 | 1734 |
while ( $user_nicename_check ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
// user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix. |
9 | 1736 |
$base_length = 49 - mb_strlen( $suffix ); |
1737 |
$alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix"; |
|
1738 |
$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 ) ); |
|
0 | 1739 |
$suffix++; |
1740 |
} |
|
1741 |
$user_nicename = $alt_user_nicename; |
|
1742 |
} |
|
1743 |
||
5 | 1744 |
$compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); |
9 | 1745 |
$data = wp_unslash( $compacted ); |
0 | 1746 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1747 |
if ( ! $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
$data = $data + compact( 'user_login' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
* 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
|
1753 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1754 |
* It only includes data in the wp_users table wp_user, not any user metadata. |
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 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
* @param array $data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
* Values and keys for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1760 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
* @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
|
1762 |
* @type string $user_pass The user's password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
* @type string $user_email The user's email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
* @type string $user_url The user's url. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
* @type string $user_nicename The user's nice name. Defaults to a URL-safe version of user's login |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
* @type string $display_name The user's display name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
* @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
|
1768 |
* the current UTC timestamp. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1769 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1770 |
* @param bool $update Whether the user is being updated rather than created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
* @param int|null $id ID of the user to be updated, or NULL if the user is being created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
|
0 | 1775 |
if ( $update ) { |
5 | 1776 |
if ( $user_email !== $old_user_data->user_email ) { |
1777 |
$data['user_activation_key'] = ''; |
|
1778 |
} |
|
0 | 1779 |
$wpdb->update( $wpdb->users, $data, compact( 'ID' ) ); |
1780 |
$user_id = (int) $ID; |
|
1781 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
$wpdb->insert( $wpdb->users, $data ); |
0 | 1783 |
$user_id = (int) $wpdb->insert_id; |
1784 |
} |
|
1785 |
||
1786 |
$user = new WP_User( $user_id ); |
|
1787 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
/** |
9 | 1789 |
* Filters a user's meta values and keys immediately after the user is created or updated |
1790 |
* and before any user meta is inserted or updated. |
|
1791 |
* |
|
1792 |
* Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. |
|
1793 |
* |
|
1794 |
* @since 4.4.0 |
|
1795 |
* |
|
1796 |
* @param array $meta { |
|
1797 |
* Default meta values and keys for the user. |
|
1798 |
* |
|
1799 |
* @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
|
1800 |
* @type string $first_name The user's first name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
* @type string $last_name The user's last name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
* @type string $description The user's description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
* @type bool $rich_editing Whether to enable the rich-editor for the user. False if not empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1804 |
* @type bool $syntax_highlighting Whether to enable the rich code editor for the user. False if not empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1805 |
* @type bool $comment_shortcuts Whether to enable keyboard shortcuts for the user. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
* @type string $admin_color The color scheme for a user's admin screen. Default 'fresh'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
* @type int|bool $use_ssl Whether to force SSL on the user's admin area. 0|false if SSL is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
* not forced. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
* @type bool $show_admin_bar_front Whether to show the admin bar on the front end for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
* Default true. |
9 | 1811 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
* @param WP_User $user User object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
* @param bool $update Whether the user is being updated rather than created. |
9 | 1814 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
$meta = apply_filters( 'insert_user_meta', $meta, $user, $update ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
|
5 | 1817 |
// Update user meta. |
1818 |
foreach ( $meta as $key => $value ) { |
|
1819 |
update_user_meta( $user_id, $key, $value ); |
|
1820 |
} |
|
1821 |
||
1822 |
foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) { |
|
1823 |
if ( isset( $userdata[ $key ] ) ) { |
|
1824 |
update_user_meta( $user_id, $key, $userdata[ $key ] ); |
|
1825 |
} |
|
0 | 1826 |
} |
1827 |
||
5 | 1828 |
if ( isset( $userdata['role'] ) ) { |
1829 |
$user->set_role( $userdata['role'] ); |
|
1830 |
} elseif ( ! $update ) { |
|
9 | 1831 |
$user->set_role( get_option( 'default_role' ) ); |
5 | 1832 |
} |
1833 |
wp_cache_delete( $user_id, 'users' ); |
|
1834 |
wp_cache_delete( $user_login, 'userlogins' ); |
|
0 | 1835 |
|
5 | 1836 |
if ( $update ) { |
1837 |
/** |
|
1838 |
* Fires immediately after an existing user is updated. |
|
1839 |
* |
|
1840 |
* @since 2.0.0 |
|
1841 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1842 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1843 |
* @param WP_User $old_user_data Object containing user's data prior to update. |
5 | 1844 |
*/ |
1845 |
do_action( 'profile_update', $user_id, $old_user_data ); |
|
1846 |
} else { |
|
1847 |
/** |
|
1848 |
* Fires immediately after a new user is registered. |
|
1849 |
* |
|
1850 |
* @since 1.5.0 |
|
1851 |
* |
|
1852 |
* @param int $user_id User ID. |
|
1853 |
*/ |
|
1854 |
do_action( 'user_register', $user_id ); |
|
1855 |
} |
|
0 | 1856 |
|
1857 |
return $user_id; |
|
1858 |
} |
|
1859 |
||
1860 |
/** |
|
5 | 1861 |
* Update a user in the database. |
0 | 1862 |
* |
1863 |
* It is possible to update a user's password by specifying the 'user_pass' |
|
1864 |
* value in the $userdata parameter array. |
|
1865 |
* |
|
1866 |
* If current user's password is being updated, then the cookies will be |
|
1867 |
* cleared. |
|
1868 |
* |
|
1869 |
* @since 2.0.0 |
|
5 | 1870 |
* |
1871 |
* @see wp_insert_user() For what fields can be set in $userdata. |
|
0 | 1872 |
* |
9 | 1873 |
* @param array|object|WP_User $userdata An array of user data or a user object of type stdClass or WP_User. |
0 | 1874 |
* @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. |
1875 |
*/ |
|
9 | 1876 |
function wp_update_user( $userdata ) { |
5 | 1877 |
if ( $userdata instanceof stdClass ) { |
0 | 1878 |
$userdata = get_object_vars( $userdata ); |
5 | 1879 |
} elseif ( $userdata instanceof WP_User ) { |
0 | 1880 |
$userdata = $userdata->to_array(); |
5 | 1881 |
} |
0 | 1882 |
|
5 | 1883 |
$ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0; |
1884 |
if ( ! $ID ) { |
|
1885 |
return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
1886 |
} |
|
0 | 1887 |
|
1888 |
// First, get all of the original fields |
|
1889 |
$user_obj = get_userdata( $ID ); |
|
5 | 1890 |
if ( ! $user_obj ) { |
0 | 1891 |
return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
5 | 1892 |
} |
0 | 1893 |
|
1894 |
$user = $user_obj->to_array(); |
|
1895 |
||
1896 |
// Add additional custom fields |
|
1897 |
foreach ( _get_additional_user_keys( $user_obj ) as $key ) { |
|
1898 |
$user[ $key ] = get_user_meta( $ID, $key, true ); |
|
1899 |
} |
|
1900 |
||
1901 |
// Escape data pulled from DB. |
|
1902 |
$user = add_magic_quotes( $user ); |
|
1903 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
// If password is changing, hash it now |
9 | 1906 |
$plaintext_pass = $userdata['user_pass']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
$userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1909 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
* Filters whether to send the password change email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1911 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
* @see wp_insert_user() For `$user` and `$userdata` fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
* @param bool $send Whether to send the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
* @param array $user The original user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
* @param array $userdata The updated user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
$send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata ); |
0 | 1921 |
} |
1922 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1923 |
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
|
1924 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1925 |
* Filters whether to send the email change email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1928 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
* @see wp_insert_user() For `$user` and `$userdata` fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1930 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1931 |
* @param bool $send Whether to send the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1932 |
* @param array $user The original user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1933 |
* @param array $userdata The updated user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
$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
|
1936 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1937 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
wp_cache_delete( $user['user_email'], 'useremail' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
wp_cache_delete( $user['user_nicename'], 'userslugs' ); |
0 | 1940 |
|
1941 |
// 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
|
1942 |
$userdata = array_merge( $user, $userdata ); |
9 | 1943 |
$user_id = wp_insert_user( $userdata ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1944 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1945 |
if ( ! is_wp_error( $user_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1946 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
$blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1949 |
$switched_locale = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1950 |
if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1951 |
$switched_locale = switch_to_locale( get_user_locale( $user_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1953 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1954 |
if ( ! empty( $send_password_change_email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1955 |
/* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 1956 |
$pass_change_text = __( |
1957 |
'Hi ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1959 |
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
|
1960 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
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
|
1962 |
###ADMIN_EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
All at ###SITENAME### |
9 | 1968 |
###SITEURL###' |
1969 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1970 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1971 |
$pass_change_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
'to' => $user['user_email'], |
9 | 1973 |
/* translators: Password change notification email subject. %s: Site name */ |
1974 |
'subject' => __( '[%s] Password Changed' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
'message' => $pass_change_text, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1976 |
'headers' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
* Filters the contents of the email sent when the user's password is changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
* @since 4.3.0 |
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 |
* @param array $pass_change_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
* Used to build wp_mail(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
* @type string $to The intended recipients. Add emails in a comma separated string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
* @type string $subject The subject of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1988 |
* @type string $message The content of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
* 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
|
1990 |
* - ###USERNAME### The current user's username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
* - ###ADMIN_EMAIL### The admin email in case this was unexpected. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
* - ###EMAIL### The user's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
* - ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
* - ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1995 |
* @type string $headers Headers. Add headers in a newline (\r\n) separated string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1996 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1997 |
* @param array $user The original user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1998 |
* @param array $userdata The updated user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1999 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2000 |
$pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2002 |
$pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2003 |
$pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2004 |
$pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2005 |
$pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2006 |
$pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2007 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
if ( ! empty( $send_email_change_email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
/* translators: Do not translate USERNAME, ADMIN_EMAIL, NEW_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 2013 |
$email_change_text = __( |
2014 |
'Hi ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2015 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2016 |
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
|
2017 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
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
|
2019 |
###ADMIN_EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2020 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2021 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
All at ###SITENAME### |
9 | 2025 |
###SITEURL###' |
2026 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
$email_change_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
'to' => $user['user_email'], |
9 | 2030 |
/* translators: Email change notification email subject. %s: Site name */ |
2031 |
'subject' => __( '[%s] Email Changed' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
'message' => $email_change_text, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
'headers' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
* Filters the contents of the email sent when the user's email is changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
* @param array $email_change_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
* Used to build wp_mail(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2043 |
* @type string $to The intended recipients. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2044 |
* @type string $subject The subject of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
* @type string $message The content of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
* 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
|
2047 |
* - ###USERNAME### The current user's username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
* - ###ADMIN_EMAIL### The admin email in case this was unexpected. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
* - ###NEW_EMAIL### The new email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
* - ###EMAIL### The old email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
* - ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
* - ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
* @type string $headers Headers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
* @param array $user The original user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
* @param array $userdata The updated user array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
$email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata ); |
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 |
$email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
$email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $userdata['user_email'], $email_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2063 |
$email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2064 |
$email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2066 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2067 |
wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
} |
0 | 2074 |
|
2075 |
// Update the cookies if the password changed. |
|
2076 |
$current_user = wp_get_current_user(); |
|
2077 |
if ( $current_user->ID == $ID ) { |
|
9 | 2078 |
if ( isset( $plaintext_pass ) ) { |
0 | 2079 |
wp_clear_auth_cookie(); |
5 | 2080 |
|
2081 |
// Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. |
|
2082 |
// If it's greater than this, then we know the user checked 'Remember Me' when they logged in. |
|
9 | 2083 |
$logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
5 | 2084 |
/** This filter is documented in wp-includes/pluggable.php */ |
2085 |
$default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false ); |
|
2086 |
$remember = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ); |
|
2087 |
||
2088 |
wp_set_auth_cookie( $ID, $remember ); |
|
0 | 2089 |
} |
2090 |
} |
|
2091 |
||
2092 |
return $user_id; |
|
2093 |
} |
|
2094 |
||
2095 |
/** |
|
5 | 2096 |
* A simpler way of inserting a user into the database. |
0 | 2097 |
* |
2098 |
* 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
|
2099 |
* complex user creation use wp_insert_user() to specify more information. |
0 | 2100 |
* |
2101 |
* @since 2.0.0 |
|
2102 |
* @see wp_insert_user() More complete way to create a new user |
|
2103 |
* |
|
2104 |
* @param string $username The user's username. |
|
2105 |
* @param string $password The user's password. |
|
5 | 2106 |
* @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
|
2107 |
* @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
|
2108 |
* be created. |
0 | 2109 |
*/ |
9 | 2110 |
function wp_create_user( $username, $password, $email = '' ) { |
0 | 2111 |
$user_login = wp_slash( $username ); |
9 | 2112 |
$user_email = wp_slash( $email ); |
2113 |
$user_pass = $password; |
|
2114 |
||
2115 |
$userdata = compact( 'user_login', 'user_email', 'user_pass' ); |
|
2116 |
return wp_insert_user( $userdata ); |
|
0 | 2117 |
} |
2118 |
||
2119 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2120 |
* 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
|
2121 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2122 |
* 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
|
2123 |
* of those keys in the user meta data to be set. |
0 | 2124 |
* |
2125 |
* @since 3.3.0 |
|
2126 |
* @access private |
|
2127 |
* |
|
5 | 2128 |
* @param WP_User $user WP_User instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
* @return array List of user keys to be populated in wp_update_user(). |
0 | 2130 |
*/ |
2131 |
function _get_additional_user_keys( $user ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2132 |
$keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' ); |
0 | 2133 |
return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); |
2134 |
} |
|
2135 |
||
2136 |
/** |
|
2137 |
* Set up the user contact methods. |
|
2138 |
* |
|
2139 |
* Default contact methods were removed in 3.6. A filter dictates contact methods. |
|
2140 |
* |
|
2141 |
* @since 3.7.0 |
|
2142 |
* |
|
2143 |
* @param WP_User $user Optional. WP_User object. |
|
2144 |
* @return array Array of contact methods and their labels. |
|
2145 |
*/ |
|
2146 |
function wp_get_user_contact_methods( $user = null ) { |
|
2147 |
$methods = array(); |
|
2148 |
if ( get_site_option( 'initial_db_version' ) < 23588 ) { |
|
2149 |
$methods = array( |
|
2150 |
'aim' => __( 'AIM' ), |
|
2151 |
'yim' => __( 'Yahoo IM' ), |
|
9 | 2152 |
'jabber' => __( 'Jabber / Google Talk' ), |
0 | 2153 |
); |
2154 |
} |
|
2155 |
||
2156 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2157 |
* Filters the user contact methods. |
0 | 2158 |
* |
2159 |
* @since 2.9.0 |
|
2160 |
* |
|
2161 |
* @param array $methods Array of contact methods and their labels. |
|
9 | 2162 |
* @param WP_User $user WP_User object. |
0 | 2163 |
*/ |
2164 |
return apply_filters( 'user_contactmethods', $methods, $user ); |
|
2165 |
} |
|
2166 |
||
2167 |
/** |
|
2168 |
* The old private function for setting up user contact methods. |
|
2169 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2170 |
* Use wp_get_user_contact_methods() instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2171 |
* |
0 | 2172 |
* @since 2.9.0 |
2173 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
* @param WP_User $user Optional. WP_User object. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
* @return array Array of contact methods and their labels. |
0 | 2177 |
*/ |
2178 |
function _wp_get_user_contactmethods( $user = null ) { |
|
2179 |
return wp_get_user_contact_methods( $user ); |
|
2180 |
} |
|
2181 |
||
2182 |
/** |
|
5 | 2183 |
* Gets the text suggesting how to create strong passwords. |
2184 |
* |
|
2185 |
* @since 4.1.0 |
|
2186 |
* |
|
2187 |
* @return string The password hint text. |
|
2188 |
*/ |
|
2189 |
function wp_get_password_hint() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2190 |
$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 | 2191 |
|
2192 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2193 |
* Filters the text describing the site's password complexity policy. |
5 | 2194 |
* |
2195 |
* @since 4.1.0 |
|
2196 |
* |
|
2197 |
* @param string $hint The password hint text. |
|
2198 |
*/ |
|
2199 |
return apply_filters( 'password_hint', $hint ); |
|
2200 |
} |
|
2201 |
||
2202 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
* 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
|
2204 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2205 |
* @since 4.4.0 |
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 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
* @global PasswordHash $wp_hasher Portable PHP password hashing framework. |
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 |
* @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
|
2211 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
* @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
|
2213 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2214 |
function get_password_reset_key( $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
global $wpdb, $wp_hasher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
|
9 | 2217 |
if ( ! ( $user instanceof WP_User ) ) { |
2218 |
return new WP_Error( 'invalidcombo', __( '<strong>ERROR</strong>: There is no account with that username or email address.' ) ); |
|
2219 |
} |
|
2220 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
* Fires before a new password is retrieved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2223 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2224 |
* Use the {@see 'retrieve_password'} hook instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2225 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2226 |
* @since 1.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2227 |
* @deprecated 1.5.1 Misspelled. Use 'retrieve_password' hook instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2228 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2229 |
* @param string $user_login The user login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2230 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2231 |
do_action( 'retreive_password', $user->user_login ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
* Fires before a new password is retrieved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
* @since 1.5.1 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
* @param string $user_login The user login name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
do_action( 'retrieve_password', $user->user_login ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
$allow = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
if ( is_multisite() && is_user_spammy( $user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
$allow = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2247 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2248 |
* Filters whether to allow a password to be reset. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2249 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2250 |
* @since 2.7.0 |
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 |
* @param bool $allow Whether to allow the password to be reset. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2253 |
* @param int $user_data->ID The ID of the user attempting to reset a password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2254 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2255 |
$allow = apply_filters( 'allow_password_reset', $allow, $user->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2256 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2257 |
if ( ! $allow ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2258 |
return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2259 |
} elseif ( is_wp_error( $allow ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2260 |
return $allow; |
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 |
// Generate something random for a password reset key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2264 |
$key = wp_generate_password( 20, false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2265 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2266 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
* Fires when a password reset key is generated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2268 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
* @param string $user_login The username for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
* @param string $key The generated password reset key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2273 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
do_action( 'retrieve_password_key', $user->user_login, $key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
// Now insert the key, hashed, into the DB. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
if ( empty( $wp_hasher ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2279 |
$wp_hasher = new PasswordHash( 8, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
} |
9 | 2281 |
$hashed = time() . ':' . $wp_hasher->HashPassword( $key ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
$key_saved = $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2283 |
if ( false === $key_saved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
return new WP_Error( 'no_password_key_update', __( 'Could not save password reset key to database.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2285 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2286 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
return $key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2288 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2289 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2290 |
/** |
0 | 2291 |
* Retrieves a user row based on password reset key and login |
2292 |
* |
|
2293 |
* A key is considered 'expired' if it exactly matches the value of the |
|
2294 |
* user_activation_key field, rather than being matched after going through the |
|
2295 |
* hashing process. This field is now hashed; old values are no longer accepted |
|
2296 |
* but have a different WP_Error code so good user feedback can be provided. |
|
2297 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2298 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2299 |
* |
5 | 2300 |
* @global wpdb $wpdb WordPress database object for queries. |
2301 |
* @global PasswordHash $wp_hasher Portable PHP password hashing framework instance. |
|
0 | 2302 |
* |
2303 |
* @param string $key Hash to validate sending user's password. |
|
2304 |
* @param string $login The user login. |
|
2305 |
* @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys. |
|
2306 |
*/ |
|
9 | 2307 |
function check_password_reset_key( $key, $login ) { |
0 | 2308 |
global $wpdb, $wp_hasher; |
2309 |
||
9 | 2310 |
$key = preg_replace( '/[^a-z0-9]/i', '', $key ); |
2311 |
||
2312 |
if ( empty( $key ) || ! is_string( $key ) ) { |
|
2313 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
|
2314 |
} |
|
2315 |
||
2316 |
if ( empty( $login ) || ! is_string( $login ) ) { |
|
2317 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
|
2318 |
} |
|
0 | 2319 |
|
2320 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
|
9 | 2321 |
if ( ! $row ) { |
2322 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
|
2323 |
} |
|
0 | 2324 |
|
2325 |
if ( empty( $wp_hasher ) ) { |
|
5 | 2326 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
0 | 2327 |
$wp_hasher = new PasswordHash( 8, true ); |
2328 |
} |
|
2329 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2330 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2331 |
* Filters the expiration time of password reset keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2333 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2334 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2335 |
* @param int $expiration The expiration time in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2336 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2337 |
$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
|
2338 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2339 |
if ( false !== strpos( $row->user_activation_key, ':' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
list( $pass_request_time, $pass_key ) = explode( ':', $row->user_activation_key, 2 ); |
9 | 2341 |
$expiration_time = $pass_request_time + $expiration_duration; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
} else { |
9 | 2343 |
$pass_key = $row->user_activation_key; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2344 |
$expiration_time = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2345 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2346 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2347 |
if ( ! $pass_key ) { |
9 | 2348 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2349 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2350 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2351 |
$hash_is_correct = $wp_hasher->CheckPassword( $key, $pass_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2352 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2353 |
if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { |
0 | 2354 |
return get_userdata( $row->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2355 |
} elseif ( $hash_is_correct && $expiration_time ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2356 |
// Key has an expiration time that's passed |
9 | 2357 |
return new WP_Error( 'expired_key', __( 'Invalid key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2358 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2359 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2360 |
if ( hash_equals( $row->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) { |
9 | 2361 |
$return = new WP_Error( 'expired_key', __( 'Invalid key.' ) ); |
0 | 2362 |
$user_id = $row->ID; |
2363 |
||
2364 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
* Filters the return value of check_password_reset_key() when an |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
* old-style key is used. |
0 | 2367 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
* @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
|
2369 |
* @since 4.3.0 Previously key hashes were stored without an expiration time. |
0 | 2370 |
* |
2371 |
* @param WP_Error $return A WP_Error object denoting an expired key. |
|
2372 |
* Return a WP_User object to validate the key. |
|
2373 |
* @param int $user_id The matched user ID. |
|
2374 |
*/ |
|
2375 |
return apply_filters( 'password_reset_key_expired', $return, $user_id ); |
|
2376 |
} |
|
2377 |
||
9 | 2378 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
0 | 2379 |
} |
2380 |
||
2381 |
/** |
|
2382 |
* Handles resetting the user's password. |
|
2383 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2384 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2385 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
* @param WP_User $user The user |
0 | 2387 |
* @param string $new_pass New password for the user in plaintext |
2388 |
*/ |
|
2389 |
function reset_password( $user, $new_pass ) { |
|
5 | 2390 |
/** |
2391 |
* Fires before the user's password is reset. |
|
2392 |
* |
|
2393 |
* @since 1.5.0 |
|
2394 |
* |
|
2395 |
* @param object $user The user. |
|
2396 |
* @param string $new_pass New user password. |
|
2397 |
*/ |
|
0 | 2398 |
do_action( 'password_reset', $user, $new_pass ); |
2399 |
||
2400 |
wp_set_password( $new_pass, $user->ID ); |
|
2401 |
update_user_option( $user->ID, 'default_password_nag', false, true ); |
|
2402 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2403 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2404 |
* Fires after the user's password is reset. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2406 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2408 |
* @param WP_User $user The user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2409 |
* @param string $new_pass New user password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2410 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2411 |
do_action( 'after_password_reset', $user, $new_pass ); |
0 | 2412 |
} |
2413 |
||
2414 |
/** |
|
2415 |
* Handles registering a new user. |
|
2416 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* |
0 | 2419 |
* @param string $user_login User's username for logging in |
2420 |
* @param string $user_email User's email address to send password and add |
|
2421 |
* @return int|WP_Error Either user's ID or error on failure. |
|
2422 |
*/ |
|
2423 |
function register_new_user( $user_login, $user_email ) { |
|
2424 |
$errors = new WP_Error(); |
|
2425 |
||
2426 |
$sanitized_user_login = sanitize_user( $user_login ); |
|
5 | 2427 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2428 |
* Filters the email address of a user being registered. |
5 | 2429 |
* |
2430 |
* @since 2.1.0 |
|
2431 |
* |
|
2432 |
* @param string $user_email The email address of the new user. |
|
2433 |
*/ |
|
0 | 2434 |
$user_email = apply_filters( 'user_registration_email', $user_email ); |
2435 |
||
2436 |
// Check the username |
|
2437 |
if ( $sanitized_user_login == '' ) { |
|
2438 |
$errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); |
|
2439 |
} elseif ( ! validate_username( $user_login ) ) { |
|
2440 |
$errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
|
2441 |
$sanitized_user_login = ''; |
|
2442 |
} elseif ( username_exists( $sanitized_user_login ) ) { |
|
2443 |
$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
|
2444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2445 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2446 |
/** This filter is documented in wp-includes/user.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
$illegal_user_logins = array_map( 'strtolower', (array) apply_filters( 'illegal_user_logins', array() ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2448 |
if ( in_array( strtolower( $sanitized_user_login ), $illegal_user_logins ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2449 |
$errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2450 |
} |
0 | 2451 |
} |
2452 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2453 |
// Check the email address |
0 | 2454 |
if ( $user_email == '' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2455 |
$errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) ); |
0 | 2456 |
} elseif ( ! is_email( $user_email ) ) { |
2457 |
$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); |
|
2458 |
$user_email = ''; |
|
2459 |
} elseif ( email_exists( $user_email ) ) { |
|
2460 |
$errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); |
|
2461 |
} |
|
2462 |
||
5 | 2463 |
/** |
2464 |
* Fires when submitting registration form data, before the user is created. |
|
2465 |
* |
|
2466 |
* @since 2.1.0 |
|
2467 |
* |
|
2468 |
* @param string $sanitized_user_login The submitted username after being sanitized. |
|
2469 |
* @param string $user_email The submitted email. |
|
2470 |
* @param WP_Error $errors Contains any errors with submitted username and email, |
|
2471 |
* e.g., an empty field, an invalid username or email, |
|
2472 |
* or an existing username or email. |
|
2473 |
*/ |
|
0 | 2474 |
do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); |
2475 |
||
5 | 2476 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
* Filters the errors encountered when a new user is being registered. |
5 | 2478 |
* |
2479 |
* The filtered WP_Error object may, for example, contain errors for an invalid |
|
2480 |
* or existing username or email address. A WP_Error object should always returned, |
|
2481 |
* but may or may not contain errors. |
|
2482 |
* |
|
2483 |
* If any errors are present in $errors, this will abort the user's registration. |
|
2484 |
* |
|
2485 |
* @since 2.1.0 |
|
2486 |
* |
|
2487 |
* @param WP_Error $errors A WP_Error object containing any errors encountered |
|
2488 |
* during registration. |
|
2489 |
* @param string $sanitized_user_login User's username after it has been sanitized. |
|
2490 |
* @param string $user_email User's email. |
|
2491 |
*/ |
|
0 | 2492 |
$errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
2493 |
||
9 | 2494 |
if ( $errors->has_errors() ) { |
0 | 2495 |
return $errors; |
9 | 2496 |
} |
0 | 2497 |
|
2498 |
$user_pass = wp_generate_password( 12, false ); |
|
9 | 2499 |
$user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
0 | 2500 |
if ( ! $user_id || is_wp_error( $user_id ) ) { |
2501 |
$errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); |
|
2502 |
return $errors; |
|
2503 |
} |
|
2504 |
||
2505 |
update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. |
|
2506 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2507 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2508 |
* Fires after a new user registration has been recorded. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2509 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2510 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2511 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2512 |
* @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
|
2513 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2514 |
do_action( 'register_new_user', $user_id ); |
0 | 2515 |
|
2516 |
return $user_id; |
|
2517 |
} |
|
5 | 2518 |
|
2519 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2520 |
* 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
|
2521 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2522 |
* 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
|
2523 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2524 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2525 |
* @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
|
2526 |
* notifications only to the user created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
* @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
|
2529 |
* @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
|
2530 |
* 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
|
2531 |
* Default 'both'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2532 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2533 |
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
|
2534 |
wp_new_user_notification( $user_id, null, $notify ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2535 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2536 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2537 |
/** |
5 | 2538 |
* Retrieve the current session token from the logged_in cookie. |
2539 |
* |
|
2540 |
* @since 4.0.0 |
|
2541 |
* |
|
2542 |
* @return string Token. |
|
2543 |
*/ |
|
2544 |
function wp_get_session_token() { |
|
2545 |
$cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
2546 |
return ! empty( $cookie['token'] ) ? $cookie['token'] : ''; |
|
2547 |
} |
|
2548 |
||
2549 |
/** |
|
2550 |
* Retrieve a list of sessions for the current user. |
|
2551 |
* |
|
2552 |
* @since 4.0.0 |
|
2553 |
* @return array Array of sessions. |
|
2554 |
*/ |
|
2555 |
function wp_get_all_sessions() { |
|
2556 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2557 |
return $manager->get_all(); |
|
2558 |
} |
|
2559 |
||
2560 |
/** |
|
2561 |
* Remove the current session token from the database. |
|
2562 |
* |
|
2563 |
* @since 4.0.0 |
|
2564 |
*/ |
|
2565 |
function wp_destroy_current_session() { |
|
2566 |
$token = wp_get_session_token(); |
|
2567 |
if ( $token ) { |
|
2568 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2569 |
$manager->destroy( $token ); |
|
2570 |
} |
|
2571 |
} |
|
2572 |
||
2573 |
/** |
|
2574 |
* Remove all but the current session token for the current user for the database. |
|
2575 |
* |
|
2576 |
* @since 4.0.0 |
|
2577 |
*/ |
|
2578 |
function wp_destroy_other_sessions() { |
|
2579 |
$token = wp_get_session_token(); |
|
2580 |
if ( $token ) { |
|
2581 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2582 |
$manager->destroy_others( $token ); |
|
2583 |
} |
|
2584 |
} |
|
2585 |
||
2586 |
/** |
|
2587 |
* Remove all session tokens for the current user from the database. |
|
2588 |
* |
|
2589 |
* @since 4.0.0 |
|
2590 |
*/ |
|
2591 |
function wp_destroy_all_sessions() { |
|
2592 |
$manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2593 |
$manager->destroy_all(); |
|
2594 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2597 |
* Get the user IDs of all users with no role on this site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2598 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
* @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
|
2601 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
* @return array Array of user IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2604 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
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
|
2606 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2607 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2608 |
if ( ! $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2609 |
$site_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2610 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2611 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2612 |
$prefix = $wpdb->get_blog_prefix( $site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2613 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2614 |
if ( is_multisite() && $site_id != get_current_blog_id() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
switch_to_blog( $site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2616 |
$role_names = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2617 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2618 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2619 |
$role_names = wp_roles()->get_names(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2620 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2621 |
|
9 | 2622 |
$regex = implode( '|', array_keys( $role_names ) ); |
2623 |
$regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); |
|
2624 |
$users = $wpdb->get_col( |
|
2625 |
$wpdb->prepare( |
|
2626 |
" |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2627 |
SELECT user_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2628 |
FROM $wpdb->usermeta |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2629 |
WHERE meta_key = '{$prefix}capabilities' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2630 |
AND meta_value NOT REGEXP %s |
9 | 2631 |
", |
2632 |
$regex |
|
2633 |
) |
|
2634 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2635 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2636 |
return $users; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2637 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2638 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2639 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2640 |
* Retrieves the current user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2641 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2642 |
* 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
|
2643 |
* 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
|
2644 |
* 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
|
2645 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
* 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
|
2647 |
* 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
|
2648 |
* compatibility. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2649 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2650 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2651 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2652 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2653 |
* @see wp_get_current_user() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2654 |
* @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
|
2655 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2656 |
* @return WP_User Current WP_User instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2657 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2658 |
function _wp_get_current_user() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2659 |
global $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2660 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2661 |
if ( ! empty( $current_user ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2662 |
if ( $current_user instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2663 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2664 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2665 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2666 |
// Upgrade stdClass to WP_User |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2667 |
if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
9 | 2668 |
$cur_id = $current_user->ID; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2669 |
$current_user = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2670 |
wp_set_current_user( $cur_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2671 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2672 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2674 |
// $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
|
2675 |
$current_user = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2676 |
wp_set_current_user( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
return $current_user; |
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 |
|
9 | 2680 |
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2681 |
wp_set_current_user( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2683 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2686 |
* Filters the current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2687 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2688 |
* 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
|
2689 |
* request's cookies, if available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2690 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2691 |
* 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
|
2692 |
* the current user. |
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 |
* @since 3.9.0 |
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 |
* @param int|bool $user_id User ID if one has been determined, false otherwise. |
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 |
$user_id = apply_filters( 'determine_current_user', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2699 |
if ( ! $user_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
wp_set_current_user( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
} |
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 |
wp_set_current_user( $user_id ); |
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 |
return $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2707 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2708 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2710 |
* Send a confirmation request email when a change of user email address is attempted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2711 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2712 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2713 |
* @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
|
2714 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2715 |
* @global WP_Error $errors WP_Error object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2716 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2717 |
function send_confirmation_on_profile_email() { |
9 | 2718 |
global $errors; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2719 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2720 |
$current_user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2721 |
if ( ! is_object( $errors ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2722 |
$errors = new WP_Error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2723 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2724 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2725 |
if ( $current_user->ID != $_POST['user_id'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2726 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2727 |
} |
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 |
if ( $current_user->user_email != $_POST['email'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
if ( ! is_email( $_POST['email'] ) ) { |
9 | 2731 |
$errors->add( |
2732 |
'user_email', |
|
2733 |
__( '<strong>ERROR</strong>: The email address isn’t correct.' ), |
|
2734 |
array( |
|
2735 |
'form-field' => 'email', |
|
2736 |
) |
|
2737 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2739 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2740 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2741 |
|
9 | 2742 |
if ( email_exists( $_POST['email'] ) ) { |
2743 |
$errors->add( |
|
2744 |
'user_email', |
|
2745 |
__( '<strong>ERROR</strong>: The email address is already used.' ), |
|
2746 |
array( |
|
2747 |
'form-field' => 'email', |
|
2748 |
) |
|
2749 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2750 |
delete_user_meta( $current_user->ID, '_new_email' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2752 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2753 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2754 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2755 |
$hash = md5( $_POST['email'] . time() . wp_rand() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2756 |
$new_user_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2757 |
'hash' => $hash, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2758 |
'newemail' => $_POST['email'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2759 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2760 |
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
|
2761 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2762 |
$sitename = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2763 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2764 |
/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 2765 |
$email_text = __( |
2766 |
'Howdy ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2767 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2768 |
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
|
2769 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2770 |
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
|
2771 |
###ADMIN_URL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2772 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2773 |
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
|
2774 |
take this action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2775 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2776 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2777 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2779 |
All at ###SITENAME### |
9 | 2780 |
###SITEURL###' |
2781 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2782 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2783 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2784 |
* 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
|
2785 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
* 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
|
2787 |
* ###USERNAME### The current user's username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
* ###ADMIN_URL### The link to click on to confirm the email change. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2789 |
* ###EMAIL### The new email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2790 |
* ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2791 |
* ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2792 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2793 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2794 |
* @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
|
2795 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2796 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2797 |
* @param array $new_user_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2798 |
* Data relating to the new user email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2799 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2800 |
* @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
|
2801 |
* @type string $newemail The proposed new email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2802 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2803 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2804 |
$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
|
2805 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2806 |
$content = str_replace( '###USERNAME###', $current_user->user_login, $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2807 |
$content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail=' . $hash ) ), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2808 |
$content = str_replace( '###EMAIL###', $_POST['email'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2809 |
$content = str_replace( '###SITENAME###', $sitename, $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
$content = str_replace( '###SITEURL###', home_url(), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
|
9 | 2812 |
/* translators: New email address notification email subject. %s: Site name */ |
2813 |
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
|
2814 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2815 |
$_POST['email'] = $current_user->user_email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2816 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2817 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2819 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2820 |
* 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
|
2821 |
* after email address change. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2823 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2824 |
* @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
|
2825 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2826 |
* @global string $pagenow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2827 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2828 |
function new_user_email_admin_notice() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2829 |
global $pagenow; |
9 | 2830 |
|
2831 |
if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) ) { |
|
2832 |
$email = get_user_meta( get_current_user_id(), '_new_email', true ); |
|
2833 |
if ( $email ) { |
|
2834 |
/* translators: %s: New email address */ |
|
2835 |
echo '<div class="notice notice-info"><p>' . sprintf( __( 'Your email address has not been updated yet. Please check your inbox at %s for a confirmation email.' ), '<code>' . esc_html( $email['newemail'] ) . '</code>' ) . '</p></div>'; |
|
2836 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2837 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2839 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2841 |
* Get all user privacy request types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2842 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2845 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
* @return array List of core privacy action types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2848 |
function _wp_privacy_action_request_types() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2849 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2850 |
'export_personal_data', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
'remove_personal_data', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2856 |
* Registers the personal data exporter for users. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2860 |
* @param array $exporters An array of personal data exporters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2861 |
* @return array An array of personal data exporters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2862 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
function wp_register_user_personal_data_exporter( $exporters ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2864 |
$exporters['wordpress-user'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2865 |
'exporter_friendly_name' => __( 'WordPress User' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
'callback' => 'wp_user_personal_data_exporter', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2867 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2868 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2869 |
return $exporters; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2870 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2871 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2872 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2873 |
* 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
|
2874 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2875 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2876 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
* @param string $email_address The users email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2878 |
* @return array An array of personal data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2879 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2880 |
function wp_user_personal_data_exporter( $email_address ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2881 |
$email_address = trim( $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2882 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2883 |
$data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2884 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2885 |
$user = get_user_by( 'email', $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2886 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2887 |
if ( ! $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2888 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2889 |
'data' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2890 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2891 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2892 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2893 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2894 |
$user_meta = get_user_meta( $user->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2895 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2896 |
$user_prop_to_export = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2897 |
'ID' => __( 'User ID' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2898 |
'user_login' => __( 'User Login Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2899 |
'user_nicename' => __( 'User Nice Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2900 |
'user_email' => __( 'User Email' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2901 |
'user_url' => __( 'User URL' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2902 |
'user_registered' => __( 'User Registration Date' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2903 |
'display_name' => __( 'User Display Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2904 |
'nickname' => __( 'User Nickname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2905 |
'first_name' => __( 'User First Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2906 |
'last_name' => __( 'User Last Name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2907 |
'description' => __( 'User Description' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2909 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2910 |
$user_data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2911 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2912 |
foreach ( $user_prop_to_export as $key => $name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2913 |
$value = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
switch ( $key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
case 'ID': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
case 'user_login': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2918 |
case 'user_nicename': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2919 |
case 'user_email': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
case 'user_url': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
case 'user_registered': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
case 'display_name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
$value = $user->data->$key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
case 'nickname': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
case 'first_name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2927 |
case 'last_name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2928 |
case 'description': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2929 |
$value = $user_meta[ $key ][0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2930 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2931 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2933 |
if ( ! empty( $value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2934 |
$user_data_to_export[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2935 |
'name' => $name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2936 |
'value' => $value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2937 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2938 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2939 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2940 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2941 |
$data_to_export[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2942 |
'group_id' => 'user', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2943 |
'group_label' => __( 'User' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2944 |
'item_id' => "user-{$user->ID}", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2945 |
'data' => $user_data_to_export, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2946 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2948 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2949 |
'data' => $data_to_export, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2950 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2951 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2952 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2953 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2954 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2955 |
* Update log when privacy request is confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2956 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2957 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2958 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2959 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2960 |
* @param int $request_id ID of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2961 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2962 |
function _wp_privacy_account_request_confirmed( $request_id ) { |
9 | 2963 |
$request = wp_get_user_request_data( $request_id ); |
2964 |
||
2965 |
if ( ! $request ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2966 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2967 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2968 |
|
9 | 2969 |
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
|
2970 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2973 |
update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() ); |
9 | 2974 |
wp_update_post( |
2975 |
array( |
|
2976 |
'ID' => $request_id, |
|
2977 |
'post_status' => 'request-confirmed', |
|
2978 |
) |
|
2979 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2980 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
* Notify the site administrator via email when a request is confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2985 |
* 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
|
2986 |
* action was needed on their part yet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2987 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2988 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2989 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2990 |
* @param int $request_id The ID of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2991 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2992 |
function _wp_privacy_send_request_confirmation_notification( $request_id ) { |
9 | 2993 |
$request = wp_get_user_request_data( $request_id ); |
2994 |
||
2995 |
if ( ! is_a( $request, 'WP_User_Request' ) || 'request-confirmed' !== $request->status ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2996 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2997 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2998 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2999 |
$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
|
3000 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3001 |
if ( $already_notified ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
|
9 | 3005 |
$manage_url = add_query_arg( 'page', $request->action_name, admin_url( 'tools.php' ) ); |
3006 |
$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
|
3007 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3008 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3009 |
* Filters the recipient of the data request confirmation notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3011 |
* 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
|
3012 |
* 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
|
3013 |
* 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
|
3014 |
* 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
|
3015 |
* responsible for managing privacy requests. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
* |
9 | 3019 |
* @param string $admin_email The email address of the notification recipient. |
3020 |
* @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
|
3021 |
*/ |
9 | 3022 |
$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
|
3023 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3024 |
$email_data = array( |
9 | 3025 |
'request' => $request, |
3026 |
'user_email' => $request->email, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3027 |
'description' => $action_description, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3028 |
'manage_url' => $manage_url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3029 |
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
'siteurl' => home_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
'admin_email' => $admin_email, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3032 |
); |
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 |
/* translators: Do not translate SITENAME, USER_EMAIL, DESCRIPTION, MANAGE_URL, SITEURL; those are placeholders. */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3035 |
$email_text = __( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
'Howdy, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3037 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
A user data privacy request has been confirmed on ###SITENAME###: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3039 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3040 |
User: ###USER_EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3041 |
Request: ###DESCRIPTION### |
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 |
You can view and manage these data privacy requests here: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3044 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3045 |
###MANAGE_URL### |
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 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3048 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3049 |
###SITEURL###' |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3053 |
* Filters the body of the user request confirmation email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3054 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3055 |
* The email is sent to an administrator when an user request is confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3056 |
* 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
|
3057 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3058 |
* ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3059 |
* ###USER_EMAIL### The user email for the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3060 |
* ###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
|
3061 |
* ###MANAGE_URL### The URL to manage requests. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3062 |
* ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3063 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3064 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3065 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3066 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3068 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3069 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
* @type string $user_email The email address confirming a request |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
* @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
|
3073 |
* @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
|
3074 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3075 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
* @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
|
3077 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3078 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
$content = apply_filters( 'user_confirmed_action_email_content', $email_text, $email_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
$content = str_replace( '###SITENAME###', $email_data['sitename'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3082 |
$content = str_replace( '###USER_EMAIL###', $email_data['user_email'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
$content = str_replace( '###DESCRIPTION###', $email_data['description'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
$content = str_replace( '###MANAGE_URL###', esc_url_raw( $email_data['manage_url'] ), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
$content = str_replace( '###SITEURL###', esc_url_raw( $email_data['siteurl'] ), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
$subject = sprintf( |
9 | 3088 |
/* 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
|
3089 |
__( '[%1$s] Action Confirmed: %2$s' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
$email_data['sitename'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
$action_description |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3092 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3093 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3094 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3095 |
* Filters the subject of the user request confirmation email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3096 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3097 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3098 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3099 |
* @param string $subject The email subject. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3100 |
* @param string $sitename The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3101 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3102 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3105 |
* @type string $user_email The email address confirming a request |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3106 |
* @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
|
3107 |
* @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
|
3108 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3109 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
* @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
|
3111 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3112 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3113 |
$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
|
3114 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
$email_sent = wp_mail( $email_data['admin_email'], $subject, $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
if ( $email_sent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3118 |
update_post_meta( $request_id, '_wp_admin_notified', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
|
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 |
* Notify the user when their erasure request is fulfilled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3125 |
* 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
|
3126 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3128 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3129 |
* @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
|
3130 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) { |
9 | 3132 |
$request = wp_get_user_request_data( $request_id ); |
3133 |
||
3134 |
if ( ! is_a( $request, 'WP_User_Request' ) || 'request-completed' !== $request->status ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3135 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3137 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
$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
|
3139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3140 |
if ( $already_notified ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
|
9 | 3144 |
// Localize message content for user; fallback to site default for visitors. |
3145 |
if ( ! empty( $request->user_id ) ) { |
|
3146 |
$locale = get_user_locale( $request->user_id ); |
|
3147 |
} else { |
|
3148 |
$locale = get_locale(); |
|
3149 |
} |
|
3150 |
||
3151 |
$switched_locale = switch_to_locale( $locale ); |
|
3152 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
* Filters the recipient of the data erasure fulfillment notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3156 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3157 |
* |
9 | 3158 |
* @param string $user_email The email address of the notification recipient. |
3159 |
* @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
|
3160 |
*/ |
9 | 3161 |
$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
|
3162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3163 |
$email_data = array( |
9 | 3164 |
'request' => $request, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3165 |
'message_recipient' => $user_email, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3166 |
'privacy_policy_url' => get_privacy_policy_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3167 |
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3168 |
'siteurl' => home_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3169 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3170 |
|
9 | 3171 |
$subject = sprintf( |
3172 |
/* translators: Erasure request fulfilled notification email subject. %s: Site name. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3173 |
__( '[%s] Erasure Request Fulfilled' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3174 |
$email_data['sitename'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3175 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3176 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3177 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3178 |
* 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
|
3179 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3180 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3181 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3182 |
* @param string $subject The email subject. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3183 |
* @param string $sitename The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3185 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3187 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3188 |
* @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
|
3189 |
* 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
|
3190 |
* by the `user_erasure_fulfillment_email_to` filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
* @type string $privacy_policy_url Privacy policy URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
$subject = apply_filters( 'user_erasure_complete_email_subject', $subject, $email_data['sitename'], $email_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
if ( empty( $email_data['privacy_policy_url'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
/* translators: Do not translate SITENAME, SITEURL; those are placeholders. */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
$email_text = __( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
'Howdy, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3202 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
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
|
3204 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
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
|
3206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3208 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3209 |
###SITEURL###' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3210 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3211 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
/* translators: Do not translate SITENAME, SITEURL, PRIVACY_POLICY_URL; those are placeholders. */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3213 |
$email_text = __( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3214 |
'Howdy, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3215 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3216 |
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
|
3217 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3218 |
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
|
3219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3220 |
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
|
3221 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3222 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3223 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3224 |
###SITEURL###' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3225 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3226 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3227 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3228 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3229 |
* Filters the body of the data erasure fulfillment notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3230 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3231 |
* The email is sent to a user when a their data erasure request is fulfilled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3232 |
* by an administrator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3233 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3234 |
* 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
|
3235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3236 |
* ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3237 |
* ###PRIVACY_POLICY_URL### Privacy policy page URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3238 |
* ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3241 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3244 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3246 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
* @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
|
3248 |
* 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
|
3249 |
* by the `user_erasure_fulfillment_email_to` filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
* @type string $privacy_policy_url Privacy policy URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
$content = apply_filters( 'user_confirmed_action_email_content', $email_text, $email_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
$content = str_replace( '###SITENAME###', $email_data['sitename'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
$content = str_replace( '###PRIVACY_POLICY_URL###', $email_data['privacy_policy_url'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
$content = str_replace( '###SITEURL###', esc_url_raw( $email_data['siteurl'] ), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3261 |
$email_sent = wp_mail( $user_email, $subject, $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3262 |
|
9 | 3263 |
if ( $switched_locale ) { |
3264 |
restore_previous_locale(); |
|
3265 |
} |
|
3266 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3267 |
if ( $email_sent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3268 |
update_post_meta( $request_id, '_wp_user_notified', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3269 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3270 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3271 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
* Return request confirmation message HTML. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3274 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
* @param int $request_id The request ID being confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3279 |
* @return string $message The confirmation message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3280 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3281 |
function _wp_privacy_account_request_confirmed_message( $request_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3282 |
$request = wp_get_user_request_data( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3283 |
|
9 | 3284 |
$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
|
3285 |
$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
|
3286 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
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
|
3288 |
if ( 'export_personal_data' === $request->action_name ) { |
9 | 3289 |
$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
|
3290 |
$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
|
3291 |
} elseif ( 'remove_personal_data' === $request->action_name ) { |
9 | 3292 |
$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
|
3293 |
$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
|
3294 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3296 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3297 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
* 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
|
3299 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3300 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3301 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3302 |
* @param string $message The message to the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3303 |
* @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
|
3304 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
$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
|
3306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3307 |
return $message; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3308 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3309 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3311 |
* Create and log a user request to perform a specific action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3312 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
* 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
|
3314 |
* 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
|
3315 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3317 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3318 |
* @param string $email_address User email address. This can be the address of a registered or non-registered user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3319 |
* @param string $action_name Name of the action that is being confirmed. Required. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3320 |
* @param array $request_data Misc data you want to send with the verification request and pass to the actions once the request is confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3321 |
* @return int|WP_Error Returns the request ID if successful, or a WP_Error object on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3322 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3323 |
function wp_create_user_request( $email_address = '', $action_name = '', $request_data = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3324 |
$email_address = sanitize_email( $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
$action_name = sanitize_key( $action_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3326 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
if ( ! is_email( $email_address ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3328 |
return new WP_Error( 'invalid_email', __( 'Invalid email address.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3330 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3331 |
if ( ! $action_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3332 |
return new WP_Error( 'invalid_action', __( 'Invalid action name.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3333 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3335 |
$user = get_user_by( 'email', $email_address ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3336 |
$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
|
3337 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
// Check for duplicates. |
9 | 3339 |
$requests_query = new WP_Query( |
3340 |
array( |
|
3341 |
'post_type' => 'user_request', |
|
3342 |
'post_name__in' => array( $action_name ), // Action name stored in post_name column. |
|
3343 |
'title' => $email_address, // Email address stored in post_title column. |
|
3344 |
'post_status' => array( |
|
3345 |
'request-pending', |
|
3346 |
'request-confirmed', |
|
3347 |
), |
|
3348 |
'fields' => 'ids', |
|
3349 |
) |
|
3350 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3351 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
if ( $requests_query->found_posts ) { |
9 | 3353 |
return new WP_Error( 'duplicate_request', __( 'An incomplete request for this email address already exists.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3355 |
|
9 | 3356 |
$request_id = wp_insert_post( |
3357 |
array( |
|
3358 |
'post_author' => $user_id, |
|
3359 |
'post_name' => $action_name, |
|
3360 |
'post_title' => $email_address, |
|
3361 |
'post_content' => wp_json_encode( $request_data ), |
|
3362 |
'post_status' => 'request-pending', |
|
3363 |
'post_type' => 'user_request', |
|
3364 |
'post_date' => current_time( 'mysql', false ), |
|
3365 |
'post_date_gmt' => current_time( 'mysql', true ), |
|
3366 |
), |
|
3367 |
true |
|
3368 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3369 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
return $request_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3371 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3372 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
* Get action description from the name and return a string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
* @param string $action_name Action name of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
* @return string Human readable action name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
function wp_user_request_action_description( $action_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
switch ( $action_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
case 'export_personal_data': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
$description = __( 'Export Personal Data' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
case 'remove_personal_data': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
$description = __( 'Erase Personal Data' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3390 |
/* translators: %s: action name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3391 |
$description = sprintf( __( 'Confirm the "%s" action' ), $action_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3392 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3393 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
* Filters the user action description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3398 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3399 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
* @param string $description The default description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
* @param string $action_name The name of the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
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
|
3404 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3405 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3406 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
* Send a confirmation request email to confirm an action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3408 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3409 |
* 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
|
3410 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3413 |
* @param string $request_id ID of the request created via wp_create_user_request(). |
9 | 3414 |
* @return bool|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
|
3415 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
function wp_send_user_request( $request_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
$request_id = absint( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3418 |
$request = wp_get_user_request_data( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
if ( ! $request ) { |
9 | 3421 |
return new WP_Error( 'invalid_request', __( 'Invalid user request.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
|
9 | 3424 |
// Localize message content for user; fallback to site default for visitors. |
3425 |
if ( ! empty( $request->user_id ) ) { |
|
3426 |
$locale = get_user_locale( $request->user_id ); |
|
3427 |
} else { |
|
3428 |
$locale = get_locale(); |
|
3429 |
} |
|
3430 |
||
3431 |
$switched_locale = switch_to_locale( $locale ); |
|
3432 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
$email_data = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3434 |
'request' => $request, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
'email' => $request->email, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3436 |
'description' => wp_user_request_action_description( $request->action_name ), |
9 | 3437 |
'confirm_url' => add_query_arg( |
3438 |
array( |
|
3439 |
'action' => 'confirmaction', |
|
3440 |
'request_id' => $request_id, |
|
3441 |
'confirm_key' => wp_generate_user_request_key( $request_id ), |
|
3442 |
), |
|
3443 |
wp_login_url() |
|
3444 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3445 |
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3446 |
'siteurl' => home_url(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3447 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3448 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3449 |
/* translators: Do not translate DESCRIPTION, CONFIRM_URL, SITENAME, SITEURL: those are placeholders. */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3450 |
$email_text = __( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3451 |
'Howdy, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3452 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3453 |
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
|
3454 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3455 |
###DESCRIPTION### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3456 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3457 |
To confirm this, please click on the following link: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3458 |
###CONFIRM_URL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3459 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3460 |
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
|
3461 |
take this action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3463 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3464 |
All at ###SITENAME### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3465 |
###SITEURL###' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3466 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3469 |
* 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
|
3470 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3471 |
* 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
|
3472 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3473 |
* ###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
|
3474 |
* ###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
|
3475 |
* ###SITENAME### The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3476 |
* ###SITEURL### The URL to the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3477 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3478 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3479 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3480 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3481 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3482 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3483 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3484 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3485 |
* @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
|
3486 |
* @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
|
3487 |
* @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
|
3488 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3490 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3491 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3492 |
$content = apply_filters( 'user_request_action_email_content', $email_text, $email_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3493 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
$content = str_replace( '###DESCRIPTION###', $email_data['description'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
$content = str_replace( '###CONFIRM_URL###', esc_url_raw( $email_data['confirm_url'] ), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3496 |
$content = str_replace( '###EMAIL###', $email_data['email'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3497 |
$content = str_replace( '###SITENAME###', $email_data['sitename'], $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3498 |
$content = str_replace( '###SITEURL###', esc_url_raw( $email_data['siteurl'] ), $content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3499 |
|
9 | 3500 |
/* translators: Confirm privacy data request notification email subject. 1: Site title, 2: Name of the action */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3501 |
$subject = sprintf( __( '[%1$s] Confirm Action: %2$s' ), $email_data['sitename'], $email_data['description'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3502 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3503 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3504 |
* Filters the subject 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
|
3505 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3506 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3507 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3508 |
* @param string $subject The email subject. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3509 |
* @param string $sitename The name of the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
* @param array $email_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3511 |
* Data relating to the account action email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
* @type WP_User_Request $request User request object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
* @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
|
3515 |
* @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
|
3516 |
* @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
|
3517 |
* @type string $sitename The site name sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
* @type string $siteurl The site URL sending the mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
$subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
|
9 | 3523 |
$email_sent = wp_mail( $email_data['email'], $subject, $content ); |
3524 |
||
3525 |
if ( $switched_locale ) { |
|
3526 |
restore_previous_locale(); |
|
3527 |
} |
|
3528 |
||
3529 |
if ( ! $email_sent ) { |
|
3530 |
return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export confirmation email.' ) ); |
|
3531 |
} |
|
3532 |
||
3533 |
return true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3534 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3535 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3536 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3537 |
* 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
|
3538 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3539 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
* @param int $request_id Request ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
* @return string Confirmation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
function wp_generate_user_request_key( $request_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3545 |
global $wp_hasher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
// Generate something random for a confirmation key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
$key = wp_generate_password( 20, false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3549 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3550 |
// Return the key, hashed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3551 |
if ( empty( $wp_hasher ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3552 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3553 |
$wp_hasher = new PasswordHash( 8, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
|
9 | 3556 |
wp_update_post( |
3557 |
array( |
|
3558 |
'ID' => $request_id, |
|
3559 |
'post_status' => 'request-pending', |
|
3560 |
'post_password' => $wp_hasher->HashPassword( $key ), |
|
3561 |
) |
|
3562 |
); |
|
7
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 |
return $key; |
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 |
|
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 |
* Validate a user request by comparing the key with the request's key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
* @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
|
3573 |
* @param string $key Provided key to validate. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3574 |
* @return bool|WP_Error WP_Error on failure, true on success. |
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 |
function wp_validate_user_request_key( $request_id, $key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
global $wp_hasher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
$request_id = absint( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
$request = wp_get_user_request_data( $request_id ); |
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 |
if ( ! $request ) { |
9 | 3583 |
return new WP_Error( 'invalid_request', __( 'Invalid request.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
if ( ! in_array( $request->status, array( 'request-pending', 'request-failed' ), true ) ) { |
9 | 3587 |
return new WP_Error( 'expired_link', __( 'This link has expired.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
} |
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 |
if ( empty( $key ) ) { |
9 | 3591 |
return new WP_Error( 'missing_key', __( 'Missing confirm key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3593 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
if ( empty( $wp_hasher ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3596 |
$wp_hasher = new PasswordHash( 8, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3599 |
$key_request_time = $request->modified_timestamp; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3600 |
$saved_key = $request->confirm_key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3601 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3602 |
if ( ! $saved_key ) { |
9 | 3603 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
if ( ! $key_request_time ) { |
9 | 3607 |
return new WP_Error( 'invalid_key', __( 'Invalid action.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3611 |
* Filters the expiration time of confirm keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3613 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3614 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
* @param int $expiration The expiration time in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3616 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3617 |
$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
|
3618 |
$expiration_time = $key_request_time + $expiration_duration; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3619 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3620 |
if ( ! $wp_hasher->CheckPassword( $key, $saved_key ) ) { |
9 | 3621 |
return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3622 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3623 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3624 |
if ( ! $expiration_time || time() > $expiration_time ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3625 |
return new WP_Error( 'expired_key', __( 'The confirmation email has expired.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3626 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3627 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3629 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3631 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
* Return data about a user request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3633 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3634 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3635 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3636 |
* @param int $request_id Request ID to get data about. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
* @return WP_User_Request|false |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3639 |
function wp_get_user_request_data( $request_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3640 |
$request_id = absint( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3641 |
$post = get_post( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3642 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3643 |
if ( ! $post || 'user_request' !== $post->post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3644 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3646 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
return new WP_User_Request( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3649 |
|
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 |
* WP_User_Request class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
* Represents user request data loaded from a WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3656 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
final class WP_User_Request { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3658 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
* Request ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
* @var int |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
public $ID = 0; |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3666 |
* User 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 |
* @var int |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3669 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
public $user_id = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
* User email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
* @var int |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
public $email = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3679 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
* Action name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3681 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3682 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3683 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3684 |
public $action_name = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3685 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3686 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
* Current status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3689 |
* @var string |
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 |
public $status = ''; |
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 |
* Timestamp this request was created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
* @var int|null |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3698 |
public $created_timestamp = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
|
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 |
* Timestamp this request was last modified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
* @var int|null |
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 |
public $modified_timestamp = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
|
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 |
* Timestamp this request was confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
* @var int |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3711 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
public $confirmed_timestamp = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3714 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3715 |
* Timestamp this request was completed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
* @var int |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
public $completed_timestamp = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
* Misc data assigned to this request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
public $request_data = array(); |
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 |
* Key used to confirm this request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3731 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3732 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3733 |
public $confirm_key = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3734 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3735 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3736 |
* Constructor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3737 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
* @since 4.9.6 |
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 |
* @param WP_Post|object $post Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
public function __construct( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
$this->ID = $post->ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
$this->user_id = $post->post_author; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
$this->email = $post->post_title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
$this->action_name = $post->post_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
$this->status = $post->post_status; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
$this->created_timestamp = strtotime( $post->post_date_gmt ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
$this->modified_timestamp = strtotime( $post->post_modified_gmt ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
$this->confirmed_timestamp = (int) get_post_meta( $post->ID, '_wp_user_request_confirmed_timestamp', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
$this->completed_timestamp = (int) get_post_meta( $post->ID, '_wp_user_request_completed_timestamp', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3752 |
$this->request_data = json_decode( $post->post_content, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
$this->confirm_key = $post->post_password; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
} |