21 Dec
Adjusting Wordpress functions
On Ochblog we're using the K2 theme, as I've mentioned earlyer. This theme uses the wp_register() function in the menu bar, a function wich displays a different link (register or admin) depending on wether you're logged in or not. Since I made a custom profile page, I decided I wanted this to link to;
To do this, I needed to localize the function first.
In Wordpress, al functions are to be found in the wp-includes folder. This particular function is found in the file template-functions-general.php, and goes like this:
function wp_register( $before = '<li>', $after = '</li>' ) {
if ( ! is_user_logged_in() ) {
if ( get_settings('users_can_register') )
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
else
$link = '';
} else {
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
}
echo apply_filters('register', $link);
}
So, I added a few lines of code to add the extra link, and I changed the register link to my custom register page. The new code looks like this:
function wp_register( $before = '<li>', $after = '</li>' ) {
if ( ! is_user_logged_in() ) {
if ( get_settings('users_can_register') )
$link = $before . '<a href="' . get_settings('siteurl') . '/register.php">' . __('Register') . '</a>' . $after;
else
$link = '';
} else {
if (current_user_can(edit_posts))
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
else
$link = $before . '<a href="' . get_settings('siteurl') . '/profile/">' . __('Profile') . '</a>' . $after;
}
echo apply_filters('register', $link);
}
It's nothing fancy, but this just shows how easy Wordpress is to adjust to your needs, if you're not to keen on running the latest version at all times. If you do want to run the latest version, you should realize that this kind of hacks is generally overwritten with the default function on each update.