User Greeting

After the user logs in, the WSG says that we should greet them by first name and provide a Logout link. I accomplished this by creating a block named Greeting.

The block contents consist of two divs, one for the greeting and one for the Logout button. These are wrapped in another div and positioned side-by-side using float:left; and float:right; CSS directives.

The user's first name is printed via PHP code, thusly:

Hello <a href="/user"><span class="iac-username"><?php $n = explode(' ', $user->name); print $n[0]; ?></span></a>.

The span element lets us style the user's name (in this case using bold font. The PHP snipped breaks up the user's name by spaces, and prints the first word. Thus a user name of John Q. Public is printed as John. The first name is also hyperlinked to the user's account page, so that if they click on their name they will see their profile information.

The Logout button is implemented as an HTML form, thusly:

<form action="/user/logout"> <input type="submit" value=" Logout " class="form-submit"/> </form>

To ensure that this block is only displayed to logged-in users, I added the following PHP code to the block editor's Show block on specific pages dialog:

<?php global $user; return ($user->uid > 0); ?>