• Hello,

    I have a wordpress 2.0 blog that has been running fine, until recently I had to move the database to a new location on the same server. The old DB was was in a shared database, whereas the new one is the database installed on my dedicated server.

    What I did was dump a backup of the old DB (as the wordpress tables were among many other tables for the site), restore the DB in the new location, and change wp-config to connect to the new DB – only had to change DB_HOST to ‘localhost’.

    For the most part, the blog is intact, except for the error at the top which reads:

    Warning: Invalid argument supplied for foreach() in /wp-includes/capabilities.php on line 19

    Whats worse, the admin login has these errors:

    Warning: Invalid argument supplied for foreach() in /wp-includes/capabilities.php on line 19

    Warning: Cannot modify header information – headers already sent by (output started at /wp-includes/capabilities.php:19) in /wp-login.php on line 9

    This also prevents me from logging in to the admin.

    It’s clear that the problem is with capabilities.php but I’m not sure how or why since the file wasn’t touched. The wordpress files didn’t move or change except for wp-config.

    I’m an intermediate with PHP/MySQL. Any pointers or help would be appreciated

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter illamental

    (@illamental)

    Has anyone seen this before? Or have any ideas what I could have done wrong?

    Thread Starter illamental

    (@illamental)

    still having this problem….wordpress new release didnt fix

    here’s line 19 – 22 of capabilities.php:

    foreach ($this->roles as $role => $data) {
    $this->role_objects[$role] = new WP_Role($role, $this->roles[$role][‘capabilities’]);
    $this->role_names[$role] = $this->roles[$role][‘name’];
    }

    I have the same problem and it’s been quite frustrating to resolve. I installed WordPress in an ISS server. If someone could drop be and help us out that would be much appreciated.

    Thread Starter illamental

    (@illamental)

    ignat, i figured it out

    problem with mine was some information in the database that capabilities.php was trying to retrieve. i wont go into the details of how i figured it out, but here was my solution:

    in my wp_options table, i found the option with the name “wp_user_roles”. in that same row, it’s “option_value” field has a lot of code/characters starting with “a:5:{s:13:”administrator”……

    this text is supposed to be one long string of text, but when i moved the database over, it had broken the long string into several lines with breaks inbetween. this made capabilities.php unable to read the information properly. once i removed all the breaks, the site was back to normal.

    i hope this helps ??

    I have the same problem, and i’ve tried to “tidy-up” the wp_user_role in my db, but nothing seems to work.

    I can’t access anything in the admin section, i don’t have sufficient rights.

    What can i do ?

    /Mads

    I ALSO have the problem. Where are all these people that brag about how EASY it is to install WordPress!!! My install is “straight out of the box” on a “virgin” linux system. Should have been 100%.

    VERY frustrating.

    Since moving over from an IIS server to a fresh Linux with Apache 2 Handler (not sure what ‘handler’ means) + PHP 5.0.4 installation… I am now getting this error when attempting to log in to the Admin area.

    It is pulling from the same old database that was not altered in the move, so I tried re-installing WordPress thinking that it might have some ‘calibrating’ features unique for the server upon install and that the old files wouldn’t work. After 3 or 4 re-installs, my issues remain and I am finding little consolation on these support forums for this error.

    I do not have a broken string as illamental did, so that didn’t help. So, my client’s site is down until I can rectify the issue. My guess is that it’s something to do with Apache or PHP (since that’s the only thing that changed in the move), but I have no idea what.

    Edit: Since posting this, I checked out this post which had been resolved. However… their solution with the .htaccess file did not solve my issue. I am going to contact my host to see if they can disable that PHP function from their end.

    Figured it out! Thanks to jimre, who posted the information about the PHP feature of magic_quotes, I decided to do some reearch at php.net and found that only the magic_quotes_runtime should be turned off.

    When this piece of data regarding access permissions is pulled from the database magic_quotes_runtime was adding a backslash before the quote character, so a:5:{s:13:”administrator”… was turning into a:5:{s:13:\”administrator\”…. What is WP to do with this random bit of information? Return an error of course!

    So, I turned ONLY the magic_quotes_runtime feature off through the .htaccess file within /wordpress/, and voila. Turning off the magic_quotes_gpc ended up shutting down the site all together… so a bit of Trial and Error was involved, but my issue is now resolved.

    I’ve tried to put this in my .htaccess

    php_flag set_magic_quotes_runtime off

    i’ve also trieed it without set_in the beginning. Nothing works for me :/

    I just have php_flag magic_quotes_runtime Off … no “set_” in there … so, I’m not sure what to say. Did you do a phpinfo(); on your site to see if your magic_quotes is even on?

    i’m having the same problem! on a windows server. so, no. htaccess file… What are my options? for heavens sakes!

    tsteingard…

    I’ve just checked, and magic_quotes_runtime is’nt activated on my hosts server

    I don’t know, then. I was having a problem on a Windows IIS server, so I advised my client to get his host to move to a Linux box with Apache/PHP/MySQL, and then I ran into this issue with the PHP “magic quotes” being turned on. So, I figured out how to turn it off, and voila.

    kingmedia, what are you seeing on your site? Are you getting the slashes before anything that has quotes on it? If so, then your issue is with Magic Quotes in PHP. If not, then you’ve got a completely different issue.

    tsteingard >>> Then it’s maybe someting different… i get this message all the time though.

    Warning: Invalid argument supplied for foreach() in /hsphere/local/home/binarybo/kingmedia.dk/wp-includes/capabilities.php on line 19

    I’ve been struggling with this on IIS and have come up with a hack that seems to work. With my host, magic_quotes_gpc is on, and there is no way to turn it off. The problem starts on line 14 of capabilities.php – $this->roles =get_option($this->role_key);
    The get_option function gets user role data that illamental refers to above. magic_quotes_gpc escapes the quotes, so the following lines in capabilities.php don’t know how to handle the return value.
    I copied the get_options function (actually get_settings, which get_options calls), and changed the call on line 14 to point to the new function. The only difference is the new function uses stripslashes when getting the row from the db. Here’s the change in the new function:
    $value = stripslashes(wp_cache_get($setting, 'options'));
    // original: $value = wp_cache_get($setting, 'options');

    I originally tried to just change get_settings, but it is used by other functions and errors popped up in other places.
    Magic_quotes_gpc still causes problems elsewhere, like if you have a single quote or apostrophe in a post it causes an sql error. I’m still working on that.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Invalid argument …foreach() in capabilities.php’ is closed to new replies.