Developer role and restricting Admins

Hi Everyone!
I’m new to BF and have been using Bricks for about a year now, never looking back.

Aside form the powerful animation features of BF, I was drawn to the user role editor because I really want to restrict my clients’ access to the builder and styling. I also want the client to keep their “Administrator” roles so they continue to feel important.

I created a Developer role and then restricted access to the builder and other developer related features for the Administrator role. This if course doesn’t restrict the Admin’s ability to assign the Developer role to a new user to I consulted ChatGPT and, Boom!

This snippet restricts the Admin role from assigning the Developer role to other users. Please let me know if you find holes in this approach. Now I just need to restrict access to code snippets…

// Hook into user role update
add_action( 'set_user_role', 'restrict_admin_assign_developer_role', 10, 3 );

function restrict_admin_assign_developer_role( $user_id, $role, $old_roles ) {
    // Check if the current user is an administrator
    if ( current_user_can( 'administrator' ) ) {
        // Check if the role being assigned is Developer
        if ( $role === 'developer' ) {
            // Revert the role to the previous one (assuming you don't want administrators assigning the Developer role)
            $user = new WP_User( $user_id );
            $user->set_role( $old_roles[0] );

            // Display a message to the administrator informing them of the restriction
            add_action( 'admin_notices', 'developer_role_restricted_notice' );
        }
    }
}

function developer_role_restricted_notice() {
    ?>
    <div class="notice notice-error is-dismissible">
        <p><?php _e( 'Administrators are restricted from assigning the Developer role.', 'text-domain' ); ?></p>
    </div>
    <?php
}