Categories
General

Fixing author pages in WP

I just noticed that my author pages at wedin.org were pretty messed up and now that I’ve fixed them I figured I’d make some notes about what I did.

The first problem: Giving the admin a nickname that’s the same as an existing username breaks that user’s author page.

I thought it would be nice to give the admin user the nickname ‘isaac’ because then when I commented on posts without remembering to log out the comments would say ‘isaac’ rather than the Orwellian ‘admin.’ Obviously, I wasn’t thinking straight – one should only do serious admin tasks when logged in as the admin. The danger of making a mistake isn’t the only drawback – it somehow confuses WordPress, breaking the author archive page of the user whose nickname the admin uses. This may only happen with permalinks – I didn’t investigate it extensively.

The solution: Set the admin’s nickname back to ‘admin’ (and log out after doing admin stuff!). Or I guess you could promote your normal user high enough to do most admin tasks.

The second problem: Broken author pages for users with ‘@’ and such in their usernames.

Some of my users have registered using their email addresses as usernames. That shouldn’t be a problem – WordPress allows ‘@’ and ‘.’ in usernames, so it should be able to deal with them, right? Apparently not with permalinks turned on. Without permalinks the author page receives an author ID to identify which posts to show. With permalinks the author page receives the author nicename to identify which posts to get. Unfortunately, the WordPress function the codex suggests using to get the author info is get_userdatabylogin(), which wants (duh) the author’s login. The login has things like ‘@’ and ‘.’ but the nicename does not. So, for my users crazy enough to use their email addresses for login names the author page was showing nothing.

The solution: Rewrite the author page to use this query instead of get_userdatabylogin():

$wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_nicename = '$queried_name'");

This should probably be in a cascade of if…else statements so that turning off permalinks doesn’t break the author page.

Avatar photo

By isaac

I like cats. he/him