if (CRM_Core_Permission::check('edit all contacts')) { // user is allowed to edit all contacts } else { // user is not allowed to edit all contacts }
if (!CRM_Core_Permission::check('access CiviReport') || !CRM_Core_Permission::check('view all contacts')) { CRM_Core_Error::statusBounce(ts('You do not have permission to view this page.')); }In this example, we are checking if the user has access to CiviReport and can view all contacts. If they don't have both permissions, we are redirecting them to an error page. Overall, CRM_Core_Permission is an essential library to manage user roles and permissions in CiviCRM. It provides a flexible and robust solution to control access to your website's functionality and data.