author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress user administration API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Creates a new user from the "Users" form using $_POST information. |
|
11 |
* |
|
5 | 12 |
* @since 2.0.0 |
0 | 13 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @return int|WP_Error WP_Error or User ID. |
0 | 15 |
*/ |
16 |
function add_user() { |
|
17 |
return edit_user(); |
|
18 |
} |
|
19 |
||
20 |
/** |
|
21 |
* Edit user settings based on contents of $_POST |
|
22 |
* |
|
23 |
* Used on user-edit.php and profile.php to manage and process user options, passwords etc. |
|
24 |
* |
|
5 | 25 |
* @since 2.0.0 |
0 | 26 |
* |
27 |
* @param int $user_id Optional. User ID. |
|
19 | 28 |
* @return int|WP_Error User ID of the updated user or WP_Error on failure. |
0 | 29 |
*/ |
30 |
function edit_user( $user_id = 0 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
$wp_roles = wp_roles(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
$user = new stdClass(); |
9 | 33 |
$user_id = (int) $user_id; |
0 | 34 |
if ( $user_id ) { |
9 | 35 |
$update = true; |
36 |
$user->ID = $user_id; |
|
37 |
$userdata = get_userdata( $user_id ); |
|
0 | 38 |
$user->user_login = wp_slash( $userdata->user_login ); |
39 |
} else { |
|
40 |
$update = false; |
|
41 |
} |
|
42 |
||
9 | 43 |
if ( ! $update && isset( $_POST['user_login'] ) ) { |
16 | 44 |
$user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true ); |
9 | 45 |
} |
0 | 46 |
|
16 | 47 |
$pass1 = ''; |
48 |
$pass2 = ''; |
|
9 | 49 |
if ( isset( $_POST['pass1'] ) ) { |
18 | 50 |
$pass1 = trim( $_POST['pass1'] ); |
9 | 51 |
} |
52 |
if ( isset( $_POST['pass2'] ) ) { |
|
18 | 53 |
$pass2 = trim( $_POST['pass2'] ); |
0 | 54 |
} |
55 |
||
9 | 56 |
if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) { |
57 |
$new_role = sanitize_text_field( $_POST['role'] ); |
|
58 |
||
59 |
// If the new role isn't editable by the logged-in user die with error. |
|
60 |
$editable_roles = get_editable_roles(); |
|
61 |
if ( ! empty( $new_role ) && empty( $editable_roles[ $new_role ] ) ) { |
|
62 |
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 ); |
|
63 |
} |
|
64 |
||
65 |
$potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false; |
|
66 |
||
67 |
/* |
|
68 |
* Don't let anyone with 'promote_users' edit their own role to something without it. |
|
69 |
* Multisite super admins can freely edit their roles, they possess all caps. |
|
70 |
*/ |
|
71 |
if ( |
|
72 |
( is_multisite() && current_user_can( 'manage_network_users' ) ) || |
|
16 | 73 |
get_current_user_id() !== $user_id || |
9 | 74 |
( $potential_role && $potential_role->has_cap( 'promote_users' ) ) |
75 |
) { |
|
76 |
$user->role = $new_role; |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
if ( isset( $_POST['email'] ) ) { |
|
5 | 81 |
$user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) ); |
9 | 82 |
} |
0 | 83 |
if ( isset( $_POST['url'] ) ) { |
16 | 84 |
if ( empty( $_POST['url'] ) || 'http://' === $_POST['url'] ) { |
0 | 85 |
$user->user_url = ''; |
86 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
$user->user_url = sanitize_url( $_POST['url'] ); |
9 | 88 |
$protocols = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) ); |
89 |
$user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url; |
|
0 | 90 |
} |
91 |
} |
|
9 | 92 |
if ( isset( $_POST['first_name'] ) ) { |
0 | 93 |
$user->first_name = sanitize_text_field( $_POST['first_name'] ); |
9 | 94 |
} |
95 |
if ( isset( $_POST['last_name'] ) ) { |
|
0 | 96 |
$user->last_name = sanitize_text_field( $_POST['last_name'] ); |
9 | 97 |
} |
98 |
if ( isset( $_POST['nickname'] ) ) { |
|
0 | 99 |
$user->nickname = sanitize_text_field( $_POST['nickname'] ); |
9 | 100 |
} |
101 |
if ( isset( $_POST['display_name'] ) ) { |
|
0 | 102 |
$user->display_name = sanitize_text_field( $_POST['display_name'] ); |
9 | 103 |
} |
0 | 104 |
|
9 | 105 |
if ( isset( $_POST['description'] ) ) { |
0 | 106 |
$user->description = trim( $_POST['description'] ); |
9 | 107 |
} |
0 | 108 |
|
109 |
foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) { |
|
9 | 110 |
if ( isset( $_POST[ $method ] ) ) { |
111 |
$user->$method = sanitize_text_field( $_POST[ $method ] ); |
|
112 |
} |
|
0 | 113 |
} |
114 |
||
16 | 115 |
if ( isset( $_POST['locale'] ) ) { |
116 |
$locale = sanitize_text_field( $_POST['locale'] ); |
|
117 |
if ( 'site-default' === $locale ) { |
|
118 |
$locale = ''; |
|
119 |
} elseif ( '' === $locale ) { |
|
120 |
$locale = 'en_US'; |
|
121 |
} elseif ( ! in_array( $locale, get_available_languages(), true ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
if ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
if ( ! wp_download_language_pack( $locale ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
$locale = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
$locale = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
} |
16 | 129 |
} |
130 |
||
131 |
$user->locale = $locale; |
|
132 |
} |
|
133 |
||
0 | 134 |
if ( $update ) { |
9 | 135 |
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true'; |
136 |
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true'; |
|
137 |
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh'; |
|
0 | 138 |
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false'; |
139 |
} |
|
140 |
||
16 | 141 |
$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' === $_POST['comment_shortcuts'] ? 'true' : ''; |
0 | 142 |
|
143 |
$user->use_ssl = 0; |
|
9 | 144 |
if ( ! empty( $_POST['use_ssl'] ) ) { |
0 | 145 |
$user->use_ssl = 1; |
9 | 146 |
} |
0 | 147 |
|
148 |
$errors = new WP_Error(); |
|
149 |
||
150 |
/* checking that username has been typed */ |
|
16 | 151 |
if ( '' === $user->user_login ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
152 |
$errors->add( 'user_login', __( '<strong>Error:</strong> Please enter a username.' ) ); |
9 | 153 |
} |
0 | 154 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
/* checking that nickname has been typed */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
if ( $update && empty( $user->nickname ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
$errors->add( 'nickname', __( '<strong>Error:</strong> Please enter a nickname.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
|
5 | 160 |
/** |
161 |
* Fires before the password and confirm password fields are checked for congruity. |
|
162 |
* |
|
163 |
* @since 1.5.1 |
|
164 |
* |
|
165 |
* @param string $user_login The username. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* @param string $pass1 The password (passed by reference). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* @param string $pass2 The confirmed password (passed by reference). |
5 | 168 |
*/ |
0 | 169 |
do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) ); |
170 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
// Check for blank password when adding a user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
if ( ! $update && empty( $pass1 ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
$errors->add( 'pass', __( '<strong>Error:</strong> Please enter a password.' ), array( 'form-field' => 'pass1' ) ); |
0 | 174 |
} |
175 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
// Check for "\" in password. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
if ( str_contains( wp_unslash( $pass1 ), '\\' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
$errors->add( 'pass', __( '<strong>Error:</strong> Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
} |
0 | 180 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
// Checking the password has been typed twice the same. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
182 |
if ( ( $update || ! empty( $pass1 ) ) && $pass1 !== $pass2 ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
$errors->add( 'pass', __( '<strong>Error:</strong> Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
} |
0 | 185 |
|
9 | 186 |
if ( ! empty( $pass1 ) ) { |
0 | 187 |
$user->user_pass = $pass1; |
9 | 188 |
} |
0 | 189 |
|
9 | 190 |
if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
191 |
$errors->add( 'user_login', __( '<strong>Error:</strong> This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
9 | 192 |
} |
0 | 193 |
|
9 | 194 |
if ( ! $update && username_exists( $user->user_login ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
195 |
$errors->add( 'user_login', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) ); |
9 | 196 |
} |
0 | 197 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
/** This filter is documented in wp-includes/user.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
|
16 | 201 |
if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
$errors->add( 'invalid_username', __( '<strong>Error:</strong> Sorry, that username is not allowed.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
// Checking email address. |
0 | 206 |
if ( empty( $user->user_email ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
$errors->add( 'empty_email', __( '<strong>Error:</strong> Please enter an email address.' ), array( 'form-field' => 'email' ) ); |
9 | 208 |
} elseif ( ! is_email( $user->user_email ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
209 |
$errors->add( 'invalid_email', __( '<strong>Error:</strong> The email address is not correct.' ), array( 'form-field' => 'email' ) ); |
16 | 210 |
} else { |
211 |
$owner_id = email_exists( $user->user_email ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
212 |
if ( $owner_id && ( ! $update || ( $owner_id !== $user->ID ) ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
213 |
$errors->add( 'email_exists', __( '<strong>Error:</strong> This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) ); |
16 | 214 |
} |
0 | 215 |
} |
216 |
||
5 | 217 |
/** |
218 |
* Fires before user profile update errors are returned. |
|
219 |
* |
|
220 |
* @since 2.8.0 |
|
221 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* @param WP_Error $errors WP_Error object (passed by reference). |
16 | 223 |
* @param bool $update Whether this is a user update. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
* @param stdClass $user User object (passed by reference). |
5 | 225 |
*/ |
0 | 226 |
do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) ); |
227 |
||
9 | 228 |
if ( $errors->has_errors() ) { |
0 | 229 |
return $errors; |
9 | 230 |
} |
0 | 231 |
|
232 |
if ( $update ) { |
|
233 |
$user_id = wp_update_user( $user ); |
|
234 |
} else { |
|
235 |
$user_id = wp_insert_user( $user ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
$notify = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin'; |
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 |
/** |
9 | 239 |
* Fires after a new user has been created. |
240 |
* |
|
241 |
* @since 4.4.0 |
|
242 |
* |
|
19 | 243 |
* @param int|WP_Error $user_id ID of the newly created user or WP_Error on failure. |
244 |
* @param string $notify Type of notification that should happen. See |
|
245 |
* wp_send_new_user_notifications() for more information. |
|
9 | 246 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
do_action( 'edit_user_created_user', $user_id, $notify ); |
0 | 248 |
} |
249 |
return $user_id; |
|
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* Fetch a filtered list of user roles that the current user is |
|
254 |
* allowed to edit. |
|
255 |
* |
|
9 | 256 |
* Simple function whose main purpose is to allow filtering of the |
0 | 257 |
* list of roles in the $wp_roles object so that plugins can remove |
258 |
* inappropriate ones depending on the situation or user making edits. |
|
259 |
* Specifically because without filtering anyone with the edit_users |
|
260 |
* capability can edit others to be administrators, even if they are |
|
261 |
* only editors or authors. This filter allows admins to delegate |
|
262 |
* user management. |
|
263 |
* |
|
5 | 264 |
* @since 2.8.0 |
0 | 265 |
* |
9 | 266 |
* @return array[] Array of arrays containing role information. |
0 | 267 |
*/ |
268 |
function get_editable_roles() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
$all_roles = wp_roles()->roles; |
5 | 270 |
|
271 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* Filters the list of editable roles. |
5 | 273 |
* |
274 |
* @since 2.8.0 |
|
275 |
* |
|
9 | 276 |
* @param array[] $all_roles Array of arrays containing role information. |
5 | 277 |
*/ |
278 |
$editable_roles = apply_filters( 'editable_roles', $all_roles ); |
|
0 | 279 |
|
280 |
return $editable_roles; |
|
281 |
} |
|
282 |
||
283 |
/** |
|
284 |
* Retrieve user data and filter it. |
|
285 |
* |
|
286 |
* @since 2.0.5 |
|
287 |
* |
|
288 |
* @param int $user_id User ID. |
|
18 | 289 |
* @return WP_User|false WP_User object on success, false on failure. |
0 | 290 |
*/ |
291 |
function get_user_to_edit( $user_id ) { |
|
292 |
$user = get_userdata( $user_id ); |
|
293 |
||
9 | 294 |
if ( $user ) { |
0 | 295 |
$user->filter = 'edit'; |
9 | 296 |
} |
0 | 297 |
|
298 |
return $user; |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* Retrieve the user's drafts. |
|
303 |
* |
|
304 |
* @since 2.0.0 |
|
305 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
* |
0 | 308 |
* @param int $user_id User ID. |
309 |
* @return array |
|
310 |
*/ |
|
311 |
function get_users_drafts( $user_id ) { |
|
312 |
global $wpdb; |
|
9 | 313 |
$query = $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id ); |
5 | 314 |
|
315 |
/** |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
316 |
* Filters the SQL query string for the user's drafts query. |
5 | 317 |
* |
318 |
* @since 2.0.0 |
|
319 |
* |
|
320 |
* @param string $query The user's drafts query string. |
|
321 |
*/ |
|
322 |
$query = apply_filters( 'get_users_drafts', $query ); |
|
0 | 323 |
return $wpdb->get_results( $query ); |
324 |
} |
|
325 |
||
326 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
* Delete user and optionally reassign posts and links to another user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
328 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
* Note that on a Multisite installation the user only gets removed from the site |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
* and does not get deleted from the database. |
0 | 331 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
* If the `$reassign` parameter is not assigned to a user ID, then all posts will |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
* be deleted of that user. The action {@see 'delete_user'} that is passed the user ID |
0 | 334 |
* being deleted will be run after the posts are either reassigned or deleted. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
335 |
* The user meta will also be deleted that are for that user ID. |
0 | 336 |
* |
337 |
* @since 2.0.0 |
|
338 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
* @param int $id User ID. |
0 | 342 |
* @param int $reassign Optional. Reassign posts and links to new User ID. |
343 |
* @return bool True when finished. |
|
344 |
*/ |
|
5 | 345 |
function wp_delete_user( $id, $reassign = null ) { |
0 | 346 |
global $wpdb; |
347 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
if ( ! is_numeric( $id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
|
9 | 352 |
$id = (int) $id; |
0 | 353 |
$user = new WP_User( $id ); |
354 |
||
9 | 355 |
if ( ! $user->exists() ) { |
0 | 356 |
return false; |
9 | 357 |
} |
0 | 358 |
|
5 | 359 |
// Normalize $reassign to null or a user ID. 'novalue' was an older default. |
360 |
if ( 'novalue' === $reassign ) { |
|
361 |
$reassign = null; |
|
362 |
} elseif ( null !== $reassign ) { |
|
363 |
$reassign = (int) $reassign; |
|
364 |
} |
|
0 | 365 |
|
5 | 366 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
367 |
* Fires immediately before a user is deleted from the site. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
368 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
* Note that on a Multisite installation the user only gets removed from the site |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
370 |
* and does not get deleted from the database. |
5 | 371 |
* |
372 |
* @since 2.0.0 |
|
16 | 373 |
* @since 5.5.0 Added the `$user` parameter. |
5 | 374 |
* |
375 |
* @param int $id ID of the user to delete. |
|
376 |
* @param int|null $reassign ID of the user to reassign posts and links to. |
|
377 |
* Default null, for no reassignment. |
|
16 | 378 |
* @param WP_User $user WP_User object of the user to delete. |
5 | 379 |
*/ |
16 | 380 |
do_action( 'delete_user', $id, $reassign, $user ); |
5 | 381 |
|
382 |
if ( null === $reassign ) { |
|
0 | 383 |
$post_types_to_delete = array(); |
384 |
foreach ( get_post_types( array(), 'objects' ) as $post_type ) { |
|
385 |
if ( $post_type->delete_with_user ) { |
|
386 |
$post_types_to_delete[] = $post_type->name; |
|
387 |
} elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) { |
|
388 |
$post_types_to_delete[] = $post_type->name; |
|
389 |
} |
|
390 |
} |
|
391 |
||
5 | 392 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* Filters the list of post types to delete with a user. |
5 | 394 |
* |
395 |
* @since 3.4.0 |
|
396 |
* |
|
9 | 397 |
* @param string[] $post_types_to_delete Array of post types to delete. |
398 |
* @param int $id User ID. |
|
5 | 399 |
*/ |
0 | 400 |
$post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id ); |
401 |
$post_types_to_delete = implode( "', '", $post_types_to_delete ); |
|
9 | 402 |
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) ); |
0 | 403 |
if ( $post_ids ) { |
9 | 404 |
foreach ( $post_ids as $post_id ) { |
0 | 405 |
wp_delete_post( $post_id ); |
9 | 406 |
} |
0 | 407 |
} |
408 |
||
16 | 409 |
// Clean links. |
9 | 410 |
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) ); |
0 | 411 |
|
412 |
if ( $link_ids ) { |
|
9 | 413 |
foreach ( $link_ids as $link_id ) { |
414 |
wp_delete_link( $link_id ); |
|
415 |
} |
|
0 | 416 |
} |
417 |
} else { |
|
418 |
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) ); |
|
9 | 419 |
$wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) ); |
0 | 420 |
if ( ! empty( $post_ids ) ) { |
9 | 421 |
foreach ( $post_ids as $post_id ) { |
0 | 422 |
clean_post_cache( $post_id ); |
9 | 423 |
} |
0 | 424 |
} |
9 | 425 |
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) ); |
426 |
$wpdb->update( $wpdb->links, array( 'link_owner' => $reassign ), array( 'link_owner' => $id ) ); |
|
0 | 427 |
if ( ! empty( $link_ids ) ) { |
9 | 428 |
foreach ( $link_ids as $link_id ) { |
0 | 429 |
clean_bookmark_cache( $link_id ); |
9 | 430 |
} |
0 | 431 |
} |
432 |
} |
|
433 |
||
16 | 434 |
// FINALLY, delete user. |
0 | 435 |
if ( is_multisite() ) { |
436 |
remove_user_from_blog( $id, get_current_blog_id() ); |
|
437 |
} else { |
|
438 |
$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); |
|
9 | 439 |
foreach ( $meta as $mid ) { |
0 | 440 |
delete_metadata_by_mid( 'user', $mid ); |
9 | 441 |
} |
0 | 442 |
|
443 |
$wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); |
|
444 |
} |
|
445 |
||
446 |
clean_user_cache( $user ); |
|
447 |
||
5 | 448 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
* Fires immediately after a user is deleted from the site. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
* Note that on a Multisite installation the user may not have been deleted from |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
452 |
* the database depending on whether `wp_delete_user()` or `wpmu_delete_user()` |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
453 |
* was called. |
5 | 454 |
* |
455 |
* @since 2.9.0 |
|
16 | 456 |
* @since 5.5.0 Added the `$user` parameter. |
5 | 457 |
* |
458 |
* @param int $id ID of the deleted user. |
|
459 |
* @param int|null $reassign ID of the user to reassign posts and links to. |
|
460 |
* Default null, for no reassignment. |
|
16 | 461 |
* @param WP_User $user WP_User object of the deleted user. |
5 | 462 |
*/ |
16 | 463 |
do_action( 'deleted_user', $id, $reassign, $user ); |
0 | 464 |
|
465 |
return true; |
|
466 |
} |
|
467 |
||
468 |
/** |
|
469 |
* Remove all capabilities from user. |
|
470 |
* |
|
471 |
* @since 2.1.0 |
|
472 |
* |
|
473 |
* @param int $id User ID. |
|
474 |
*/ |
|
9 | 475 |
function wp_revoke_user( $id ) { |
0 | 476 |
$id = (int) $id; |
477 |
||
9 | 478 |
$user = new WP_User( $id ); |
0 | 479 |
$user->remove_all_caps(); |
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
* @global int $user_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* @param false $errors Deprecated. |
0 | 488 |
*/ |
9 | 489 |
function default_password_nag_handler( $errors = false ) { |
0 | 490 |
global $user_ID; |
5 | 491 |
// Short-circuit it. |
9 | 492 |
if ( ! get_user_option( 'default_password_nag' ) ) { |
0 | 493 |
return; |
9 | 494 |
} |
0 | 495 |
|
16 | 496 |
// get_user_setting() = JS-saved UI setting. Else no-js-fallback code. |
497 |
if ( 'hide' === get_user_setting( 'default_password_nag' ) |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
498 |
|| isset( $_GET['default_password_nag'] ) && '0' === $_GET['default_password_nag'] |
16 | 499 |
) { |
9 | 500 |
delete_user_setting( 'default_password_nag' ); |
18 | 501 |
update_user_meta( $user_ID, 'default_password_nag', false ); |
0 | 502 |
} |
503 |
} |
|
504 |
||
505 |
/** |
|
506 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
* |
18 | 508 |
* @param int $user_ID |
509 |
* @param WP_User $old_data |
|
0 | 510 |
*/ |
9 | 511 |
function default_password_nag_edit_user( $user_ID, $old_data ) { |
5 | 512 |
// Short-circuit it. |
9 | 513 |
if ( ! get_user_option( 'default_password_nag', $user_ID ) ) { |
0 | 514 |
return; |
9 | 515 |
} |
0 | 516 |
|
9 | 517 |
$new_data = get_userdata( $user_ID ); |
0 | 518 |
|
5 | 519 |
// Remove the nag if the password has been changed. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
520 |
if ( $new_data->user_pass !== $old_data->user_pass ) { |
9 | 521 |
delete_user_setting( 'default_password_nag' ); |
18 | 522 |
update_user_meta( $user_ID, 'default_password_nag', false ); |
0 | 523 |
} |
524 |
} |
|
525 |
||
526 |
/** |
|
527 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* |
19 | 529 |
* @global string $pagenow The filename of the current screen. |
0 | 530 |
*/ |
531 |
function default_password_nag() { |
|
532 |
global $pagenow; |
|
19 | 533 |
|
5 | 534 |
// Short-circuit it. |
16 | 535 |
if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) { |
0 | 536 |
return; |
9 | 537 |
} |
0 | 538 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
539 |
$default_password_nag_message = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
540 |
'<p><strong>%1$s</strong> %2$s</p>', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
541 |
__( 'Notice:' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
542 |
__( 'You are using the auto-generated password for your account. Would you like to change it?' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
543 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
544 |
$default_password_nag_message .= sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
545 |
'<p><a href="%1$s">%2$s</a> | ', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
546 |
esc_url( get_edit_profile_url() . '#password' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
547 |
__( 'Yes, take me to my profile page' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
548 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
549 |
$default_password_nag_message .= sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
550 |
'<a href="%1$s" id="default-password-nag-no">%2$s</a></p>', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
551 |
'?default_password_nag=0', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
552 |
__( 'No thanks, do not remind me again' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
553 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
554 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
555 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
556 |
$default_password_nag_message, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
557 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
558 |
'additional_classes' => array( 'error', 'default-password-nag' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
559 |
'paragraph_wrap' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
560 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
561 |
); |
0 | 562 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* @since 3.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
*/ |
9 | 568 |
function delete_users_add_js() { |
569 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
<script> |
19 | 571 |
jQuery( function($) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
var submit = $('#submit').prop('disabled', true); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
$('input[name="delete_option"]').one('change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
submit.prop('disabled', false); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
$('#reassign_user').focus( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
$('#delete_option1').prop('checked', true).trigger('change'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
}); |
19 | 579 |
} ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
</script> |
9 | 581 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
* Optional SSL preference that can be turned on by hooking to the 'personal_options' action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* See the {@see 'personal_options'} action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* |
16 | 591 |
* @param WP_User $user User data object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
*/ |
9 | 593 |
function use_ssl_preference( $user ) { |
594 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
<tr class="user-use-ssl-wrap"> |
9 | 596 |
<th scope="row"><?php _e( 'Use https' ); ?></th> |
597 |
<td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked( '1', $user->use_ssl ); ?> /> <?php _e( 'Always use https when visiting the admin' ); ?></label></td> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
</tr> |
9 | 599 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
/** |
16 | 603 |
* @since MU (3.0.0) |
604 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* @param string $text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* @return string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
function admin_created_user_email( $text ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
$roles = get_editable_roles(); |
9 | 610 |
$role = $roles[ $_REQUEST['role'] ]; |
16 | 611 |
|
19 | 612 |
if ( '' !== get_bloginfo( 'name' ) ) { |
613 |
$site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
614 |
} else { |
|
615 |
$site_title = parse_url( home_url(), PHP_URL_HOST ); |
|
616 |
} |
|
617 |
||
9 | 618 |
return sprintf( |
16 | 619 |
/* translators: 1: Site title, 2: Site URL, 3: User role. */ |
9 | 620 |
__( |
621 |
'Hi, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
You\'ve been invited to join \'%1$s\' at |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
%2$s with the role of %3$s. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
If you do not want to join this site please ignore |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
this email. This invitation will expire in a few days. |
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 |
Please click the following link to activate your user account: |
9 | 628 |
%%s' |
629 |
), |
|
19 | 630 |
$site_title, |
9 | 631 |
home_url(), |
632 |
wp_specialchars_decode( translate_user_role( $role['name'] ) ) |
|
633 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
} |
18 | 635 |
|
636 |
/** |
|
637 |
* Checks if the Authorize Application Password request is valid. |
|
638 |
* |
|
639 |
* @since 5.6.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
640 |
* @since 6.2.0 Allow insecure HTTP connections for the local environment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
641 |
* @since 6.3.2 Validates the success and reject URLs to prevent `javascript` pseudo protocol from being executed. |
18 | 642 |
* |
643 |
* @param array $request { |
|
644 |
* The array of request data. All arguments are optional and may be empty. |
|
645 |
* |
|
646 |
* @type string $app_name The suggested name of the application. |
|
19 | 647 |
* @type string $app_id A UUID provided by the application to uniquely identify it. |
648 |
* @type string $success_url The URL the user will be redirected to after approving the application. |
|
649 |
* @type string $reject_url The URL the user will be redirected to after rejecting the application. |
|
18 | 650 |
* } |
651 |
* @param WP_User $user The user authorizing the application. |
|
652 |
* @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not. |
|
653 |
*/ |
|
654 |
function wp_is_authorize_application_password_request_valid( $request, $user ) { |
|
655 |
$error = new WP_Error(); |
|
656 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
657 |
if ( isset( $request['success_url'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
658 |
$validated_success_url = wp_is_authorize_application_redirect_url_valid( $request['success_url'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
659 |
if ( is_wp_error( $validated_success_url ) ) { |
18 | 660 |
$error->add( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
661 |
$validated_success_url->get_error_code(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
662 |
$validated_success_url->get_error_message() |
18 | 663 |
); |
664 |
} |
|
665 |
} |
|
666 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
667 |
if ( isset( $request['reject_url'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
668 |
$validated_reject_url = wp_is_authorize_application_redirect_url_valid( $request['reject_url'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
669 |
if ( is_wp_error( $validated_reject_url ) ) { |
18 | 670 |
$error->add( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
671 |
$validated_reject_url->get_error_code(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
672 |
$validated_reject_url->get_error_message() |
18 | 673 |
); |
674 |
} |
|
675 |
} |
|
676 |
||
677 |
if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) { |
|
678 |
$error->add( |
|
679 |
'invalid_app_id', |
|
19 | 680 |
__( 'The application ID must be a UUID.' ) |
18 | 681 |
); |
682 |
} |
|
683 |
||
684 |
/** |
|
685 |
* Fires before application password errors are returned. |
|
686 |
* |
|
687 |
* @since 5.6.0 |
|
688 |
* |
|
689 |
* @param WP_Error $error The error object. |
|
690 |
* @param array $request The array of request data. |
|
691 |
* @param WP_User $user The user authorizing the application. |
|
692 |
*/ |
|
693 |
do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user ); |
|
694 |
||
695 |
if ( $error->has_errors() ) { |
|
696 |
return $error; |
|
697 |
} |
|
698 |
||
699 |
return true; |
|
700 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
701 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
702 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
703 |
* Validates the redirect URL protocol scheme. The protocol can be anything except `http` and `javascript`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
704 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
705 |
* @since 6.3.2 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
706 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
707 |
* @param string $url The redirect URL to be validated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
708 |
* @return true|WP_Error True if the redirect URL is valid, a WP_Error object otherwise. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
709 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
710 |
function wp_is_authorize_application_redirect_url_valid( $url ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
711 |
$bad_protocols = array( 'javascript', 'data' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
712 |
if ( empty( $url ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
713 |
return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
714 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
715 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
716 |
// Based on https://www.rfc-editor.org/rfc/rfc2396#section-3.1 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
717 |
$valid_scheme_regex = '/^[a-zA-Z][a-zA-Z0-9+.-]*:/'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
718 |
if ( ! preg_match( $valid_scheme_regex, $url ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
719 |
return new WP_Error( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
720 |
'invalid_redirect_url_format', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
721 |
__( 'Invalid URL format.' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
722 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
723 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
724 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
725 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
726 |
* Filters the list of invalid protocols used in applications redirect URLs. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
727 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
728 |
* @since 6.3.2 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
729 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
730 |
* @param string[] $bad_protocols Array of invalid protocols. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
731 |
* @param string $url The redirect URL to be validated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
732 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
733 |
$invalid_protocols = apply_filters( 'wp_authorize_application_redirect_url_invalid_protocols', $bad_protocols, $url ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
734 |
$invalid_protocols = array_map( 'strtolower', $invalid_protocols ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
735 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
736 |
$scheme = wp_parse_url( $url, PHP_URL_SCHEME ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
737 |
$host = wp_parse_url( $url, PHP_URL_HOST ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
738 |
$is_local = 'local' === wp_get_environment_type(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
739 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
740 |
// Validates if the proper URI format is applied to the URL. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
741 |
if ( empty( $host ) || empty( $scheme ) || in_array( strtolower( $scheme ), $invalid_protocols, true ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
742 |
return new WP_Error( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
743 |
'invalid_redirect_url_format', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
744 |
__( 'Invalid URL format.' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
745 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
746 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
747 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
748 |
if ( 'http' === $scheme && ! $is_local ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
749 |
return new WP_Error( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
750 |
'invalid_redirect_scheme', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
751 |
__( 'The URL must be served over a secure connection.' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
752 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
753 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
754 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
755 |
return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
756 |
} |