WordPress : Add an admin user to database and Reset User Roles

sponsored

In wordpress when some hacking occures or some illegal activity and want to restore the fuctionality then the default admin user may not work. If the default admin user deleted from the database also then you cannot login into the wp-admin backend of wordpress blog. To solve this problem you must manually add a new user to the blog through inserting certain values into the database. Generally PhpMyAdmin is used to do this or use the mysql command shell also.

sponsored

First locate the database of wordpress. The database name, username and password of the database is on the wp-config.php file. Find the lines given below in wp-config.php

/** The name of the database for WordPress */
 define('DB_NAME', 'yourdb_wp');
/** MySQL database username */
     define('DB_USER', 'youruser');
/** MySQL database password */
     define('DB_PASSWORD', 'yourpassword');

Then select the database from the database select menu in phpMyAdmin. Your database will be loaded and you will now see a list of your database tables. You will need to change the wp_users and the wp_usermeta table. Click on the wp_users table to bring up the data for that table. You should see a list of the current users come up – or if you do not have any users you will see the list of database fields available. Click Insert in the top to insert values into this table. The field names and description are given below.

Creating User by Editing wp_users table

  1. user_login – this is the username you want to use to access WordPress
  2. user_pass – this is the password you want to use to access WordPress (be sure to select MD5 from the phpMyAdmin Function menu – WordPress stores passwords with MD5 encryption)
  3. user_nicename – put whatever you would like to refer to yourself as in here (not your username)
  4. user_email – this is the email account associated with this user
  5. user_url – the url to your website like – http://smashingweb.info
  6. user_registered – when was this user registered – just select a date with the date selector or enter the date.
  7. user_activation_key – you can leave this blank — There is no activation key needed
  8. user_status – leave this set to 0
  9. display_name – put a name to display on the admin panel and on the posts.

Now hit the Go button. The value is inserted into the table and you will get a user_id from the field ID. Take that and keep written.

If there are no errors continue with editing the wp_usermeta table. Some values in this table is required to get the added user working with  administrator privilages. that is user level 10.

Creating User Privilages by Editing the wp_usermeta table

 

Now we just created a user by inserting values. Next is we will need to give it privileges to access the WordPress Admin seciton. This is done through the wp_usermeta table. You will need to know the id of the user you just created.We will need to insert two rows into the wp_usermeta table, wp_capabilities and wp_user_level. Here are the steps you will need to follow to give your user privileges.

  1. Click on the wp_usermeta table to bring up the entries.
  2. Click on the “Insert” tab to insert a new row.
  3. Fill in the following data.
    1. umeta_id – leave this blank it is automatically generated
    2. user_id – this is the id of your inserted user (this id will get from the wp_users table ID field)
    3. meta_key – for this step insert wp_capabilities
    4. meta_value – insert exactly this – a:1:{s:13:"administrator";s:1:"1";}
  4. Then press Go. The value is inserted into this table.
  5. Insert another row with the data given below
    1. umeta_id – leave this blank it is automatically generated
    2. user_id – this is the id of your inserted user (this id will get from the wp_users table ID field)
    3. meta_key – for this step insert wp_user_level
    4. meta_value – insert 10
  6. Click the “Go” button in phpMyAdmin to insert the row.

Now you can login with the new inserted user from the wp-admin login page with the username and password specified. After login just go to the Users section and edit on your profile then click update profile button on the bottom. Now wordpress will create some other keys in the tables and have a “clean up” the user just added through backend.

Still some problem persists You can just navigate to wp_options table and find wp_user_roles entry in the option name field Just update the option value given below.

 

a:5:{s:13:"administrator";a:2:{s:4:"name";s:13:"Administrator";s:12:"capabilities";a:62:{s:13:"switch_themes";b:1;s:11:"edit_themes";b:1;s:16:"activate_plugins";b:1;s:12:"edit_plugins";b:1;s:10:"edit_users";b:1;s:10:"edit_files";b:1;s:14:"manage_options";b:1;s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:6:"import";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:8:"level_10";b:1;s:7:"level_9";b:1;s:7:"level_8";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;s:12:"delete_users";b:1;s:12:"create_users";b:1;s:17:"unfiltered_upload";b:1;s:14:"edit_dashboard";b:1;s:14:"update_plugins";b:1;s:14:"delete_plugins";b:1;s:15:"install_plugins";b:1;s:13:"update_themes";b:1;s:14:"install_themes";b:1;s:11:"update_core";b:1;s:10:"list_users";b:1;s:12:"remove_users";b:1;s:9:"add_users";b:1;s:13:"promote_users";b:1;s:18:"edit_theme_options";b:1;s:13:"delete_themes";b:1;s:6:"export";b:1;}}s:6:"editor";a:2:{s:4:"name";s:6:"Editor";s:12:"capabilities";a:34:{s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;}}s:6:"author";a:2:{s:4:"name";s:6:"Author";s:12:"capabilities";a:10:{s:12:"upload_files";b:1;s:10:"edit_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:4:"read";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;s:22:"delete_published_posts";b:1;}}s:11:"contributor";a:2:{s:4:"name";s:11:"Contributor";s:12:"capabilities";a:5:{s:10:"edit_posts";b:1;s:4:"read";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;}}s:10:"subscriber";a:2:{s:4:"name";s:10:"Subscriber";s:12:"capabilities";a:2:{s:4:"read";b:1;s:7:"level_0";b:1;}}}

Generally this is not needed but in some special cases to fix the user roles and permissions in wordpress this will help. Still more problems then drop a query here.

That is it – Added a new user through database in wordpress.

Enhanced by Zemanta

sponsored

Leave a Reply