0

I did dozens of tests, this is the code that I am tring to make work:

$user = get_userdata($user_ID);
    /* WE NEED TO REMOVE BBP ROLES */
    $roles = array();
    global $wp_roles;
    foreach ($user->roles as $key => $role) {
       if (substr($role, 0, 4) != 'bbp_') {
          array_push($roles, translate_user_role($wp_roles->role_names[$role]));
       }
   }

I replaced the parameter passed to translate_user_role with a lot of others but nothing works, neither just:

translate_user_role('Administrator');

or

translate_user_role('administrator');

1 Answer 1

0

Please note that translate_user_role doesn't work in the front-end currently.

Here is a workaround, you can place this in your theme:

add_action( 'init', 'load_admin_textdomain_in_front' )
function load_admin_textdomain_in_front() {
    if ( ! is_admin() ) {
        load_textdomain( 'default', WP_LANG_DIR . '/admin-' . get_locale() . '.mo' );
    }
}
3
  • Hi @JoryHogeveen, thank you for your reply, actually I still need it, so sorry for my long delay as well. I added this code but the role names are not translated yet, maybe is the way I get them, I am trying to insert some roles in an array, I did many tests, such as: array_push($roles, __($wp_roles->roles[$role]['name'], 'default')); or array_push($roles, $wp_roles->roles[$role]['name']);
    – Antonio
    Commented Aug 26, 2016 at 16:43
  • Hi @Antonio, never got a notice of your comment, sorry. You can get all role names with $wp_roles->role_names. Small example to add all roles translated: array_push( $roles, array_map( 'translate_user_role', $wp_roles->role_names ) ) Hope this comment still helps! Edit: Oh, and please accept the answer if it worked for you :) Commented Mar 16, 2017 at 18:55
  • Hello @Jory, thank you so much for your reply, it's still helpful actually. I did another test and I've noticed that now your first reply is enough to translate the roles on the frontend, now I can use translate_user_role($wp_roles->roles[$role]['name']); and it takes effect. Thank you so much!
    – Antonio
    Commented Mar 27, 2017 at 13:09

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.