Edit File by line
/home/barbar84/www/wp-admin/includes
File: user.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress user administration API.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Creates a new user from the "Users" form using $_POST information.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.0.0
[11] Fix | Delete
*
[12] Fix | Delete
* @return int|WP_Error WP_Error or User ID.
[13] Fix | Delete
*/
[14] Fix | Delete
function add_user() {
[15] Fix | Delete
return edit_user();
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Edit user settings based on contents of $_POST
[20] Fix | Delete
*
[21] Fix | Delete
* Used on user-edit.php and profile.php to manage and process user options, passwords etc.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 2.0.0
[24] Fix | Delete
*
[25] Fix | Delete
* @param int $user_id Optional. User ID.
[26] Fix | Delete
* @return int|WP_Error User ID of the updated user.
[27] Fix | Delete
*/
[28] Fix | Delete
function edit_user( $user_id = 0 ) {
[29] Fix | Delete
$wp_roles = wp_roles();
[30] Fix | Delete
$user = new stdClass;
[31] Fix | Delete
$user_id = (int) $user_id;
[32] Fix | Delete
if ( $user_id ) {
[33] Fix | Delete
$update = true;
[34] Fix | Delete
$user->ID = $user_id;
[35] Fix | Delete
$userdata = get_userdata( $user_id );
[36] Fix | Delete
$user->user_login = wp_slash( $userdata->user_login );
[37] Fix | Delete
} else {
[38] Fix | Delete
$update = false;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
if ( ! $update && isset( $_POST['user_login'] ) ) {
[42] Fix | Delete
$user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
$pass1 = '';
[46] Fix | Delete
$pass2 = '';
[47] Fix | Delete
if ( isset( $_POST['pass1'] ) ) {
[48] Fix | Delete
$pass1 = trim( $_POST['pass1'] );
[49] Fix | Delete
}
[50] Fix | Delete
if ( isset( $_POST['pass2'] ) ) {
[51] Fix | Delete
$pass2 = trim( $_POST['pass2'] );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) {
[55] Fix | Delete
$new_role = sanitize_text_field( $_POST['role'] );
[56] Fix | Delete
[57] Fix | Delete
// If the new role isn't editable by the logged-in user die with error.
[58] Fix | Delete
$editable_roles = get_editable_roles();
[59] Fix | Delete
if ( ! empty( $new_role ) && empty( $editable_roles[ $new_role ] ) ) {
[60] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false;
[64] Fix | Delete
[65] Fix | Delete
/*
[66] Fix | Delete
* Don't let anyone with 'promote_users' edit their own role to something without it.
[67] Fix | Delete
* Multisite super admins can freely edit their roles, they possess all caps.
[68] Fix | Delete
*/
[69] Fix | Delete
if (
[70] Fix | Delete
( is_multisite() && current_user_can( 'manage_network_users' ) ) ||
[71] Fix | Delete
get_current_user_id() !== $user_id ||
[72] Fix | Delete
( $potential_role && $potential_role->has_cap( 'promote_users' ) )
[73] Fix | Delete
) {
[74] Fix | Delete
$user->role = $new_role;
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
if ( isset( $_POST['email'] ) ) {
[79] Fix | Delete
$user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
[80] Fix | Delete
}
[81] Fix | Delete
if ( isset( $_POST['url'] ) ) {
[82] Fix | Delete
if ( empty( $_POST['url'] ) || 'http://' === $_POST['url'] ) {
[83] Fix | Delete
$user->user_url = '';
[84] Fix | Delete
} else {
[85] Fix | Delete
$user->user_url = esc_url_raw( $_POST['url'] );
[86] Fix | Delete
$protocols = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) );
[87] Fix | Delete
$user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url;
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
if ( isset( $_POST['first_name'] ) ) {
[91] Fix | Delete
$user->first_name = sanitize_text_field( $_POST['first_name'] );
[92] Fix | Delete
}
[93] Fix | Delete
if ( isset( $_POST['last_name'] ) ) {
[94] Fix | Delete
$user->last_name = sanitize_text_field( $_POST['last_name'] );
[95] Fix | Delete
}
[96] Fix | Delete
if ( isset( $_POST['nickname'] ) ) {
[97] Fix | Delete
$user->nickname = sanitize_text_field( $_POST['nickname'] );
[98] Fix | Delete
}
[99] Fix | Delete
if ( isset( $_POST['display_name'] ) ) {
[100] Fix | Delete
$user->display_name = sanitize_text_field( $_POST['display_name'] );
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ( isset( $_POST['description'] ) ) {
[104] Fix | Delete
$user->description = trim( $_POST['description'] );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) {
[108] Fix | Delete
if ( isset( $_POST[ $method ] ) ) {
[109] Fix | Delete
$user->$method = sanitize_text_field( $_POST[ $method ] );
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
if ( isset( $_POST['locale'] ) ) {
[114] Fix | Delete
$locale = sanitize_text_field( $_POST['locale'] );
[115] Fix | Delete
if ( 'site-default' === $locale ) {
[116] Fix | Delete
$locale = '';
[117] Fix | Delete
} elseif ( '' === $locale ) {
[118] Fix | Delete
$locale = 'en_US';
[119] Fix | Delete
} elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
[120] Fix | Delete
$locale = '';
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$user->locale = $locale;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
if ( $update ) {
[127] Fix | Delete
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
[128] Fix | Delete
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
[129] Fix | Delete
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
[130] Fix | Delete
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' === $_POST['comment_shortcuts'] ? 'true' : '';
[134] Fix | Delete
[135] Fix | Delete
$user->use_ssl = 0;
[136] Fix | Delete
if ( ! empty( $_POST['use_ssl'] ) ) {
[137] Fix | Delete
$user->use_ssl = 1;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
$errors = new WP_Error();
[141] Fix | Delete
[142] Fix | Delete
/* checking that username has been typed */
[143] Fix | Delete
if ( '' === $user->user_login ) {
[144] Fix | Delete
$errors->add( 'user_login', __( '<strong>Error</strong>: Please enter a username.' ) );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/* checking that nickname has been typed */
[148] Fix | Delete
if ( $update && empty( $user->nickname ) ) {
[149] Fix | Delete
$errors->add( 'nickname', __( '<strong>Error</strong>: Please enter a nickname.' ) );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Fires before the password and confirm password fields are checked for congruity.
[154] Fix | Delete
*
[155] Fix | Delete
* @since 1.5.1
[156] Fix | Delete
*
[157] Fix | Delete
* @param string $user_login The username.
[158] Fix | Delete
* @param string $pass1 The password (passed by reference).
[159] Fix | Delete
* @param string $pass2 The confirmed password (passed by reference).
[160] Fix | Delete
*/
[161] Fix | Delete
do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) );
[162] Fix | Delete
[163] Fix | Delete
// Check for blank password when adding a user.
[164] Fix | Delete
if ( ! $update && empty( $pass1 ) ) {
[165] Fix | Delete
$errors->add( 'pass', __( '<strong>Error</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
// Check for "\" in password.
[169] Fix | Delete
if ( false !== strpos( wp_unslash( $pass1 ), '\\' ) ) {
[170] Fix | Delete
$errors->add( 'pass', __( '<strong>Error</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
// Checking the password has been typed twice the same.
[174] Fix | Delete
if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) {
[175] Fix | Delete
$errors->add( 'pass', __( '<strong>Error</strong>: Passwords don&#8217;t match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
if ( ! empty( $pass1 ) ) {
[179] Fix | Delete
$user->user_pass = $pass1;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) {
[183] Fix | Delete
$errors->add( 'user_login', __( '<strong>Error</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
if ( ! $update && username_exists( $user->user_login ) ) {
[187] Fix | Delete
$errors->add( 'user_login', __( '<strong>Error</strong>: This username is already registered. Please choose another one.' ) );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/** This filter is documented in wp-includes/user.php */
[191] Fix | Delete
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
[192] Fix | Delete
[193] Fix | Delete
if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) {
[194] Fix | Delete
$errors->add( 'invalid_username', __( '<strong>Error</strong>: Sorry, that username is not allowed.' ) );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/* checking email address */
[198] Fix | Delete
if ( empty( $user->user_email ) ) {
[199] Fix | Delete
$errors->add( 'empty_email', __( '<strong>Error</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
[200] Fix | Delete
} elseif ( ! is_email( $user->user_email ) ) {
[201] Fix | Delete
$errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address isn&#8217;t correct.' ), array( 'form-field' => 'email' ) );
[202] Fix | Delete
} else {
[203] Fix | Delete
$owner_id = email_exists( $user->user_email );
[204] Fix | Delete
if ( $owner_id && ( ! $update || ( $owner_id != $user->ID ) ) ) {
[205] Fix | Delete
$errors->add( 'email_exists', __( '<strong>Error</strong>: This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) );
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Fires before user profile update errors are returned.
[211] Fix | Delete
*
[212] Fix | Delete
* @since 2.8.0
[213] Fix | Delete
*
[214] Fix | Delete
* @param WP_Error $errors WP_Error object (passed by reference).
[215] Fix | Delete
* @param bool $update Whether this is a user update.
[216] Fix | Delete
* @param stdClass $user User object (passed by reference).
[217] Fix | Delete
*/
[218] Fix | Delete
do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) );
[219] Fix | Delete
[220] Fix | Delete
if ( $errors->has_errors() ) {
[221] Fix | Delete
return $errors;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
if ( $update ) {
[225] Fix | Delete
$user_id = wp_update_user( $user );
[226] Fix | Delete
} else {
[227] Fix | Delete
$user_id = wp_insert_user( $user );
[228] Fix | Delete
$notify = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Fires after a new user has been created.
[232] Fix | Delete
*
[233] Fix | Delete
* @since 4.4.0
[234] Fix | Delete
*
[235] Fix | Delete
* @param int $user_id ID of the newly created user.
[236] Fix | Delete
* @param string $notify Type of notification that should happen. See wp_send_new_user_notifications()
[237] Fix | Delete
* for more information on possible values.
[238] Fix | Delete
*/
[239] Fix | Delete
do_action( 'edit_user_created_user', $user_id, $notify );
[240] Fix | Delete
}
[241] Fix | Delete
return $user_id;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Fetch a filtered list of user roles that the current user is
[246] Fix | Delete
* allowed to edit.
[247] Fix | Delete
*
[248] Fix | Delete
* Simple function whose main purpose is to allow filtering of the
[249] Fix | Delete
* list of roles in the $wp_roles object so that plugins can remove
[250] Fix | Delete
* inappropriate ones depending on the situation or user making edits.
[251] Fix | Delete
* Specifically because without filtering anyone with the edit_users
[252] Fix | Delete
* capability can edit others to be administrators, even if they are
[253] Fix | Delete
* only editors or authors. This filter allows admins to delegate
[254] Fix | Delete
* user management.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 2.8.0
[257] Fix | Delete
*
[258] Fix | Delete
* @return array[] Array of arrays containing role information.
[259] Fix | Delete
*/
[260] Fix | Delete
function get_editable_roles() {
[261] Fix | Delete
$all_roles = wp_roles()->roles;
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Filters the list of editable roles.
[265] Fix | Delete
*
[266] Fix | Delete
* @since 2.8.0
[267] Fix | Delete
*
[268] Fix | Delete
* @param array[] $all_roles Array of arrays containing role information.
[269] Fix | Delete
*/
[270] Fix | Delete
$editable_roles = apply_filters( 'editable_roles', $all_roles );
[271] Fix | Delete
[272] Fix | Delete
return $editable_roles;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Retrieve user data and filter it.
[277] Fix | Delete
*
[278] Fix | Delete
* @since 2.0.5
[279] Fix | Delete
*
[280] Fix | Delete
* @param int $user_id User ID.
[281] Fix | Delete
* @return WP_User|false WP_User object on success, false on failure.
[282] Fix | Delete
*/
[283] Fix | Delete
function get_user_to_edit( $user_id ) {
[284] Fix | Delete
$user = get_userdata( $user_id );
[285] Fix | Delete
[286] Fix | Delete
if ( $user ) {
[287] Fix | Delete
$user->filter = 'edit';
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
return $user;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Retrieve the user's drafts.
[295] Fix | Delete
*
[296] Fix | Delete
* @since 2.0.0
[297] Fix | Delete
*
[298] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[299] Fix | Delete
*
[300] Fix | Delete
* @param int $user_id User ID.
[301] Fix | Delete
* @return array
[302] Fix | Delete
*/
[303] Fix | Delete
function get_users_drafts( $user_id ) {
[304] Fix | Delete
global $wpdb;
[305] Fix | Delete
$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 );
[306] Fix | Delete
[307] Fix | Delete
/**
[308] Fix | Delete
* Filters the user's drafts query string.
[309] Fix | Delete
*
[310] Fix | Delete
* @since 2.0.0
[311] Fix | Delete
*
[312] Fix | Delete
* @param string $query The user's drafts query string.
[313] Fix | Delete
*/
[314] Fix | Delete
$query = apply_filters( 'get_users_drafts', $query );
[315] Fix | Delete
return $wpdb->get_results( $query );
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
/**
[319] Fix | Delete
* Remove user and optionally reassign posts and links to another user.
[320] Fix | Delete
*
[321] Fix | Delete
* If the $reassign parameter is not assigned to a User ID, then all posts will
[322] Fix | Delete
* be deleted of that user. The action {@see 'delete_user'} that is passed the User ID
[323] Fix | Delete
* being deleted will be run after the posts are either reassigned or deleted.
[324] Fix | Delete
* The user meta will also be deleted that are for that User ID.
[325] Fix | Delete
*
[326] Fix | Delete
* @since 2.0.0
[327] Fix | Delete
*
[328] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[329] Fix | Delete
*
[330] Fix | Delete
* @param int $id User ID.
[331] Fix | Delete
* @param int $reassign Optional. Reassign posts and links to new User ID.
[332] Fix | Delete
* @return bool True when finished.
[333] Fix | Delete
*/
[334] Fix | Delete
function wp_delete_user( $id, $reassign = null ) {
[335] Fix | Delete
global $wpdb;
[336] Fix | Delete
[337] Fix | Delete
if ( ! is_numeric( $id ) ) {
[338] Fix | Delete
return false;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
$id = (int) $id;
[342] Fix | Delete
$user = new WP_User( $id );
[343] Fix | Delete
[344] Fix | Delete
if ( ! $user->exists() ) {
[345] Fix | Delete
return false;
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
// Normalize $reassign to null or a user ID. 'novalue' was an older default.
[349] Fix | Delete
if ( 'novalue' === $reassign ) {
[350] Fix | Delete
$reassign = null;
[351] Fix | Delete
} elseif ( null !== $reassign ) {
[352] Fix | Delete
$reassign = (int) $reassign;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
/**
[356] Fix | Delete
* Fires immediately before a user is deleted from the database.
[357] Fix | Delete
*
[358] Fix | Delete
* @since 2.0.0
[359] Fix | Delete
* @since 5.5.0 Added the `$user` parameter.
[360] Fix | Delete
*
[361] Fix | Delete
* @param int $id ID of the user to delete.
[362] Fix | Delete
* @param int|null $reassign ID of the user to reassign posts and links to.
[363] Fix | Delete
* Default null, for no reassignment.
[364] Fix | Delete
* @param WP_User $user WP_User object of the user to delete.
[365] Fix | Delete
*/
[366] Fix | Delete
do_action( 'delete_user', $id, $reassign, $user );
[367] Fix | Delete
[368] Fix | Delete
if ( null === $reassign ) {
[369] Fix | Delete
$post_types_to_delete = array();
[370] Fix | Delete
foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
[371] Fix | Delete
if ( $post_type->delete_with_user ) {
[372] Fix | Delete
$post_types_to_delete[] = $post_type->name;
[373] Fix | Delete
} elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) {
[374] Fix | Delete
$post_types_to_delete[] = $post_type->name;
[375] Fix | Delete
}
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
/**
[379] Fix | Delete
* Filters the list of post types to delete with a user.
[380] Fix | Delete
*
[381] Fix | Delete
* @since 3.4.0
[382] Fix | Delete
*
[383] Fix | Delete
* @param string[] $post_types_to_delete Array of post types to delete.
[384] Fix | Delete
* @param int $id User ID.
[385] Fix | Delete
*/
[386] Fix | Delete
$post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
[387] Fix | Delete
$post_types_to_delete = implode( "', '", $post_types_to_delete );
[388] Fix | Delete
$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 ) );
[389] Fix | Delete
if ( $post_ids ) {
[390] Fix | Delete
foreach ( $post_ids as $post_id ) {
[391] Fix | Delete
wp_delete_post( $post_id );
[392] Fix | Delete
}
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
// Clean links.
[396] Fix | Delete
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
[397] Fix | Delete
[398] Fix | Delete
if ( $link_ids ) {
[399] Fix | Delete
foreach ( $link_ids as $link_id ) {
[400] Fix | Delete
wp_delete_link( $link_id );
[401] Fix | Delete
}
[402] Fix | Delete
}
[403] Fix | Delete
} else {
[404] Fix | Delete
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
[405] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) );
[406] Fix | Delete
if ( ! empty( $post_ids ) ) {
[407] Fix | Delete
foreach ( $post_ids as $post_id ) {
[408] Fix | Delete
clean_post_cache( $post_id );
[409] Fix | Delete
}
[410] Fix | Delete
}
[411] Fix | Delete
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
[412] Fix | Delete
$wpdb->update( $wpdb->links, array( 'link_owner' => $reassign ), array( 'link_owner' => $id ) );
[413] Fix | Delete
if ( ! empty( $link_ids ) ) {
[414] Fix | Delete
foreach ( $link_ids as $link_id ) {
[415] Fix | Delete
clean_bookmark_cache( $link_id );
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
// FINALLY, delete user.
[421] Fix | Delete
if ( is_multisite() ) {
[422] Fix | Delete
remove_user_from_blog( $id, get_current_blog_id() );
[423] Fix | Delete
} else {
[424] Fix | Delete
$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
[425] Fix | Delete
foreach ( $meta as $mid ) {
[426] Fix | Delete
delete_metadata_by_mid( 'user', $mid );
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
clean_user_cache( $user );
[433] Fix | Delete
[434] Fix | Delete
/**
[435] Fix | Delete
* Fires immediately after a user is deleted from the database.
[436] Fix | Delete
*
[437] Fix | Delete
* @since 2.9.0
[438] Fix | Delete
* @since 5.5.0 Added the `$user` parameter.
[439] Fix | Delete
*
[440] Fix | Delete
* @param int $id ID of the deleted user.
[441] Fix | Delete
* @param int|null $reassign ID of the user to reassign posts and links to.
[442] Fix | Delete
* Default null, for no reassignment.
[443] Fix | Delete
* @param WP_User $user WP_User object of the deleted user.
[444] Fix | Delete
*/
[445] Fix | Delete
do_action( 'deleted_user', $id, $reassign, $user );
[446] Fix | Delete
[447] Fix | Delete
return true;
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
/**
[451] Fix | Delete
* Remove all capabilities from user.
[452] Fix | Delete
*
[453] Fix | Delete
* @since 2.1.0
[454] Fix | Delete
*
[455] Fix | Delete
* @param int $id User ID.
[456] Fix | Delete
*/
[457] Fix | Delete
function wp_revoke_user( $id ) {
[458] Fix | Delete
$id = (int) $id;
[459] Fix | Delete
[460] Fix | Delete
$user = new WP_User( $id );
[461] Fix | Delete
$user->remove_all_caps();
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* @since 2.8.0
[466] Fix | Delete
*
[467] Fix | Delete
* @global int $user_ID
[468] Fix | Delete
*
[469] Fix | Delete
* @param false $errors Deprecated.
[470] Fix | Delete
*/
[471] Fix | Delete
function default_password_nag_handler( $errors = false ) {
[472] Fix | Delete
global $user_ID;
[473] Fix | Delete
// Short-circuit it.
[474] Fix | Delete
if ( ! get_user_option( 'default_password_nag' ) ) {
[475] Fix | Delete
return;
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
// get_user_setting() = JS-saved UI setting. Else no-js-fallback code.
[479] Fix | Delete
if ( 'hide' === get_user_setting( 'default_password_nag' )
[480] Fix | Delete
|| isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag']
[481] Fix | Delete
) {
[482] Fix | Delete
delete_user_setting( 'default_password_nag' );
[483] Fix | Delete
update_user_option( $user_ID, 'default_password_nag', false, true );
[484] Fix | Delete
}
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
/**
[488] Fix | Delete
* @since 2.8.0
[489] Fix | Delete
*
[490] Fix | Delete
* @param int $user_ID
[491] Fix | Delete
* @param WP_User $old_data
[492] Fix | Delete
*/
[493] Fix | Delete
function default_password_nag_edit_user( $user_ID, $old_data ) {
[494] Fix | Delete
// Short-circuit it.
[495] Fix | Delete
if ( ! get_user_option( 'default_password_nag', $user_ID ) ) {
[496] Fix | Delete
return;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function