How to add custom user role into wordpress

Example:

add_role('student', __(
        'Student'),
        array(
            'read'            => true, // Allows a user to read
            'create_posts'      => false, // Allows user to create new posts
            'edit_posts'        => false, // Allows user to edit their own posts
            'edit_others_posts' => false, // Allows user to edit others posts too
            'publish_posts' => false, // Allows the user to publish posts
            'manage_categories' => false, // Allows user to manage post categories
            )
     );
    

Please also consider removing admin bar for certain users:

function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}
add_action('after_setup_theme', 'remove_admin_bar');

Take a look are your “ld” keys hooked right. If they are not, wp could clash.