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 '12 at 4:32

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 '12 at 22:30
  • Calling __( 'some text' ) is identical to calling __( 'some text', 'default' ) ... it will use WP's default text domain. – EAMann Apr 4 '12 at 23:05
  • I guess it would be (uppercase 1st char) Administrator. – kaiser Apr 5 '12 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 '12 at 18:50

Your Answer

