# Setting Site-Specific Hooks

The LiveJournal code provides a number of hooks, which you can use to alter or extend the functionality of the code, tailored for your own site. You're free to implement as few or as many as you want.

If there's a hook you want but don't see, email us at dev@livejournal.com or file an issue in our Bug and Project Tracking System and we'll be more than happy to add it in.

One of the reasons for implementing hooks on LiveJournal came from a need to make distinctions between account status types, without leaving a lot of kludge in the code base, and without having to write extensive code libraries in the ljcom CVS repository.

Hooks are code references, subroutines that perform functions or return information based on objects passed to the subroutine. Some programming knowledge is necessary to write your own hooks.

## Writing Hooks

Hooks are written either in your `cgi-bin/ljconfig.pl` file, or in a seperate site-specific library file. Hooks are defined by the function `LJ::register_hook()`, which takes two arguments: the name of the hook, and the hook's perl coderef.

Most hook coderefs are passed a single hash of various objects as their argument, though there are a few exceptions. Consult for more information.

### Sample hook: userinfo_html_by_user

To give you an idea of how a hook is set up, a smaller hook is sampled below:

    LJ::register_hook("userinfo_html_by_user", sub {
        my $o = shift;
        my $r = $o->{'ret'};
        my $u = $o->{'u'};
        return unless (LJ::get_cap($u, "normal"));
        $$r .= "<img src='$LJ::IMGPREFIX/talk/sm08_star.gif' width='20' height='18' alt='&#8902;' style='vertical-align: middle; border: 0;' />";
            });

`$o` is the argument hash that is passed to the hook's subroutine, and consists of the scalar reference member `$o->{'r'}` and the user object member `$o->{'u'}`. The subroutine then checks to see if the user is part of the capability class normal, and if so it will pass the HTML image directive as the scalar reference. Now when someone loads a user information page for a normal user, a small star will appear next to their username and userid.

## Hooks Reference

&lj.customize.hooks.ref;