'How to prevent a modal from opening to everyone but the admin

I have a modal that opens when clicked to display customer data. Currently, the modal opens to all users. However, it displays a permission error "Permission not allowed." to all users except the admin which is fine but I need to prevent the modal from opening entirely for these other users.

The code:

print '<div class="per-customer-div cursor-pointer" data-load-modal="Customers.add_new" 
data-parameter-id="'.(int)$customer['customer_id'].'">';

I tried wrapping the Customer.add_new inside this condition but the issue is that it prevents even the admin from opening the modal.

Here is how I did it:

print '<div class="per-customer-div cursor-pointer"';?> <?php if ( user_can( $current_user, "administrator" )): 
    print 'data-load-modal="Customers.add_new"';
    endif; 
print 'data-parameter-id="'.(int)$customer['customer_id'].'">';


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source