This post will explain how to restore deleted WordPress user roles or capabilities. Some users wrote that they press the “Reset” button at the “Settings->User Role Editor->Tools” tab expecting something different that it really does. As the result they lost any new added roles and capabilities. It doesn’t matter manually they were added or automatically by plugins or themes. After you press “Reset” button “User Role Editor” deletes all user roles and calls WordPress core function which is used during 1st WordPress installation. Roles and capabilities are created by WordPress from the scratch and you get standard (core) list of user roles and capabilities only as the result.
“Settings->User Role Editor->Tools” contains the 1st warning that “Reset” action could be dangerous:
The 2nd warning/confirmation dialog is opened just after press the “Reset” button and it tell exactly about that:
I think, it’s quite enough to warning a user twice. If someone ignores 2 warnings about critical changes, he/she is sure what he/she does.
How to restore lost user roles
If reactivation of the plugin (“P”), which capabilities were deleted/lost, did not help:
- 1st variant – install “P” at the test WordPress site. Look into the “Custom Capabilities” section of “User Role Editor”. You will see the list of capabilities to restore manually. You may “Reset” roles at the test site before new plugin installation, in order to see its capabilities only at the “Custom capabilities” section. Add absent capabilities manually and turn them on for the needed roles.
- 2nd variant – You may try to reinstall plugin “P” from the scratch. Delete folder with the plugin “P” (wp-content/plugins/P). Open “Plugins” page. WordPress will delete plugin “P” automatically with warning message about missing files. Install plugin “P” again.
- 3rd variant – User Role Editor creates roles backup record before save the very 1st update to them. You need to use SQL tool like phpMyAdmin. Find that record at ‘wp_options’ meta database table:
select * from wp_options where option_name='wp_backup_user_roles';
As the result you will see something like this (I use MySQL Workbench):
Take data from the
option_valuefield and place them into the record where WordPress stores user roles originally. You may find it with this SQL query:
select * from wp_options where option_name='wp_user_roles';
Read this post for more details about changing WordPress user roles directly in the database using SQL commands.
- 4th variant – always make WordPress database backup before making any critical operations. This way you may simply restore the database from the fresh backup copy and continue exactly from the state you meet the accident with WordPress state.
- 5th variant – User Role Editor Pro has the “export/import” feature. This way you may easily create fresh backup not the full WordPress database, but the user roles only. Then you may restore user roles from the local disk file at any time if something goes wrong.