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?

  • Interesting question. +1 I never noticed this (using german lang installations), but maybe you have/had some role manager, membership or capability editor plugins installed?
    – kaiser
    Apr 5, 2012 at 4:32

2 Answers 2


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.

  • but per my knowledge you need to provide the translation file, no?
    – Omar Abid
    Apr 4, 2012 at 22:30
  • Calling __( 'some text' ) is identical to calling __( 'some text', 'default' ) ... it will use WP's default text domain.
    – EAMann
    Apr 4, 2012 at 23:05
  • I guess it would be (uppercase 1st char) Administrator.
    – kaiser
    Apr 5, 2012 at 4:30
  • It works and not. I'm not really sure but it fixes the bug. Anyway, I'm rewriting the roles class in the future, so that's a temp hack.
    – Omar Abid
    Apr 5, 2012 at 18:50

What you want to use is translate_user_role().


$admin = get_role( 'administrator' );
$localized_name = translate_user_role( $admin->name );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.