Invalid Role in CSV File does not generate error
-
An invalid role in the CSV file generates a user with a role of “none” because there is no check if the role supplied is valid.
I fixed this by changing the section of code currently starting at line 313.
This changes from:if( !empty( $role ) ){ if( is_array( $role ) ){ foreach ($role as $single_role) { $user_object->add_role( $single_role ); } } else{ $user_object->add_role( $role ); } }
to:
$invalidRoles = ''; if( !empty( $role ) ){ if( !is_array( $role ) ) $role[] = $role; foreach ($role as $single_role) { $single_role = strtolower($single_role); if (get_role($single_role)) { $user_object->add_role( $single_role ); } else { $invalidRoles .= $single_role.' '; } } } if ($invalidRoles != ''){ $invalidRoles = trim($invalidRoles); $problematic_row = true; $data[0] = __('Invalid Role','import-users-from-csv-with-meta').' ('.trim($invalidRoles).')'; }
I think that I’m right that roles are always stored internally in lower case, so in addition to the bug fix, I’ve forced the role to be lowercase.
Could be more elegant, but hopefully it does the job
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Invalid Role in CSV File does not generate error’ is closed to new replies.