• Hello, I am getting a critical error on my website (in dev, so I’m unable to post the link) and the following error message from debug.log. Can anyone help me fix this?

    [30-Jul-2023 10:36:53 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type WP_Role as array in /home/public/mydomain.com/wp-includes/class-wp-roles.php:292
    Stack trace: 0 /home/public/mydomain.com/wp-includes/class-wp-roles.php(332): WP_Roles->init_roles() 1 /home/public/mydomain.com/wp-includes/class-wp-roles.php(91): WP_Roles->for_site() 2 /home/public/mydomain.com/wp-settings.php(548): WP_Roles->__construct() 3 /home/public/mydomain.com/wp-config.php(117): require_once(‘/home/public/…’) 4 /home/public/mydomain.com/wp-load.php(50): require_once(‘/home/public/…’) 5 /home/public/mydomain.com/wp-login.php(12): require(‘/home/public/…’) 6 {main}

    thrown in /home/public/mydomain.com/wp-includes/class-wp-roles.php on line 292

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @sharoni,
    The error message indicates that an object of type WP_Role is being used as an array. This is happening within the WordPress core file class-wp-roles.php which is unusual, as you would normally expect errors like this to occur due to a problem in a plugin or theme.

    However, given this error, it’s possible that there is a plugin or theme which is incorrectly interacting with user roles and capabilities.

    You can try the following steps to troubleshoot:

    1. Disable all plugins: This will help you find out if a plugin is causing the issue. You can do this via the WordPress admin dashboard.
    2. Switch to a default theme: If the error isn’t caused by a plugin, try switching to a default theme to see if your theme is the problem. You can do this via the WordPress dashboard.
    3. Debug wp-config.php: If you still experience the issue after disabling plugins and switching the theme, it might be related to your wp-config.php file. As per your error log, there is a line in wp-config.php that requires wp-settings.php. Check the lines around it to see if there’s anything unusual.
    Thread Starter sharoni

    (@sharoni)

    Hi Olga, thanks for your reply.
    I renamed the plugins and theme folders as I have no access to wp dashboard and compared wp-config to the sample file but didn’t see anything out of place. I also uploaded fresh WP core files, updated php to 8 (from 7.4) and increased memory limit, but still have the error. I tried recovery mode but didn’t receive the email with the link.

    Any ideas?

    One possibility is that the user roles and capabilities on your WordPress site have been manipulated incorrectly, possibly by a plugin or custom code.

    If your error log is still indicating that the problem is in the class-wp-roles.php file after trying all the steps you’ve mentioned, it could be an issue in your database, specifically within the wp_options table. The wp_user_roles row in the wp_options table might have been corrupted. This row contains all the user role definitions.

    Before proceeding, please make sure to back up your database. You can then try to repair the database. If you have phpMyAdmin in your hosting control panel, you can use it to repair the database.

    If that doesn’t work, you may need to reset your user roles. There are plugins like “User Role Editor” that can reset your roles to their WordPress defaults, but since you can’t access the dashboard, you might need to use WP-CLI (if your host provides it) or do it manually.

    To do it manually, you’d need to access your database (likely through phpMyAdmin) and find the wp_options table, then the wp_user_roles row. The default value of this row for a fresh WordPress install can be found in the wp-includes/class-wp-role.php file. You can replace the corrupted value with the default value from a fresh WordPress install.

    Keep in mind this advice assumes the database is the issue, it’s possible that the issue is still elsewhere.

    Thread Starter sharoni

    (@sharoni)

    I am happy to say the website is working again! After your detailed reply, I went into the wp_user_roles and copied the values from another site into the table. This did the trick.

    Thanks for your assistance, Olga

    Thread Starter sharoni

    (@sharoni)

    Just to add, it was caused by faulty code and a deleted plugin as you suggested, which had left values in the wp_user_roles table.

    Sharoni

    Awesome! Really happy that your website is working again ?? Also, thank you for clarifying what the problem was – it will be useful for others who end up here researching the same problem.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP fatal error WP_Roles’ is closed to new replies.