Quantcast
Viewing all articles
Browse latest Browse all 2

Different links for authenticated and anonymous users in Drupal: drupal_goto

The drupal_goto() drupal function (all 4.x-7.x) can be useful in many situations, here a simple example to place in your template.php theme file.

function conditional_user_goto() {
	$output = '';
	global $user;
	if (in_array('authenticated user', array_values($user->roles))) {
		$path = 'user/' . $user->uid . '/some/user/based/link';
		drupal_goto($path);
	}
	else {
		$output = t('<a href="@login">Login</a> or <a href="@register">register</a> to Some User Based Action.',
            array('@login' => url('user/login', 'destination=alerting'),
            '@register' => url('user/register', 'destination=alerting')));
	}
	return $output;
}

Using print conditional_user_goto(); somewhere in your code (e.g. within a PHP block) will display a link to some user page (e.g. user page itself, tracks or subscription interface) to authenticated users, and a translatable “Login or register” message to anonymous users (I take this code from Job Posting module).


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 2

Trending Articles