{"id":3109,"date":"2019-05-27T15:11:13","date_gmt":"2019-05-27T13:11:13","guid":{"rendered":"https:\/\/www.knowboard.de\/?p=3109"},"modified":"2020-07-03T22:50:25","modified_gmt":"2020-07-03T20:50:25","slug":"how-to-create-an-admin-user-with-functions-php-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.knowboard.de\/how-to-create-an-admin-user-with-functions-php-in-wordpress\/","title":{"rendered":"How to Create an admin User with functions.php or via phpmyadmin in WordPress"},"content":{"rendered":"\n
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.<\/p>\n\n\n\n
function wpb_admin_account(){\n$user = 'enym';\n$pass = '123456';\n$email = 'test@yourdomain.com';\nif ( !username_exists( $user ) && !email_exists( $email ) ) {\n$user_id = wp_create_user( $user, $pass, $email );\n$user = new WP_User( $user_id );\n$user->set_role( 'administrator' );\n} }\nadd_action('init','wpb_admin_account');<\/pre>\n\n\n\nOnce 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.<\/p>\n\n\n\n
Method 2: Directly into phpmyadmin with this SQL statement<\/h2>\n\n\n\n
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.<\/p>\n\n\n\n
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');\n\nINSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_capabilities', 'a:1:{s:13:\\\"administrator\\\";s:1:\\\"1\\\";}');\n\nINSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_user_level', '10');<\/pre>\n","protected":false},"excerpt":{"rendered":"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…<\/p>\n","protected":false},"author":1,"featured_media":546,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-3109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","entry","has-media"],"_links":{"self":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/3109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/comments?post=3109"}],"version-history":[{"count":2,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/3109\/revisions"}],"predecessor-version":[{"id":3565,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/3109\/revisions\/3565"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/media\/546"}],"wp:attachment":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/media?parent=3109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/categories?post=3109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/tags?post=3109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}