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:
- Login in to your database dashboard
- Navigate to your WordPress site database
- Find the
wp_options
table (in my case it’swp_
, your table prefix might be bit different) - Search for the option name `wp_user_roles` (again in my case it’s
wp_
, your table prefix might be bit different) - Copy the value for this field
Step 2:
- Now navigate to the
wp_2_options
table (for this example, I’m creating a 2nd site so the prefix iswp_2_
. You may have different prefix based on your setup) - Search for the option name
wp_2_user_roles
- Update the value for this key with the value we copied from the main site.
That’s all. Your site should work now.