Getting a role based on a localized role name

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

Read More
$admin = get_role('adminstrateur');

Any cross-language solution?

Related posts

Leave a Reply

2 comments

  1. Just guessing, but maybe:

    $admin = get_role( __( 'administrator' ) );
    

    If you’re trying to make sure that WP translates the string for a specific locale, __() will return the translated string. So if get_role('administrator') works and on a French setup get_role('administrateur') would work, then the above code snippet should do what you need.