Header-Rotator

A few late night tweaks to the header image logic: I’ve created as simple a plugin as possible that lets me have three of my own images randomly appear in the heading. Based on the TwentyTen Header Rotator plugin, I ripped out all the code other than the logic to hook into the WordPress framework and the last line to pick an image at random. For my first pass, I hard-coded threefour images (a full moon on a snowy evening, a frosty window and a full batch of cherries, all taken at home) to load up the array. Got it working. That’s the first sanity check. It will be followed with admin pages, setting pages, the ability to upload and resize your own images, etc.

I tried to keep it as close to “the simplest thing that would work” for a first pass, but I left a little complexity in there: the list of images is an array of one-element arrays because the main theme uses something similar where you can store more information about each image, such as a thumbnail location. I figured I’d eventually need to add that back in there, so I left the structure in place. Here’s the core code that gets it to work:


if(!is_admin()) add_filter('theme_mod_header_image','trhr_rotate');
 
function trhr_rotate(){
$imagelist = array(
0 => array('url' => home_url('/wp-content/uploads/2011/03/cropped-DSCN1285.jpg')),
1 => array('url' => home_url('/wp-content/uploads/2011/03/cropped-DSCN1288.jpg')),
2 => array('url' => home_url('/wp-content/uploads/2011/02/cropped-SnowMoon.jpg')),
3 => array('url' => home_url('/wp-content/uploads/2010/07/cherries.jpg')),
);
return $imagelist[rand(0,count($imagelist)-1)]['url'];
}

Thanks to the Seacoast WordPress Developers group for the inspiration, and also some cool ideas from Smashing Magazine’s “Ten Things Every WordPress Plugin Developer Should Know

TwentyTenFive theme

Readers shouldn’t notice too much of a change as I switched from the TwentyTen default theme for WordPress 3.x to the TwentyTenFive theme by Richard Shepard. It was originally developed as this article for Smashing Magazine, and then took on a life of its own. The theme is available for download and modification from GitHub.com. I was pleased to be able to contribute a minor fix (a really tiny fix, consisting of two dots and a slash, but in the right place). Hope to contribute more as I learn more about WordPress internals.

TwentyTen Header Rotator Follow-up

Ah, the power of the web. I posted the problem I was having both here and on the WordPress.org web site, and within a week, another developer pointed out the simple one word addition to the plugin code to make it work in WordPress 3.1. Problem solved!

Now that I’ve spent some time poking at the code, and inspired by the “How to Build a Plugin” presentation at last Seacoast WordPress Developer’s meeting, I’m thinking of a fancier plugin that will let you load up as many images as you want and shuffle them. Inspiration is one thing, perspiration is another; I’ve got enough on my plate right now that this is a pretty low-priority issue. And there’s the challenge of feature creep: it would be nice if I could link each header to page that described the significance of the picture, had its licenses, etc. And that you could load up multiple pictures and enable/disable them individually for seasonal themes or special events. And… oh, dear.

Seacoast WordPress Developers meeting, 2-March-2011

Five people attended the March meeting of the Seacoast WordPress Developer‘s meetup, held at the New Hampshire innovation Commercialization Center near Pease in Portsmouth. We did a round of introductions and welcomed two new members and discussed what the group could focus on. We discussed the boundaries of CMS and Blogging and Wikis and how they overlap (A professional in education provided us with some great insights on how we think about some of these items), the challenge in finding consultants and clients, and how we can build up a network. We talked about potential agenda items: what should we schedule, what should we have in free-form.
I think an FAQ we ought to be prepared to answer is “What is it that WordPress is?” It’s less than obvious. “A blog” is the wrong answer, as that is a form of document, and not an application. “A CMS” is such a vaguely defined answer that it’s not much more useful than “an application.”

Other questions we started to explore, and possible future topics:

  • What is it that others are looking for on the web?
  • Good resources for learning WordPress: Codex, FAQ, books, etc.
  • WordPress SEO
  • WordPress Security
  • Loop/structure of databases tables, templates
  • Popular plugins
  • WordPress Backup tips: data and files
  • WordPress Community

Finally, Amanda presented her talk on building a plugin. She’d done some excellent research and used clear examples and explained them well. Here are the notes and slides posted to the new Seacoast WordPress Developer’s website, running WordPress, of course, and BuddyPress.

So, it was a great second meeting of the Seacoast WordPress Developer’s group. Stay tuned for more news. Thanks to Amanda for organizing the event, and to the New Hampshire Innovation Commercialization Center for providing the great facilities!

Color vim on CygWin

I’ve had to do some admin work on a Windows 2008 R2 server and found it handy to have a POSIX environment installed on Windows so I have ssh, grep, rsync, git, bash, vim and other functionality available all working within the same shell.

While vim was functional, the terminal was one that vim didn’t recognize as color, and hence the editor was only black and white and a few shades of gray. A little Googling returned this page: http://infrablue.tripod.com/cygwin.html with instructions on using rxvt as the terminal and configuring bash to run within it. A few tweaks, and I’m running vim and editing in color!

[UPDATE] @mintty_cygwin on twitter was kind enough to point out that rxvt development is pretty much stopped, but that the project http://code.google.com/p/mintty/ offered yet another TTY to run on Windows. This one has some pretty cool options, and is easy to install. I’m up and running with it now!

WordPress updated to version 3.1

A new version of WordPress is available, and I’ve updated the blog to version 3.1 and downgraded it again. It seems like some of my custom hacks didn’t make the transition as smooth as I’d like. A good lesson there: always make backups; they’re handy for quick rollbacks. Check out some of the new features, listed here.

It appears that the Header Image Rotator (http://wordpress.org/extend/plugins/twenty-ten-header-rotator/) is the problem. I’ve disabled it, got the update working, re-enabled it and it broke again. Sure enough. I’ve let the author know about the problem and the error messages in my logs. Let’s hope for a painless fix. In the meantime, I’ll post a favorite old picture of mine, taken on a cold snowy night.

Updated Planet Fox

The Venus aggregator is a Python program which will read in a list of RSS feeds and generate an HTML stream-of-news page that displays the posts, most recent first. Planet Fox (http://www.tedroche.com/planetfox/) uses the list of blogging FoxPro folks posted to the FoxPro Wiki as its source. Add yourself to the Wiki and your posts will appear in the aggregator. Thanks to one of Planet Fox’s regular readers for pointing out that Jim Nelson’s great PEMEditor blog was not on the list; it turned out the Wiki post incorrectly listed the location of the RSS feed. I’ve updated that manually, and you can see Jim’s posts.

Notes from NH Ruby/Rails, 21-Feb-2011

Eight attendees made it to the February meeting of the New Hampshire Ruby Rails group at the New Hampshire Innovation Commercialization Center. A round of introductions included the usual suspects and several new people with interesting backgrounds and interests.

Brian Turnbull talked about Ruby debugging. He had a sample he created on Github Ruby comes with it’s own debugging library, but you can add a good one with a gem: ruby-debug.
Commands:
list – lists the code currently load
next – steps through the code listed, but skips over subroutines.
step – steps into the code
where – dumps the stack
finish – finishes the current subroutine call
display – dumps a value
(commonly use display value.inspect to make a cleaner display)
pp – pretty print, evaluates any Ruby code you want
edit – launches the EDITOR variable in our shell
catch – catch exceptions
cont – continue
break – set a breakpoint

,,, and so forth. Use the help, it is your friend.

The second example is far more complex, with a Sinatra app using OmniAuth and an LDAP provider. Following the supplied documentation, the app crashes on startup. (That’s what you get for reading the docs!) Debug and another tool – rbtrace to the rescue! Excellent demo of the problem and how the tools can debug them.

Fail2Ban more skript kiddies poking 404 files

I review my web server logs pretty regularly, and there’s a pattern of 404′s I’ve seen recently that I haven’t been blocking up until now: searching each directory for ‘contact.php’ or ‘setup.php’ — the latter often searching for every variety of phpMyAdmin. I don’t have PMA on my machine, but I’d sure make sure I read all the instructions and removed setup.php if I had! (And you should, too!) I found this link that adds a simple test and rules using Fail2Ban to temporarily banning sites that hit too many 404′s too fast. I’ll have to see if this bonks too many search engines.

http://www.barbarycodes.com/2010/10/06/automated-banning-of-script-kiddies-with-fail2ban/

“That shouldn’t break anything…”

I changed one of the settings on the web server. I had it set to redirect from the older location of this blog http://www.tedroche.com/blog/ to the new subdomain of http://blog.tedroche.com but the redirect was set to a temporary (302) redirect rather than a permanent (301) one, causing extra traffic to the web server and slower response to the clients. I’ve changed this to a permanent redirect. There shouldn’t be any negative effects, he said, with his fingers crossed…