[wp-trac] [WordPress Trac] #9128: array_merge() Error when Adding Roles via Plugins

WordPress Trac wp-trac at lists.automattic.com
Sat Feb 14 07:16:34 GMT 2009


#9128: array_merge() Error when Adding Roles via Plugins
----------------------------+-----------------------------------------------
 Reporter:  johnkolbert     |       Owner:  anonymous
     Type:  defect (bug)    |      Status:  new      
 Priority:  normal          |   Milestone:  2.7.2    
Component:  Administration  |     Version:  2.7      
 Severity:  major           |    Keywords:           
----------------------------+-----------------------------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9128>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list