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 badges
Add a comment  | 

2 Answers 2

Reset to default 0

I 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