Now-Reading Tweaks

I use Rob Miller’s excel­lent Now-Reading plu­gin to track all the books I’ve read and am read­ing here at Cof­fee­Bear. After my recent site upgrade I decided to tweak the sin­gle book tem­plate for my library. I noticed that the lat­est ver­sion of Now-Reading allows you to note who read a given book on multi­user sites. As my wife occas­sion­ally posts here I wanted my reads to be marked as mine, but the default out­put of the func­tion Rob imple­mented only dis­plays the user’s login name. Seri­ously Rob, what were you think­ing? If you did not want to give end users the option to select how they want their name to print out why wouldn’t you go with display_name?

I looked at the code Rob used and with a lit­tle help from the Prac­ti­cal PHP I hacked together my own func­tion based on Rob’s. By default print_reader2 works the exactly the same as print_reader1 but by feed­ing it an addi­tional para­me­ter, you get your choice of what to use to dis­play as reader’s name:

  • 0: Prints out the user_login aka the user­name you use to log into WordPress.
  • 1: Prints user_nicename, appears to sim­ply be an all lower case ver­sion of the user’s nick­name2.
  • 2: Prints display_name, from the “Dis­play name pub­licly as” field in your Word­Press profile.
  • 3: Prints first_name, from the “First name” field in your Word­Press profile.
  • 4: Prints nick­name, from the “Nick­name” field in your Word­Press profile.
function print_reader2( $echo=true, $reader_id = 0, $display = 0 ) {
	global $userdata;

	$username='';

	switch($display) {
		case "1": if (!$reader_id) { get_currentuserinfo(); $username = $userdata->user_nicename; } else { $user_info = get_userdata($reader_id); $username = $user_info->user_nicename; }; break;
		case "2": if (!$reader_id) { get_currentuserinfo(); $username = $userdata->display_name; } else { $user_info = get_userdata($reader_id); $username = $user_info->display_name; }; break;
		case "3": if (!$reader_id) { get_currentuserinfo(); $username = $userdata->first_name; } else { $user_info = get_userdata($reader_id); $username = $user_info->first_name; }; break;
		case "4": if (!$reader_id) { get_currentuserinfo(); $username = $userdata->nickname; } else { $user_info = get_userdata($reader_id); $username = $user_info->nickname; }; break;
		default: if (!$reader_id) { get_currentuserinfo(); $username = $userdata->user_login; } else { $user_info = get_userdata($reader_id); $username = $user_info->user_login;};
   }
	if ($echo)
		echo $username;
	return $username;
}

Side note: Word­Press 2.5.1 got released today and it includes a secu­rity fix, be sure to update your blogs!

1 At least, I think it does. I’m not a pro­gram­mer and I only know enough PHP to be dan­ger­ous to myself.
2 The Word­Press Codex does not appear to define what this field is used for or why it exists, so that’s just my guess.

Share and Enjoy:
  • del.icio.us
  • Digg
  • StumbleUpon
  • Twitter
  • Reddit
  • Google Bookmarks
  • Facebook
  • MySpace
  • Yahoo! Buzz
  • Print

Similar Posts

  • Now-Reading Tweaks v2
    Some time back, I tried to make Rob Miller's Now-Reading plugin display who's reading each book on t ...
  • Author Pages with hCard & jQuery
    While I'm definitely not the designer that any of the people who created these beautiful hCards, I w ...
  • Whoops!
    Ever since I upgraded CoffeeBear to the newer version of WordPress and my fancy new theme; I noticed ...
  • Updating VectorLover Theme
    I've been posting notes about this under New Look, but figured all the changes deserved their own po ...
  • WordPress/Akismet Hack 0.0.2
    Do you run WP? Do you also have Akismet installed? Would you like a quick reference on the Dashboard ...

About Mark McKibben

Mark is a data analyst for [REDACTED], currently residing in the Midwest. CoffeeBear is a place for him to spout off about whatever catches his fancy. In his spare time, Mark does a bit of webdev & design. To stalk him more effectively, try following him on Twitter.

6 Comments

  1. Mark says:
    April 25th, 2008 at 9:59 pm

    Well as noted above, I’m not a pro­gram­mer. Looks like the orig­i­nal code I posted above only appeared to work because I was logged into my WP install when test­ing it. I’m now try­ing to fig­ure out how to make it really work.

  2. elle says:
    September 12th, 2008 at 2:45 pm

    Hello!

    I’ve been try­ing to get multi­user to work on now read­ing and just dis­cov­ered the forum is no longer around. Search­ing brought me here :)

    Where does it show who is read­ing what? It only seems to dis­play who is view­ing the blog at the time, rather than who is read­ing the book! I’ve been pulling my hair out all day, any help is appre­ci­ated (I’m not exactly a coder lol)

    Also won­der if you know any­thing about hav­ing default meta data? I would like to have the same keys dis­played for users to enter the date so we have some con­sis­tency rather than hav­ing to enter them each time, do you know any­thing about that?

    While I’m here, may as well ask some­thing else lol. Any idea how to get the num­ber of pages read to show up? Rob has it on his blog and I left a com­ment there but I don’t know how often it’s checked

    Thanks for any help :)

  3. Mark says:
    September 12th, 2008 at 5:56 pm

    Unfor­tu­nately my PHP skills were weaker than I thought and this only shows the logged in user. Since you asked about it, I started pok­ing at it again and think I’ve got it work­ing now. See my Now Read­ing Tweaks v2 post for details.

    Sorry, no idea on default­ing in meta data.

    Hmm, I’d guess Rob’s record­ing the pages read in the meta data and then dis­play­ing on his pages using the book_meta() func­tion from the Now-Reading plu­gin (see now-reading/template_functions.php).

  4. elle says:
    September 13th, 2008 at 3:57 am

    hi and thanks Mark. I will go check out your other post :)

    Rea­son I asked about the meta­data and how to make it default was because of this post http://coffeebear.net/archives/2008/06/05/now-reading-default-filters-on-book-meta/
    thought it was worth ask­ing if maybe you were work­ing with them already.

    *wish I had a man­ual* lol

  5. Mark says:
    September 13th, 2008 at 12:59 pm

    Nope, that’s some­thing a bit dif­fer­ent. In that case, Rob changed which of the Word­Press fil­ters he was apply­ing to the meta data. That broke some quick & dirty PHP code I was using, so I made the code change as men­tioned on that post to cor­rect the problem.

    And yeah, a real man­ual for Now-Reading would be great. It’s a really good plu­gin, but to get the most out of it; you just about have to be a PHP programmer.

Trackbacks/Pingbacks

  1. CoffeeBear.net » Now-Reading Tweaks v2

Leave a Reply

This work by Mark McKibben is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States.