TL;DR Scroll down to find the gist with the proposed solution to recover or reset the default WordPress roles and capabilities.
One of the most powerful features of WordPress is the user roles and capabilities system. This is a core WordPress feature that allows the permissions control over any aspect of a site. Who is able to read a post, who is able to write a post, publish it or delete it? Who can create users? and so on.
I often get help calls from clients asking for help to optimize or fix some aspects of a running WordPress site.
Last week I got access to a client’s WordPress site where all the default user’s roles disappeared, which left all the users without any role, except the super admin users (available on a multisite installation).
This is very strange and I don’t know what happened but since I was asked to change the author of some blog posts, and the author dropdown was only showing super admin users, I needed to figure out a way to reset the WordPress to get back the default users’ roles.
After some investigation I found a very simple solution which I’m sharing here on a form of a simple plugin that should be installed, activated and deactivated as soon as the users’ roles are back.
The solution uses a core function called
populate_roles() which is responsible for the WordPress role creation depending on the specific WordPress version.