This code snippet allows you to create and delete a random number of user accounts in the WordPress Admin. While it may seem like a fun and interesting feature, its practicality or usefulness might be debatable. Nevertheless, let’s dive into what this code does and how it accomplishes it.
View on…
See the code…
<?php
if (!class_exists('CreateAndDeleteSomeUserAccounts')) {
// Users: Create & Delete n New Users in WP Admin [SnipSnip.pro] - https://snipsnip.pro/s/799
// This creates then deletes a random number of WordPress user accounts so that your next new Admin account is not a low ID like 1, 2, 3, etc.
// (Now, is this actually important or helpful? Mmm... IDK. I just made it for fun!)
class CreateAndDeleteSomeUserAccounts {
public function __construct() {
require_once(ABSPATH . 'wp-admin/includes/user.php');
$this->createAndDeleteNNewUsers();
}
public function createNewUser() {
$username = uniqid();
$userdata = array(
'user_login' => 'x_user_' . $username,
'user_pass' => 'x_pass_' . $username,
);
$user_id = wp_insert_user($userdata);
return $user_id;
}
public function deleteNewUser($id) {
wp_delete_user($id);
}
public function createAndDeleteNewUser() {
$user = $this->createNewUser();
$this->deleteNewUser($user);
}
public function createAndDeleteNNewUsers() {
$rand = mt_rand(15, 45);
for ($i = 0; $i < $rand; $i++) {
$this->createAndDeleteNewUser();
}
}
}
new CreateAndDeleteSomeUserAccounts();
}