jcadima
6/27/2017 - 1:35 PM

Delete admin account

Delete admin account

<?php

// When creating a new user other than the main admin its ID will be 1 more than admin
// if there is only one admin account it will be admin = user_id = 1
// if there are other users the custom user might be 3 or 4, look for user_id 
// after creating this custom user

function admin_account(){
$user = 'testuser';
$pass = 'test@user!';
$email = 'email@domain.com';
if ( !username_exists( $user )  && !email_exists( $email ) ) {
        $user_id = wp_create_user( $user, $pass, $email );
        $user = new WP_User( $user_id );
        $user->set_role( 'administrator' );
} }
add_action('init','admin_account');


/*
* NOTE: comment or remove the code above before adding the Code Below
*/
// REMOVE CUSTOM USER
add_action( 'init', 'remove_custom_user' );
function remove_custom_user() {
	require_once(ABSPATH.'wp-admin/includes/user.php' );
	$current_user = wp_get_current_user();
	wp_delete_user( 2 ); // depends on the number of users, this should be {users}+1
}