WordPress missing user roles on local dev machine. Live site works fine

I have a live WordPress installation and a local one for development purposes. I just exported the live database, replaced all occurences of the live siteurl with the local one, and imported on my dev machine.

Problem is that on my dev machine all users have lost any permissions. When logging in I get:

Read More
Notice: Undefined offset: 2 in /var/www/mysite/wp-admin/includes/plugin.php on line 1390 

On a page template I dumped out the current userinfo with

global $current_user;
var_dump( get_currentuserinfo() );

This returns NULL on my dev machine and the correct userinfo on my live installation. I double checked the table prefixes, permissions, tried a clean WordPress installation, etc but had no luck. The confusing thing about this is, that I can query the userinfo perfectly fine with a custom sql query.

EDIT: Upon further inspection I found out that the global $wp_roles contains no user roles and capabilities. WordPress somehow can’t retrieve this from the database…

EDIT 2: Sorry for the edits. But I found the problem. Inside the wp_options table there is a row “wp_user_roles”. The value, an unserialized string did somehow include whitespaces which lead to errors when trying to unserialize the string. I replaced the database value with the live site’s one and everything works now.

Related posts

Leave a Reply

2 comments

  1. I just exported the live database, replaced all occurences of the live
    siteurl with the local one, and imported on my dev machine.

    Finding/replacing with a text editor breaks serialized data; you must change values with MySQL queries in phpmyadmin:

    UPDATE wp_options SET option_value = replace(option_value, 'http://www.olddomain.com/', 'http://www.newdomain.com/') WHERE option_name = 'home' OR option_name = 'siteurl';
    
    UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.com/blog/','http://www.newdomain.com/');
    
    UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.com/blog/', 'http://www.newdomain.com/');
    
    UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.olddomain.com/blog/', 'http://www.newdomain.com/');
    
  2. Just in case anyone else has this issue:

    I had two sites with a custom table prefix. This prefix is also used for some rows in the options table. When moving the options table from one site to another, I renamed the options table itself, but didn’t know I had to rename some of the option names too, in particular the wp_user_roles option which was actually prefix_user_roles. There were several options in my wp_options (prefix_options) table with that prefix.

    WordPress automatically created the prefix_user_roles option when it did not recognize the otherprefix_user_roles option which locked me out.