Now-Reading Tweaks

I use Rob Miller’s excellent Now-Reading plugin to track all the books I’ve read and am reading here at CoffeeBear. After my recent site upgrade I decided to tweak the single book template for my library. I noticed that the latest version of Now-Reading allows you to note who read a given book on multiuser sites. As my wife occassionally posts here I wanted my reads to be marked as mine, but the default output of the function Rob implemented only displays the user’s login name. Seriously Rob, what were you thinking? 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 little help from the Practical PHP I hacked together my own function based on Rob’s. By default print_reader2 works the exactly the same as print_reader1 but by feeding it an additional parameter, you get your choice of what to use to display as reader’s name:

  • 0: Prints out the user_login aka the username you use to log into WordPress.
  • 1: Prints user_nicename, appears to simply be an all lower case version of the user’s nickname2.
  • 2: Prints display_name, from the “Display name publicly as” field in your WordPress profile.
  • 3: Prints first_name, from the “First name” field in your WordPress profile.
  • 4: Prints nickname, from the “Nickname” field in your WordPress profile.
function print_reader2( $echo=true, $reader_id = 0, $display = 0 ) {
	global $userdata;


	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: WordPress 2.5.1 got released today and it includes a security fix, be sure to update your blogs!

1 At least, I think it does. I’m not a programmer and I only know enough PHP to be dangerous to myself.
2 The WordPress Codex does not appear to define what this field is used for or why it exists, so that’s just my guess.


Comments are closed.

Well as noted above, I’m not a programmer. Looks like the original code I posted above only appeared to work because I was logged into my WP install when testing it. I’m now trying to figure out how to make it really work.


I’ve been trying to get multiuser to work on now reading and just discovered the forum is no longer around. Searching brought me here 🙂

Where does it show who is reading what? It only seems to display who is viewing the blog at the time, rather than who is reading the book! I’ve been pulling my hair out all day, any help is appreciated (I’m not exactly a coder lol)

Also wonder if you know anything about having default meta data? I would like to have the same keys displayed for users to enter the date so we have some consistency rather than having to enter them each time, do you know anything about that?

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

Thanks for any help 🙂

Unfortunately my PHP skills were weaker than I thought and this only shows the logged in user. Since you asked about it, I started poking at it again and think I’ve got it working now. See my Now Reading Tweaks v2 post for details.

Sorry, no idea on defaulting in meta data.

Hmm, I’d guess Rob’s recording the pages read in the meta data and then displaying on his pages using the book_meta() function from the Now-Reading plugin (see now-reading/template_functions.php).

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

Reason I asked about the metadata and how to make it default was because of this post
thought it was worth asking if maybe you were working with them already.

*wish I had a manual* lol

Nope, that’s something a bit different. In that case, Rob changed which of the WordPress filters he was applying to the meta data. That broke some quick & dirty PHP code I was using, so I made the code change as mentioned on that post to correct the problem.

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

[…] time back, I tried to make Rob Miller’s Now-Reading plugin display who’s reading each book on the individual […]

Copyright © 2004 – 2021 Powered by WordPress.