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'];
}
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!
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:
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.
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.
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?
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.
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
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?
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!
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.
Thanks for the suggestions. I did make some changes to the php.ini file when I was troubleshooting though those were since reversed. Turns out something had changed the wp_user_roles value, reverting this to a value that was on an older copy of the database thankfully fixed the issue. Still not sure what originally caused this, as it hasn’t occurred again.
Using ‘livelink’ the same error happens here: Uncaught TypeError: Cannot access offset of type string on string in xxx/app/public/wp-includes/class-wp-roles.php on line 290
Changing the ‘roles’ in the DB by copying a previous DB entry I had was the only way to fix it. Quite an annoying bug.
Same here. Enabled live link and got this error right after. Copying the value of the wp_user_roles entry in the wp_options table from a backup resolved the issue. This is an annoying bug, reluctant to try live links again now…