Überspringen zu Hauptinhalt

How to Create an admin User with functions.php or via phpmyadmin in WordPress

StockSnap / Pixabay

Sometimes you don’t yet have backend access from your client but you need to got to the WordPress dashboard. Fortunately if you have some FTP credentials that work you can simply create a WordPress user by adding a few lines into the themes functions.php. Also of course I mention the regular SQL statement way as well.

Method 1: Create a user with the functions.php

function wpb_admin_account(){
$user = 'enym';
$pass = '123456';
$email = 'test@yourdomain.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','wpb_admin_account');

Once you have logged in to your WordPress site, please edit the functions.php file and delete the code above. Deleting the code will not remove the user but you don’t need it anymore since it was already created by it’s first call.

Method 2: Directly into phpmyadmin with this SQL statement

Of you you can easily create a user with a MySQL statement as well. Simply drop this snippet in phpmyadmin and you are good to go. Don’t forget to adapt to you data.

INSERT INTO                         `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('2', 'tester', MD5('password'), 'Your Name', 'info@example.com', 'https://www.example.com/', '2020-07-01 22:39:39', '', '0', 'Your name');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_capabilities', 'a:1:{s:13:\"administrator\";s:1:\"1\";}');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_user_level', '10');

Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

An den Anfang scrollen