Display function get_user_role and get_author_role in Portuguese

0

I'm developing a Wordpress application that uses the get_author_role function, however I'm not able to make it appear in Portuguese.

The first function modifies the default names:

function change_role_name() {
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    // Administrador - tem acesso a virtualmente todas as funções de administração.
    $wp_roles->roles['administrator']['name'] = 'Administrador';
    $wp_roles->role_names['administrator'] = 'Administrador';

    // Editor - pode publicar e gerenciar posts e páginas, além de gerenciar posts de outros usuários.
    $wp_roles->roles['editor']['name'] = 'Moderador';
    $wp_roles->role_names['editor'] = 'Moderador';

    // Autor - só pode publicar e gerenciar seus próprios posts.
    $wp_roles->roles['author']['name'] = 'Suporte';
    $wp_roles->role_names['author'] = 'Suporte';

    // Colaborador - pode escrever e gerenciar suas posts, mas não publicá-los: são enviados para revisão de além com função superior.
    $wp_roles->roles['contributor']['name'] = 'Estagiário';
    $wp_roles->role_names['contributor'] = 'Estagiário';

    // Assinante - só pode gerenciar o próprio perfil, mas não escrever posts. Útil para marcação de favoritos, gerenciamento de comentários, etc.
    $wp_roles->roles['subscriber']['name'] = 'Membro';
    $wp_roles->role_names['subscriber'] = 'Membro';
}

add_action('init', 'change_role_name');

The second shows what the author's level is:

function get_author_role() {
    // https://stackoverflow.com/questions/10489214/getting-an-authors-role-in-wordpress
    global $authordata;
    $author_roles = $authordata->roles;
    $author_role = array_shift($author_roles);
    return $author_role;
}

I call the function with the code below:

<?php echo get_author_role(); ?>

The problem begins when and to display the get_author_role function instead of administrator .

I have tried every method available on the internet, tried the translate_user_role however it did not work.

    
asked by anonymous 16.09.2018 / 05:27

1 answer

0

After 8 days searching for a solution, I was able to resolve it by looking at the wordpress website.

Solution link: By Vladimir Garagulia (@shinephp)

Assuming that $ authordata contains an array of valid author user roles

function get_author_role_name()
{
    global $authordata;

    $author_roles = $authordata->roles;
    $role = array_shift($author_roles);
    $wp_roles = wp_roles();
    // take role display name by role ID
    $role_name = $wp_roles->role_names[$role];

    return $role_name;
}

Use this function, then where you want to output the display name of the author role.

    
24.09.2018 / 16:28