admin管理员组文章数量:1122832
function wpmudev_custom_change_role_names_multisite() {
// Obtener los roles de la red
$wp_roles = get_site_option('wp_user_roles');
// Verificar si los roles existen
if ( isset( $wp_roles['wqer'] ) && isset( $wp_roles['editor'] ) ) {
// Cambiar los nombres
$wp_roles['wqer']['name'] = 'Owner';
//$wp_roles['wqer']['capabilities']['manage_network'] = true; // Agregar capacidad para multisitio
$wp_roles['editor']['name'] = 'Creador de Contenido';
// Actualizar los roles en la red
update_site_option('wp_user_roles', $wp_roles);
}
}
add_action('init', 'wpmudev_custom_change_role_names_multisite');
This feature only works for a simple wordpress installation. I am looking to apply this same function but in wordpress multisite.
function wpmudev_custom_change_role_names_multisite() {
// Obtener los roles de la red
$wp_roles = get_site_option('wp_user_roles');
// Verificar si los roles existen
if ( isset( $wp_roles['wqer'] ) && isset( $wp_roles['editor'] ) ) {
// Cambiar los nombres
$wp_roles['wqer']['name'] = 'Owner';
//$wp_roles['wqer']['capabilities']['manage_network'] = true; // Agregar capacidad para multisitio
$wp_roles['editor']['name'] = 'Creador de Contenido';
// Actualizar los roles en la red
update_site_option('wp_user_roles', $wp_roles);
}
}
add_action('init', 'wpmudev_custom_change_role_names_multisite');
This feature only works for a simple wordpress installation. I am looking to apply this same function but in wordpress multisite.
Share Improve this question edited Sep 20, 2024 at 20:16 Edgar Rodriguez asked Sep 20, 2024 at 20:10 Edgar RodriguezEdgar Rodriguez 112 bronze badges2 Answers
Reset to default 0I have made minor changes which can help you in achieving your desired results. We need to use network_admin_menu
hook instead of init
and also updated the condition of checking if the roles exist.
<?php
function wpmudev_custom_change_role_names_multisite() {
// Here we are getting the roles of the network.
$wp_roles = get_site_option('wp_user_roles');
// Here we are checking if the roles exist.
if ( isset( $wp_roles['administrator'] ) && isset( $wp_roles['editor'] ) ) {
// Change the names
$wp_roles['administrator']['name'] = 'Owner';
$wp_roles['editor']['name'] = 'Creador de Contenido';
// Here we have updated the roles in the network.
update_site_option('wp_user_roles', $wp_roles);
}
}
add_action('network_admin_menu', 'wpmudev_custom_change_role_names_multisite');
After much research I achieved my goal with this fragment.
function cambiar_nombres_roles1($idRol, $nameRol) {
global $wpdb;
$blog_id = get_current_blog_id();
$table_prefix = $wpdb->get_blog_prefix($blog_id);
$roles_option = $table_prefix . 'user_roles';
$roles = get_option($roles_option);
if ($roles && isset($roles[$idRol])) {
$roles[$idRol]['name'] = $nameRol;
update_option($roles_option, $roles);
}
}
本文标签: pluginsHow can I rename roles in a WordPress multisite installation
版权声明:本文标题:plugins - How can I rename roles in a WordPress multisite installation? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288994a1928210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论