Local Community

Fatal error : Cannot access offset of type string on string in "class-wp-roles.php" on line 290

Hi there, Local has just updated and now I can’t access my website anymore.

Here is the critical error message : Fatal error: Uncaught TypeError: Cannot access offset of type string on string in C:\Users\damie\Local Sites\rd-pictures\app\public\wp-includes\class-wp-roles.php on line 290

And here is line 290

 /$this->role_objects[ $role ] = new WP_Role( $role, $this->roles[ $role ]['capabilities'] );/ of my php file : 

 * Initializes all of the available roles.
	 *
	 * @since 4.9.0
	 */
	public function init_roles() {
		if ( empty( $this->roles ) ) {
			return;
		}

		$this->role_objects = array();
		$this->role_names   = array();
		foreach ( array_keys( $this->roles ) as $role ) {
			$this->role_objects[ $role ] = new WP_Role( $role, $this->roles[ $role ]['capabilities'] );
			$this->role_names[ $role ]   = $this->roles[ $role ]['name'];
		}

Thank you for your help !

Hey @Nehzyo , Welcome to the Local Community Forums!

That file looks like it’s related to WordPress core. Here’s that line found on the WP core repo on Github:

Because this is a WordPress error and not something related to Local, I’ve moved it to the “WordPress” category of the forums.

Usually an error like this is due to issues with a plugin or the theme, so you’ll need to zero in on what exactly is causing the problem.

For additional help in troubleshooting issues related to a WordPress site, I recommend taking a look at the WordPress’ support article on debugging WordPress:

Another option is to visit the WordPress.org Support forums and create support post there so that the larger WordPress community can take a look and help!

Good luck!

Following, experiencing same issue.

1 Like

Can you provide a few more details about what’s going on?

Are you seeing the exact same error as the original poster? Were you able to work through some of the debugging steps to zero in on what was going on?

Bug Summary

Getting the following warnings via front-end and back-end:
-( ! ) Warning: Illegal string offset ‘capabilities’ in /Users/x/xx/xxx/app/public/wp-includes/class-wp-roles.php on line 290
-( ! ) Warning: Illegal string offset ‘name’ in /Users/x/xx/xxx/app/public/wp-includes/class-wp-roles.php on line 291

Steps to reproduce

Start Site, Open Site or Admin

Environment Info

-macOS Big Sur v11.6
-both, Local v6.14 & Local Beta 6.15
-both, PHP 7.4 & 8.0
-renamed plugins folder and using twentytwentyone theme

Supporting info

Please provide your Local Log. See this Community Forum post for instructions on how to do so:

Screenshot:

Log:

Hey @cecchinidigital – I’ve merged your bug report to this topic to consolidate the conversation.

Looking at the Local log, I’m not seeing any errors. I also tried creating a new site to see if I could replicate, but everything looks good on my machine.

Are either of you able to create a new, plain site in Local and access it without the error?

More than likely this error is due to some sort of issue with a plugin or the theme, so you might try deactivating all the plugins and then re-enabling them one-by-one to see which one is causing issues.

Hi there, I’m in a same boat.

Bug Summary

Warning: Illegal string offset ‘capabilities’ in /Users/xxxxx/xxxxx/xxxx/xxxxx/xxxxx/app/public/wp-includes/class-wp-roles.php on line 290
Warning: Illegal string offset ‘name’ in /Users/xxxxx/xxxxx/xxxx/xxxxx/xxxxx/app/public/wp-includes/class-wp-roles.php on line 291

Steps to reproduce

After starting Live Link

Environment Info

Local v6.14 & Local Beta 6.15
PHP 7.4.1 & 8.0.0
WordPress 5.8.1

I want to access plugin and theme page for deactivate, but no capability.
I attempted log file below.

Best regards.

local-lightning.log (233.1 KB)

The site started showing this error after activating the live link, before that everything was working fine.

[07-Nov-2021 11:44:55 UTC] PHP Fatal error:  Uncaught TypeError: Cannot access offset of type string on string in /Volumes/Work/Local Sites/rankmath/app/public/wp-includes/class-wp-roles.php:290
Stack trace:
#0 /Volumes/Work/Local Sites/rankmath/app/public/wp-includes/class-wp-roles.php(330): WP_Roles->init_roles()
#1 /Volumes/Work/Local Sites/rankmath/app/public/wp-includes/class-wp-roles.php(90): WP_Roles->for_site(NULL)
#2 /Volumes/Work/Local Sites/rankmath/app/public/wp-settings.php(503): WP_Roles->__construct()
#3 /Volumes/Work/Local Sites/rankmath/app/public/wp-config.php(90): require_once('/Volumes/Work/L...')
#4 /Volumes/Work/Local Sites/rankmath/app/public/wp-load.php(50): require_once('/Volumes/Work/L...')
#5 /Volumes/Work/Local Sites/rankmath/app/public/wp-blog-header.php(13): require_once('/Volumes/Work/L...')
#6 /Volumes/Work/Local Sites/rankmath/app/public/index.php(17): require('/Volumes/Work/L...')
#7 {main}
  thrown in /Volumes/Work/Local Sites/rankmath/app/public/wp-includes/class-wp-roles.php on line 290

Thank you.

Some more details, this error is happening after enabling the live link and trying to access it.

  • Multisite with subdomains
  • Ngnix
  • PHP 8.0
  • MySQL 8.0.16
  • WP 5.8.1
  • Instant Reload Addon is enabled.

wp_user_role becomes:

a:5:{s:13:"administrator";s:5:"Array";s:6:"editor";s:5:"Array";s:6:"author";s:5:"Array";s:11:"contributor";s:5:"Array";s:10:"subscriber";s:5:"Array";}

Thanks for including these details for the site!

I’m still not seeing those PHP errors when I try and replicate. You mention that wp_user_roles have the string Array as the value for those various roles. Is that what is actually within the DB?

When I investigate that option, all of the data seems correct:

I could see how a multisite along with the data that you provided, might trigger that sort of error, but I’m unsure how the data could become corrupted like that.

@surajv – can you describe in a little more detail how this multisite was imported into Local?

@cecchinidigital @bissy @Nehzyo – you didn’t mention when outlining your sites – for the sites you see this error on, are they all subdomain Multisites as well?

Yes, Array words are present in the DB.

This is a fresh install, using a couple of plugins from the last month or so.

But error triggered when I enabled the live link and tried to access it. Whenever I try to access the live link after entering the username and password in the browser prompt, this value becomes corrupt.

If I copy the value from other installations, the live link page is accessible only one time. On second reload, it becomes corrupt again.

Note: Posts, Pages, and a few CPTs are imported from a live website but not the users.

I hope this helps.

Hey there, experiencing the same issue as well!

Bug Summary

Fatal error: Uncaught TypeError: Cannot access offset of type string on string in C:\Users\xx\xx\xxx\app\public\wp-includes\class-wp-roles.php on line 290

Steps to reproduce

Start Site, Open Site or Admin

Environment Info

  • Local 6.15
  • PHP 8.0.0
  • WordPress 5.8.1
  • Not a multisite
  • Renamed plugins folder

Supporting Info

local-lightning.log (228.0 KB)

Thanks!

This is a very interesting piece of information! What that sounds like is that there is something that is updating the user roles, likely on every page load.

You mention that there are a couple of plugins that are being used – are they all from WordPress.org (if so, can you list them?) If they are your own custom plugins, are any of them registering any CPTs along with custom capabilities?

Welcome to the Community @vasek !

I’m seeing a few lines in the Local log that look like this:

{"thread":"main","class":"Process","process":"phpCgi","level":"warn","message":"PHP:  syntax error, unexpected '(' in %%userDataPath%%\\run\\v7eN4Wu5p\\conf\\php\\php.ini on line 210","timestamp":"2021-11-08T07:22:38.951Z"}

Since that seems to be coming from the php.ini file – did you make any changes to that file?

Additionally, if you examine the database for the wp_user_roles option, does it look correct? This blog post goes into more detail about what the “correct” value for that option would look like:

You likely can fix this by updating that value to what it should be, but if you find that this site keeps updating that value to the incorrect thing, then you’ll need to drill down to the plugin that is causing issues!

Hi @ben.turner,

Yeah, you are right, once I change the theme, the error is not happening.

Theme has a couple of CPTs with these capabilities:

'capabilities'        => array(
	'publish_posts'       => 'publish_features',
	'edit_posts'          => 'edit_features',
	'edit_others_posts'   => 'edit_others_features',
	'delete_posts'        => 'delete_features',
	'delete_others_posts' => 'delete_others_features',
	'read_private_posts'  => 'read_private_features',
	'edit_post'           => 'edit_feature',
	'delete_post'         => 'delete_feature',
	'read_post'           => 'read_feature',
)

Hope this helps.

Thank you.

Those look fine, especially in the context of registering a custom post type. The key part though is how those capabilities are added to the various roles (and probably why the original error is within the class-wp-roles.php file)

This WordPress stackexchange answer is almost 100% right, but note the comment on the answer that mentions that the solution should likely use a different hook than the admin_init hook:

In this case, for performance reasons, you don’t want to constantly be re-adding capabilities to roles for every page load.

Yeah, you are right. After activating the default theme, it looks like the error is not happening, not sure what is causing this issue. I will try to figure it out in my free time.

Appreciate your help.

1 Like