function views_access

Same name in other branches
  1. 6.x-3.x views.module \views_access()

Determine if the logged in user has access to a view.

This function should only be called from a menu hook or some other embedded source. Each argument is the result of a call to views_plugin_access::get_access_callback() which is then used to determine if that display is accessible. If *any* argument is accessible, then the view is accessible.

3 calls to views_access()
ViewsAccessTest::testDynamicAccessPlugin in tests/views_access.test
Tests dynamic access plugin.
ViewsAccessTest::testMissingAccessPlugin in tests/views_access.test
Tests access for a view with a missing access plugin.
ViewsAccessTest::testStaticAccessPlugin in tests/views_access.test
Tests static access check.
1 string reference to 'views_access'
views_plugin_display_page::execute_hook_menu in plugins/views_plugin_display_page.inc
Add this display's path information to Drupal's menu system.

File

./views.module, line 1112

Code

function views_access() {
    $args = func_get_args();
    foreach ($args as $arg) {
        if ($arg === TRUE) {
            return TRUE;
        }
        if (!is_array($arg)) {
            continue;
        }
        list($callback, $arguments) = $arg;
        $arguments = $arguments ? $arguments : array();
        // Bring dynamic arguments to the access callback.
        foreach ($arguments as $key => $value) {
            if (is_int($value) && isset($args[$value])) {
                $arguments[$key] = $args[$value];
            }
        }
        if (function_exists($callback) && call_user_func_array($callback, $arguments)) {
            return TRUE;
        }
    }
    return FALSE;
}