Skip to content

Instantly share code, notes, and snippets.

@ControlledChaos
Last active February 10, 2021 22:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ControlledChaos/c6a11695b2926a3a56df1f91bbd451f1 to your computer and use it in GitHub Desktop.
Save ControlledChaos/c6a11695b2926a3a56df1f91bbd451f1 to your computer and use it in GitHub Desktop.

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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment