List permissions which are used in hook_menu, but missing in hook_permission

Public

List permissions which are used in hook_menu, but missing in hook_permission

Get raw version
php
  1. // Script to check if all the permissions defined as a user access callback
  2. // in a hook_menu are also defined in hook_permission.
  3.  
  4. // e.g. You can expect the following output:
  5. // These permissions are used in hook_menu, but not defined in hook_permission().
  6. // Array
  7. // (
  8. // [flush caches] => token/flush-cache
  9. // [use on-page translation] => i18n_string/save
  10. // )
  11.  
  12. $permissions_in_menu = db_query("SELECT access_arguments,path FROM GmVGa5_menu_router WHERE access_callback ='user_access' GROUP BY access_arguments;")->fetchAll();
  13. $defined_permissions = module_invoke_all('permission');
  14.  
  15. $missing_permissions = array();
  16. foreach ($permissions_in_menu as $record) {
  17.  
  18. $perm = unserialize($record->access_arguments);
  19. $perm = $perm[0];
  20.  
  21. if (!array_key_exists($perm, $defined_permissions)) {
  22. $missing_permissions[$perm] = $record->path;
  23. }
  24. }
  25.  
  26. echo "These permissions are used in hook_menu, but not defined in hook_permission().\n";
  27. print_r($missing_permissions);