Skip to content

Instantly share code, notes, and snippets.

@martsie
Created January 25, 2017 10:17
Show Gist options
  • Save martsie/6b9e2775efbc90f1afd0abf7c40a50ca to your computer and use it in GitHub Desktop.
Save martsie/6b9e2775efbc90f1afd0abf7c40a50ca to your computer and use it in GitHub Desktop.
A simple implementation of a custom permission check in hook_init in Drupal 7
<?php
/**
* Implements hook_init().
*
* Runs every time a page is requested on the site.
*/
function my_custom_module_init() {
if (user_access('my custom permission')) {
drupal_set_message(t('User has my custom permission'));
}
else {
drupal_set_message(t('User does not have my custom permission'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment