I’m looking for a way to link to author pages within one WordPress install simply by putting the @ symbol in front of a person’s username in a post…. just like on twitter.
Example:
If the username is “Bill256” and I write “@Bill256” it will be linked to his author page.
This is a little tricky because
sanitize_user
allows spaces in usernames, meaning it difficult to avoid grabbing the whole phrase ‘@johndoe said that … ‘ as opposed to just the actual username ‘@johndoe’ and you have no separator at the end that would help. To avoid that I imposed a requirement that spaces in the username be replaced with ‘+’.I would not expect this solution to be very robust, not without a lot of tweaking of the regex. And I think you would be better off with a shortcode, but there you go.
Note: It occurred to me that this site has a similar mention-like functionality. When writing a comment, you can notify other users by writing “@username” but usernames here can have spaces as with WordPress. The “spaces” problem here was solved by requiring that spaces just be removed, rather than substituted with “+” signs. That could be another way to solve approach the problem.
Look at the P2 theme. It does this, calling them “Mentions”.
http://themes.svn.wordpress.org/p2/1.4.2/inc/mentions.php