Title: Invalid argument &#8230;foreach() in capabilities.php
Last modified: August 18, 2016

---

# Invalid argument …foreach() in capabilities.php

 *  [illamental](https://wordpress.org/support/users/illamental/)
 * (@illamental)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/)
 * 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)

1 [2](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/page/2/?output_format=md)

 *  Thread Starter [illamental](https://wordpress.org/support/users/illamental/)
 * (@illamental)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-368979)
 * Has anyone seen this before? Or have any ideas what I could have done wrong?
 *  Thread Starter [illamental](https://wordpress.org/support/users/illamental/)
 * (@illamental)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369004)
 * 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’]; }
 *  [ignat](https://wordpress.org/support/users/ignat/)
 * (@ignat)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369005)
 * 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](https://wordpress.org/support/users/illamental/)
 * (@illamental)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369008)
 * 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 🙂
 *  [kingmedia](https://wordpress.org/support/users/kingmedia/)
 * (@kingmedia)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369014)
 * 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
 *  [lwoods](https://wordpress.org/support/users/lwoods/)
 * (@lwoods)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369015)
 * 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.
 *  [Steingard](https://wordpress.org/support/users/tsteingard/)
 * (@tsteingard)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369016)
 * 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](http://wordpress.org/support/topic/71440)
   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._
 *  [Steingard](https://wordpress.org/support/users/tsteingard/)
 * (@tsteingard)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369017)
 * Figured it out! Thanks to _jimre_, who [posted the information about the PHP feature of magic_quotes](http://wordpress.org/support/topic/71440),
   I decided to do some reearch at [php.net](http://ca3.php.net/manual/de/security.magicquotes.php)
   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.
 *  [kingmedia](https://wordpress.org/support/users/kingmedia/)
 * (@kingmedia)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369018)
 * 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 :/
 *  [Steingard](https://wordpress.org/support/users/tsteingard/)
 * (@tsteingard)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369019)
 * 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?
 *  [josedante](https://wordpress.org/support/users/josedante/)
 * (@josedante)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369022)
 * i’m having the same problem! on a windows server. so, no. htaccess file… What
   are my options? for heavens sakes!
 *  [kingmedia](https://wordpress.org/support/users/kingmedia/)
 * (@kingmedia)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369024)
 * tsteingard…
 * I’ve just checked, and `magic_quotes_runtime` is’nt activated on my hosts server
 *  [Steingard](https://wordpress.org/support/users/tsteingard/)
 * (@tsteingard)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369025)
 * 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.
 *  [kingmedia](https://wordpress.org/support/users/kingmedia/)
 * (@kingmedia)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369026)
 * 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`
 *  [masteriamnot](https://wordpress.org/support/users/masteriamnot/)
 * (@masteriamnot)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/#post-369028)
 * 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)

1 [2](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/page/2/?output_format=md)

The topic ‘Invalid argument …foreach() in capabilities.php’ is closed to new replies.

## Tags

 * [foreach](https://wordpress.org/support/topic-tag/foreach/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 17 replies
 * 9 participants
 * Last reply from: [vkaryl](https://wordpress.org/support/users/vkaryl/)
 * Last activity: [19 years, 5 months ago](https://wordpress.org/support/topic/invalid-argument-foreach-in-capabilitiesphp/page/2/#post-369039)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
