I am receiving this error when trying to add new capabilities to two of my user roles:
Error: Object of class WP_Role could not be converted to string ... on line 67
The capability I am trying to add will allow the user to see a custom page that we have built in our WP setup. This is the code I have written to populate the roles:
public static function add_csv_capability():void {
$rolesToPopulate = array((get_role( 'administrator' )), (get_role( 'editor' )));
$roles = array_fill_keys(($rolesToPopulate),NULL);
echo $roles;
foreach ($roles as $role) {
if ($role) {
$role->add_cap('use_csv_uploader');
}
}
}
Someone asked if this would answer my question, and it does and it doesn't. It explains what the error is, but now that I know what the error is all about, I need to figure out how to get this code to do what I want, which is to allow me to add capabilities to more than one role.
Any help you can give would be greatly appreciated.
Thanks!