ControlledChaos
10/30/2018 - 5:15 PM

Admin account via FTP

Create Admin Account via FTP

WordPress Snippet

If you have FTP access to a client's website but they didn't give you an administrator account then this snippet in a plugin, or in file in their ~/wp-content/mu-plugins/ folder, will generate an account for you. Change the login info to yours.

<?php

function ccd_add_admin_acct() {

	$login = '$LoginName';
	$pass  = '$MyPassword';
	$email = '$myemail@example.com';

	if ( ! username_exists( $login ) && ! email_exists( $email ) ) {
	
		$user_id = wp_create_user( $login, $pass, $email );
		$user    = new WP_User( $user_id );

		$user->set_role( 'administrator' );

	}
}
add_action( 'init', 'ccd_add_admin_acct' );