¿Alguna vez has querido cambiar los nombres de usuario predeterminados de WordPress? Este fragmento de código le permitirá cambiar cualquiera de los nombres de rol existentes, como “Administrador”, “Editor”, etc., por el que desee. Esto se mostrará en el menú de selección de roles para los usuarios. Tenga en cuenta que esto no añade un nuevo rol ni cambia permanentemente el nombre.
Instrucciones
Todo lo que tienes que hacer es añadir este código al archivo functions.php de tu tema o en un plugin específico del sitio:
function wps_change_role_name() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $wp_roles->roles['contributor']['name'] = 'Owner'; $wp_roles->role_names['contributor'] = 'Owner'; } add_action('init', 'wps_change_role_name');
Nota: Si es la primera vez que añade fragmentos de código en WordPress, consulte nuestra guía sobre cómo copiar / pegar correctamente fragmentos de código en WordPress, para no romper accidentalmente su sitio.
Si le ha gustado este fragmento de código, por favor considere consultar Cómo crear un formulario de registro de usuario personalizado en WordPress.
Hello,
How do we revert it? I created a site specific plugin for this, then I deleted it thinking that it was enough to revert back to the default user role label
Hey Cristiano,
If you’ve created the site-specific plugin manually, then you can go ahead and remove the code snippets you’ve inserted onto your plugin editor page.
Alternatively, if you’ve installed the Code Snippets plugin, you can deactivate the specific snippet you’ve added by navigating to Snippets » All Snippets from your WordPress dashboard.
Hello,
Thank you, I deactivated and then removed the plugin but the contributor role, didn’t reverted back. It remains as Owner. Weird, no?
can this be used in multisite wordpress on Version 4.8.2? because i put this code in function.php, its not working on add new user page
[…] snippet (thanks to Kevin Chard!) will let you change any of the existing role names. For example, instead of Contributor you could […]
[…] to Kevin Chard for the […]
Nice function, but good to keep in mind is that the slug of the Role remains the original…
Yes this is true you would need to also change the slug, however at that point it may be better to create a new role rather than change the name of the existing. I still think this has some uses.
Oh I agree, it definitely has some good uses! I just meant that it is something to keep in mind 🙂
Fair enough, and good point 🙂