• Resolved jhong

    (@jhong)


    Hello,

    I have some custom-rolled code that is called wp_update_user to update the user info in the database.

    However, I was receiving A Fatal error (invalid argument in ForEach).

    I tracked the problem down to the following line:

    $user = add_magic_quotes(get_object_vars($user));

    It appears that $user (which is set earlier in the function by pulling the fields from the database), is already an array, so using get_object_vars on it, makes it cease to be an array (at least it did in my case).

    Replacing the above line with

    if (is_array($user)) {
    $user = add_magic_quotes(($user));
    } else {
    $user = add_magic_quotes(get_object_vars($user))
    }

    Solved the problem.

    Is this really a bug? If not, what was causing the problem? Other than for the fix above, I have *NOT* altered any WordPress core files.

    Cheers,

    John

Viewing 1 replies (of 1 total)
  • Thread Starter jhong

    (@jhong)

    Well… it was me.

    I was calling the function from within phpBB.

    It was the call to get_userdata earlier in the function that was causing the problem. A function with the same name exists in phpBB — and didn’t throw any errors when called. However, it doesn’t return an array, whereas the WordPress one does.

    John

Viewing 1 replies (of 1 total)
  • The topic ‘Bug in wp_update_user?’ is closed to new replies.