Creating a custom views access plugin I'm trying to create a custom views access plugin, so I can perform my conditions for accessing a view.

I read several tutorials and checked the source of existing modules, but I must be coding/doing something wrong because this never works properly.

Here's the code:

File: sample.module:

function sample_views_api() {
  return array(
    'api' =&gt; 3,
  );
}


File: sample.views.inc:

function sample_views_plugins() {
  $plugins = array(
    'access' =&gt; array(
      'test' =&gt; array(
        'title' =&gt; t('Custom access check'),
        'help' =&gt; t('This is a custom access plugin.'),
        'handler' =&gt; 'sample_access_plugin',
      ),
    ),
  );
  return $plugins;
}

class sample_access_plugin extends views_plugin_access {
  function summary_title() {
    return t('Custom acces plugin');
  }
  function access($account) {
    return sample_access($account);
  }
  function get_access_callback() {
    return array('sample_access', array());
  }
}

function sample_access($account = NULL) {
  return TRUE;
}


I can see the access plugin in views, and I can select it. However, no matter what I do, the access to the view will always be forbidden (access denied). There are no messages in the error log.

Any ideas what's wrong here?

Thanks!
It seems like the sample.views.inc file does not get loaded during the access-check (as the registry already cached the information which callback it needs to execute).

So you can just move sample_access() to the file sample.module and the callback works.