The Issue:

When creating a new site in WordPress Multi-site environment, I came across this issue fatal error.

Fatal error: Uncaught Error: Call to a member function add_cap() on null in /srv/www/wordpress-default/public_html/wp-content/....XXXX....

While digging deep into it, I found that the WordPress default roles value is missing for the new site.

The Fix for this issue:

Find the correct roles value from the main site. To do this follow the below steps.

Step 1:

  1. Login in to your database dashboard
  2. Navigate to your WordPress site database
  3. Find the wp_options table (in my case it’s wp_, your table prefix might be bit different)
  4. Search for the option name `wp_user_roles`¬†(again in my case it’s wp_, your table prefix might be bit different)
  5. Copy the value for this field

Step 2:

  1. Now navigate to the wp_2_optionstable (for this example, I’m creating a 2nd site so the prefix is wp_2_. You may have different prefix based on your setup)
  2. Search for the option name wp_2_user_roles
  3. Update the value for this key with the value we copied from the main site.

That’s all. Your site should work now.