0

我曾经致力于编辑角色名称和标签名称的功能,但无法编辑角色标签名称

function change_role_name($role_name, $new_role_name, $display_name) {
    global $wp_roles;

    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    $role =& get_role($role_name);

    $wp_roles->roles[$role]['name'] = $new_role_name; //not working for editing role label name
    $wp_roles->role_names[$role] = $display_name;           
}
4

1 回答 1

-1

You could remove the old role and add a new one with the same capabilities. Though, this saves directly to the database instead of on the fly, so be careful.

function change_role_name( $old, $new, $new_display ) {
    $old_role = get_role( $old );
    $new_caps = $old_role->capabilities;

    remove_role( $old );
    add_role( $new, $new_display, $new_caps );
}
于 2012-08-01T02:35:13.090 回答