DEV Community

Cover image for Add WordPress user using FTP
Yuvraj Khavad
Yuvraj Khavad

Posted on

3

Add WordPress user using FTP

Recently, one of our clients sent us a list of WordPress website changes with FTP detail but they don’t have a WordPress admin login details.

At that time below code helps us to add a WordPress administrator user. Just add this code on function.php of the active theme.

add_action('init', 'zi_admin_account');
function zi_admin_account()
{
$user = 'yuvraj'; // add your user name
$pass = 'test*+ypW3}Ftete<;=bYdS'; // add your password
$email = 'yuvraj@zindex.co.in'; // add your email address
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');
}
}
view raw new-wp-user.php hosted with ❀ by GitHub

Just delete this code after login successfully.

Happy Coding !! Feel free to ask us any questions if have.

Top comments (2)

Collapse
 
ibonkonesa profile image
Ibon β€’

Nice solution! Maybe I would tried to use a web shell and insert user directly to database, but this one is easier :)

Collapse
 
yuvrajkhavad profile image
Yuvraj Khavad β€’

Yes, this is very easier. Thanks

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay