Tag Archives: Plugins

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.

Library Fixed and Other Changes

The library issues I was having appear to be resolved. When I upgraded WordPress, I simply overwrote the existing files (‘cuz I’m lazy) and then I went into my permalink settings and hit the update button (without actually making any changes). This is supposed to be enough to get the plugin I use for the library to reset the permalinks but that didn’t happen this time. I ended up deleting all of WordPress’ core file, re-uploading them, changing my webhost’s configuration to support PHP5, upgrading to the very latest copy of the plugin and re-saving my permalink settings before I was able to get the library working correctly again.

Other Changes

I also noticed when I upgraded/changed themes last time I forgot to add back in the magic codes to have ads from Google AdSense appear in a couple of places on my site. Those are ads are now back, though I do use another plugin to hide them from regular readers and on current content. Basically, if you are just stopping by (e.g. found me via a search engine) you will see ads. If you’ve been here a few times in the past couple of weeks, then you most likely won’t. Mind you these ads aren’t making me rich1, but they do help offset the costs of my online addiction webhosting.

New Theme

Yeah, I wasn’t a big fan of the previous theme I was using but it was good enough for a short term solution. The current theme2 is better but still needs more tweaks to make it mine. Things are likely to be in a state of flux until further notice around here. Things I still need to do:

  • Add one or more random photos to the sidebar or possibly the footer.
  • Work up a better header image.
  • Style the footer more to my liking.
  • Fix the sidebar formatting issues in IE3

1 I haven’t even had enough clicks on the silly Google AdSense ads to get paid yet
2 In case you happen to be curious, it’s a slightly tweaked version of the Shades of Gray style for the Sandbox theme.
3 Odds of this happening are tiny. I only use IE at work and then only rarely. If the slight offsets in the sidebar offends your design sensibilites, get Firefox!

WordPress Plugins: PHPInfo and PluginsUsedPlugin

I’ve been working on some stuff behind the scenes here at CoffeeBear.net with the intention of eventually upgrading the site’s backend and developing a new theme for the site. In the process of doing all this behind the scenes works, I’ve been trying out new plugins and wanted a quick way to check my server’s setup without putting a page for just anybody to view (e.g. creating my own phpinfo page). I found this a plugin by Designpraxis which basically adds the output from phpinfo to WordPress’s admin panel. Unfortunately, it buries the page/info under the Options panel. So I hacked it up to move the output under the Dashboard panel. Then I thought, it would be great if it could also list off all the plugins my site uses and what version of those plugins. I already have the pluginsUsedPlugin installed but it didn’t support plain-text output. So I hacked it up to output in plain-text, hacked up Phpinfo to include that plain-text output and then there was much rejoicing.

I thought it only fair to share my hacks, so enjoy or not as you choose. I’m sure there’s a more elegant way to code these changes, but I am not a programmer so if you use these and don’t like how I changed them… Well, you just have to suffer then. :p Feel free to ask questions but keep in mind:

  • I’m not a programmer.
  • These plugins aren’t originally mine. I don’t know much about how they work. I only know enough to hack together my changes.
  • If my hacked versions don’t work for you, try the originals before asking me for help. The people who made the originals should have a better idea of why things work/don’t work.

CoffeeBear’s Hacked Plugins

Text-Link-Ads Updated

Text-Link-Ads is a nice service which I use to help pay the bills for running this site. They just released a new version of their WordPress plugin which I use to put their adverts on this site, so I installed it but in doing so it overwrote a couple of changes I’d made to the old plugin. I had made those changes as I like the service and I definitely like the additional income1, but I don’t like how the plugin makes the ad links less than obviously ads. So my changes in the plugin add a specific class which I can then style via CSS. Since I don’t want to have to keep redoing my customizations from scratch each time they release the plugin; I’m posting the code changes I make here.

Under function outputHtmlAds(), I changed the following line of code from:
echo "\n<ul>\n";</ul>

echo "\n<ul class=\"tla_sponsor_link\">\n";</ul>

Also under function returnPostAd($postId), I changed:
return "\n\n<em>".$prefixes[$prefixIndex].":</em> $ad->before_text <a href=\"$ad->url\">$ad->text</a> $ad->after_text";

return "\n\n<div class=\"tla_sponsor_link\"><em>".$prefixes[$prefixIndex].":</em> $ad->before_text <a href=\"$ad->url\">$ad->text</a> $ad->after_text</div>";

Side note: TLA, you guys should change the Our Blog to be called something else as the link doesn’t actually take users to your blog.

1 I don’t make enough from these ads to get rich mind you. Just enough to cover the costs of running CoffeeBear.net and maybe a cup of good coffee from my local coffee shop.

Convert from AMM to Now Reading

As part of my upgrading to the latest/greatest version of WordPress, I switched over to using the Now Reading plugin from AMM. I switched because development on AMM seems to have come to a complete halt and it was acting somewhat flaky prior to the upgrade. One of the big problems with switching over was I didn’t want to have to manually enter in all books I’d already read and rated. As Now Reading supports storing so much more data, I had to write a bit of custom SQL to import my existing info. It’s not a great solution, mostly because AMM didn’t store all of the same info (e.g. date entered, started and finished).
INSERT INTO wp_now_reading(b_added, b_started, b_finished, b_title, b_nice_title, b_author, b_nice_author, b_image, b_asin, b_status, b_rating, b_review)
SELECT amm_dateadded, amm_dateadded, amm_dateadded, amm_title,
REPLACE(REPLACE(LCASE(amm_title), ',', '' ), ')', '' ), '(', '' )
, ' ', '-' ), '...', '-' ), ':', '-' )
, '!', '-' ), '?', '-' ), '&', '-' )
, '\'', '' ), '--', '-' ), amm_author, REPLACE(REPLACE(REPLACE( LCASE( amm_author ) , '.', '' ) , '&', 'and' ) , ' ', '-' ), amm_smallImageURL, amm_asin, 'read', amm_rating *2, amm_userComments
FROM wp_amm amm
WHERE amm_ProductGroup = 'Book' AND amm_asin NOT IN (SELECT b_asin FROM wp_now_reading);

This short script copied over all my books for me and got everything setup as well as could be expected given the differences in the data. Below is a list of the assumptions I made in writing this script to convert to Now Reading:

  • AMM only stores one date, so I used that for all dates on the books I copied over.
  • The above script limit itself to books and skips any already in your wp_now_reading table.
  • Now Reading has additional fields the title & author. I’m not sure what the “b_nice_author” field is used for, but the “b_nice_title” is used when you go to edit a specific book. The format of the “b_nice_” fields seems to be to replace anything other than a letter or a number with a hyphen and to have all the letters be lower case. I tried to make sure I did the same with my script, however you may need to double-check your data before running this to make sure I didn’t miss a symbol you used.
  • I marked all the books I was copying over as “read”.
  • AMM only allowed ratings of 1 – 5; while Now Reading allows 1 – 10. So when I copied the ratings over, I doubled them.

NOTE: If you have questions about this script, post them in the comments here. Keep in mind that I’m not providing full fledged support for the script and if you don’t know how to run this without asking, then you probably shouldn’t be messing with it. Also, if you’re really going to try running this script, then for god’s sake backup your database FIRST!

Copyright © 2004 – 2020 CoffeeBear.net. Powered by WordPress.