There is no open registration on my site so I would like to hide the Register link that displays at the top to anonymous users. In the past, I have just edited the function that returns those links at the top. I figured there must be a better way but I'm not sure how to do it. Would it be possible to check a variable to see whether user registration is restricted to administrators or not and only create the register link if new account creation is allowed on the site? Currently if someone clicks that link they get an Access Denied. I'd rather not display it at all. Thanks!

Comments

djg_tram’s picture

Sure, very easy (this might come late for you but others might still be interested). Just wrap the innards of the function in an if block:

if (variable_get('user_register', 0)) {}

thekurt’s picture

Status: Active » Closed (fixed)

Thanks djg_tram for the tip. I had the same issue.

In sites/all/themes/admire_grunge/template.php I changed this:

function login_register_links(){
	$login = url(drupal_get_path_alias('user'));
	$register = url(drupal_get_path_alias('user/register'));
	return "<a href=\"$login\">" . t('Login') . '</a>' . " | <a href=\"$register\">" . t('Register') . "</a>";
}

into this:

function login_register_links(){
	$login = url(drupal_get_path_alias('user'));
	$register = url(drupal_get_path_alias('user/register'));
	if (variable_get('user_register', 0)) {
		return "<a href=\"$login\">" . t('Login') . '</a>' . " | <a href=\"$register\">" . t('Register') . "</a>";
	}
	else {return "<a href=\"$login\">" . t('Login') . '</a>';
	}
}

This works fine.

Kurt.