Skip to content

Instantly share code, notes, and snippets.

@t9nick
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save t9nick/cea8a0479a7199bd2ebb to your computer and use it in GitHub Desktop.
Save t9nick/cea8a0479a7199bd2ebb to your computer and use it in GitHub Desktop.
Displays user name with log out link
<?php
// $Id$
/**
* @file
* Outputs block with simple links to login / logout.
*/
/**
* Implementation of hook_block_info()
*/
function simple_login_block_info() {
$blocks['simple_login'] = array (
'info' => t('User logout / login links'),
'status' => true,
'region' => 'header',
'weight' => 0,
'visibility' => 1,
'cache' => DRUPAL_CACHE_PER_USER,
);
return $blocks;
}
/**
* Implementation of hook_block_view()
*/
function simple_login_block_view($delta = '') {
switch($delta) {
case 'simple_login':
$block['subject'] = '';
$block['content'] = simple_login_contents();
return $block;
break;
}
}
function simple_login_contents() {
if (user_is_logged_in()){
global $user;
$output = t('@username', array('@username' => format_username($user))) . ' | '.l('Log out', 'user/logout');
} else {
$output = l('Login', 'user') . ' | '. l('Create Account','user/register');
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment