The MU forums have moved to WordPress.org

array_merge() warnings in capabilities.php (48 posts)

  1. bforchhammer
    Member
    Posted 10 years ago #

    I just installed a fresh copy of wpmu 2.7.1 and got the following errors on various pages:

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /wp-includes/capabilities.php on line 539

    Warning: Cannot modify header information - headers already sent by (output started at /wp-includes/capabilities.php:537) in /wp-includes/functions.php on line 689

    Warning: Cannot modify header information - headers already sent by (output started at /wp-includes/capabilities.php:537) in /wp-includes/functions.php on line 690

    First time I saw these errors was when trying to activate a user which I had created as "admin" in the backend. I think I added the new user to the list of SITE Admins which I guess might have caused confusions when activating...

    Later I saw the same errors when adding the same user to a new blog using the "SiteAdmin > Blogs > Edit Blog" page... I was logged in as the new user at that time (does that matter?)

    And another error which I don't remember which page it happened on:

    Fatal error: Call to a member function has_cap() on a non-object in /wp-admin/users.php on line 59

  2. alphawolf70
    Member
    Posted 10 years ago #

    I just upgraded my 2.7 install to 2.7.1 using the auto upgrade feature, and am getting similar errors:

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/html/blogs/wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /var/www/html/blogs/wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /var/www/html/blogs/wp-includes/capabilities.php on line 539

  3. jlencion
    Member
    Posted 10 years ago #

    I also just upgraded from 2.7 to 2.7.1 by downloading and replacing files and I an getting the same errors as alphawolf70 when I visit any of my root blog's admin pages.

  4. jlencion
    Member
    Posted 10 years ago #

    I don't know if this is the best way to fix this bug, but I added this to line 537 of my capabilities.php file in wp-includes:

    if ( is_array($role->capabilities) )

    so that section looks like this:

    if ( is_array($role->capabilities) )
    	$this->allcaps = array_merge( $this->allcaps, $role->capabilities );

    That made the warnings disappear for me. However, the source of the problem may lie somewhere else.

  5. donncha
    Key Master
    Posted 10 years ago #

    jlencion - that hides the problem but doesn't solve it. Can you add this code just before line 537? (before the foreach)
    error_log( print_r( $role, 1 ) );
    Check your PHP error log and paste the debug test to http://pastebin.com/ and link to it here please.

  6. binh
    Member
    Posted 10 years ago #

    I got exactly this same error. But it's not happening just on one of my blog cars.apmart.com The rest seem to be fine.

    Exact same 3 errors right on the homepage.

  7. binh
    Member
    Posted 10 years ago #

    I checked the v2.7.0 capabilities.php file and locate line 537. Found the different and fixed it. As follow:


    # Binh 2.7.1: $role =& $wp_roles->get_role( $role );
    # Fix to:
    $role = $wp_roles->get_role( $role );

    believe me Donncha, the problem lies somewhere and that somewhere is exactly that & sign.

  8. cheeoo
    Member
    Posted 10 years ago #

    also getting this error.

    binh, that's a bad fix. it would be more proper to force (array) type.

  9. jfcarter
    Member
    Posted 10 years ago #

    I'm getting the same error. It is really frustrating not to know what to do.

    Does anyone know what is wrong here?

  10. andrea_r
    Moderator
    Posted 10 years ago #

    Did you try upgrading to 2.7.1?

  11. alphawolf70
    Member
    Posted 10 years ago #

    andrea_r, this was caused by the upgrade to 2.7.1...

  12. andrea_r
    Moderator
    Posted 10 years ago #

    Ah, I think there was a trac ticket on it.

  13. donncha
    Key Master
    Posted 10 years ago #

    Go on, someone with that error - please try to debug it and find what role is missing it's capabilities and we'll fix it. See my instructions above wrt error_log()

    Better still, document steps that will allow *anyone* to reproduce it.

  14. donncha
    Key Master
    Posted 10 years ago #

    How to reproduce:

    1. Set a "non blog user" dashboard blog.
    2. Create a user without a blog. (I created it through the signup form but I think you could probably do it from the backend too)
    3. Login as that user. Everything's fine. Logout again.
    4. Add that user as a site admin.
    5. Login again. Check your php error log. Lots of errors.

  15. donncha
    Key Master
    Posted 10 years ago #

    Looks like the promote_if_siteadmin() function is causing this.

    Commenting out calls to that function fixes this problem.

  16. ctrl_alt_ESC
    Member
    Posted 10 years ago #

    I added error_log( print_r( $role, 1 ) ); before the for each. I see two blank lines before the Warning: array_merge() in the error log

  17. josswinn
    Member
    Posted 10 years ago #

    @donncha is commenting out calls to that function the resolution to this issue or just an indicator to a fix. Commenting out a call doesn't sound like a fix but then what do I know?!

  18. thelaw
    Member
    Posted 10 years ago #

    I'm nailed as well and am having a mapping or crosslinking problem that might be related to this issue. Changing the permissions of a user results in this:

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 539

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 539

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 537

    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/mysite/public_html/wp-includes/capabilities.php on line 539

    Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/mysite/public_html/wp-includes/capabilities.php on line 641

    Warning: array_reduce() [function.array-reduce]: The first argument should be an array in /home/mysite/public_html/wp-includes/capabilities.php on line 641

    Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/wp-includes/capabilities.php:537) in /home/mysite/public_html/wp-includes/pluggable.php on line 856

  19. 3singes
    Member
    Posted 10 years ago #

    donncha :

    foreach ( (array) $this->roles as $role ) {
      error_log( print_r( $role, 1 ) ) ;
      $role =& $wp_roles->get_role( $role );
      error_log( "After =& : ",print_r( $role, 1) ) ;
      $this->allcaps = array_merge( $this->allcaps, $role->capabilities );
    }

    Here is what appeared in my error_log after putting the debug lines into capabilities.php :

    [Sun Apr 26 00:37:08 2009] [error] [client 000] administrator
    [Sun Apr 26 00:37:08 2009] [error] [client 000] After =& :
    [Sun Apr 26 00:37:08 2009] [error] [client 000] subscriber
    [Sun Apr 26 00:37:08 2009] [error] [client 000] After =& :
    [Sun Apr 26 00:37:08 2009] [error] [client 000] administrator
    [Sun Apr 26 00:37:08 2009] [error] [client 000] After =& :
    [Sun Apr 26 00:37:08 2009] [error] [client 000] subscriber
    [Sun Apr 26 00:37:08 2009] [error] [client 000] After =& :

    It looks like =& operator is destroying $role.

  20. Trent
    Member
    Posted 10 years ago #

    Yesterday Donncha put the following submission forward. Does it fix the problem?

    http://trac.mu.wordpress.org/changeset/1764

    Trent

  21. thelaw
    Member
    Posted 10 years ago #

    Hmmm... this seemed to work for me. Thanks donncha!

  22. josswinn
    Member
    Posted 10 years ago #

    Yes, adding 'return 'false;' stopped the error messages for me, too. Thank you.

  23. bmemor21
    Member
    Posted 10 years ago #

    Adding that "return false;" statement fixed this issue for me as well!

  24. mebenson
    Member
    Posted 10 years ago #

    I came here to report the exact same problem. Adding the "return false;" fixed it for me too!

    Thank you.

  25. paynehd
    Member
    Posted 10 years ago #

    I'm running wp 2.7.1...so, were do I put the "return false" statement, ie., what php source file?

    thanks

  26. paynehd
    Member
    Posted 10 years ago #

    FYI,

    forgot to mention in last post, I don't have or can't find the wpmu_functions.php mentioned in http://trac.mu.wordpress.org/changeset/1764...

    That's why I need help...

    thanks

  27. josswinn
    Member
    Posted 10 years ago #

    wp-includes/wpmu-functions.php

    You do have that file :-)

  28. bluee
    Member
    Posted 10 years ago #

    I think I found a typo in wpmu-functions.php. In function promote_if_site_admin the line:
    $user->{$cap_key} = array_merge(array( 'administrator' => '1' ), (array)$user->{$cap_key});
    should be:
    $user->{$cap_key} = array_merge(array( 'Administrator' => '1' ), (array)$user->{$cap_key});
    In other words, a capital A in administrator

  29. yianniy
    Member
    Posted 10 years ago #

    Bluee,

    Thanks for the fix, that worked great!

    The fix is on line 1975 of wpmu-functions.php

  30. alphawolf70
    Member
    Posted 10 years ago #

    The fix from Bluee worked for me too.

About this Topic

  • Started 10 years ago by bforchhammer
  • Latest reply from puppylove