I use the following code to get the Administrator role
$admin = get_role('administrator');
This works fine, but on a different WordPress language setup, this code breaks. For example, in French it should be
$admin = get_role('adminstrateur');
Any cross-language solution?
Just guessing, but maybe:
If you’re trying to make sure that WP translates the string for a specific locale,
__()
will return the translated string. So ifget_role('administrator')
works and on a French setupget_role('administrateur')
would work, then the above code snippet should do what you need.What you want to use is
translate_user_role()
.https://developer.wordpress.org/reference/functions/translate_user_role/