The view module has a great function when set a menu tab with contextual filter user:uid, so the user that is author of that node will be able to see the content. Lets say for an example the flag module has a view bookmarks, so when a user choose some node to follow/flag it will be available in his user/%/bookmarks.

How can I do this with custom code? I have my code here as a test:

function mymodule_menu() {

    $items = array();   

    $items['user/%/add-news'] = array(
        'title' => 'Hello World',
        'page callback' => 'mymodule_user_news',
        'page arguments' => array(1),
        'access arguments' => array('access content'),

    return $items;

function mymodule_user_news() {
        return 'Hello world';

This "Hello World" everybody can see it. Of course, because I'm using 'access arguments' => array('access content'),

How can I set this page to be visible only for user author?

I'm planning to add here a form, so the user can fill the form and send it to the administrator of the website.

Oh, by the way when I set a link only visible to the author user I use this echo l(t("Profile edit"), 'user/' . $GLOBALS['user']->uid . '/edit');

How can I use the $GLOBALS['user']->uid in a module?

1 Answer 1


Access arguments

Understanding access arguments in Drupal's menu system can be a little confusing, but they are really quite simple. Let's take this example and work through the arguments.

  $items['foo/bar/user'] = array(
    'title' => 'Foobar',
    'description' => 'List, add, and edit Foobars.',
    'page callback' => 'foo_bar_function',
    'access callback' => 'user_access',
    'access arguments' => array('administer users'),

Permissions Arguments, array('this_permission') Here access arguments is the key for an array that contains one item administer users. This means that the current user must have permission to administer users in order to access the page. Which page? Notice the first line gives the path to $item. The path is 'foo/bar/user'.

In this example, 'administer users' is the string that drupal uses to reference permissions. If you go to the permissions page (Administer

User Management >> Permissions), you can see a list of strings you might use for access arguments. Each permission can be used by your module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.