﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
9128,array_merge() Error when Adding Roles via Plugins,johnkolbert,,"Scenario:
Adding a new user role that has the same capabilities as the ""Administrator"" role.

Code Used:

{{{
global $wp_roles;
$admin_role = $wp_roles->get_role(""administrator"");
$wp_roles->add_role(""superadmin"", Super Admin, $admin_role->capabilities);
}}}
 
Error Encountered:

{{{
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /Applications/MAMP/htdocs/wp2pt7/wp-includes/capabilities.php on line 537

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /Applications/MAMP/htdocs/wp2pt7/wp-includes/capabilities.php on line 537

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /Applications/MAMP/htdocs/wp2pt7/wp-includes/capabilities.php on line 539
}}}

Suggested Fix:

PHP 5.0 is sensitive for array_merge only using arrays. By using typecasting you can merge other types.

Here's what capabilities.php should be for lines 534-539:

{{{
$this->allcaps = array();
		foreach ( (array) $this->roles as $role ) {
			$role =& $wp_roles->get_role( $role );
			$this->allcaps = array_merge( (array)$this->allcaps, (array)$role->capabilities );
		}
		$this->allcaps = array_merge( (array)$this->allcaps, (array)$this->caps );

}}}


Notice the addition of the (array) typecast in the array_merge functions.",defect (bug),closed,normal,3.0,Role/Capability,2.7,major,fixed,has-patch commit,
