Archive for the 'open-source' Category

Turning a WordPress Sidebar Plugin Into a Widget

Converting a WordPress plugin to a widget doesn’t have to be difficult, but because the official API’s over at wordpress.org are so lacking in detail (the example they provide won’t even work if you cut and paste), many developers can become frustrated with the process.

STEP 1: Using a widget to call a plugin function (no user input)

To begin, assume you have a very simple sidebar plugin that can be called by editing the sidebar theme directly. In your plugin file, there is some function called “nifty_stuff” that outputs some sort of html code to display in the sidebar. In the bad old days of WordPress, the only way a user could display such a plugin would be to edit their theme and add the line of code provided by the plugin author to some point in their sidebar.php file (or whatever the sidebar’s name happens to be). And in older wordpress versions and themes this is still what a blogger needs to do, so you want to leave your user with that option.

If the plugin function requires no input from the user, then the following code will add it to their widgets menu where they can simply drag and drop it into a simplified representation of their sidebar. Just add this code to the same script that holds the “nifty_stuff” function:

function widget_nifty_stuff_init() {

if(!function_exists(‘register_sidebar_widget’)) { return; }
function widget_nifty_stuff($args) {

extract($args);
echo $before_widget . $before_title . $after_title;
nifty_stuff();
echo $after_widget;

}
register_sidebar_widget(‘Nifty Stuff’,’widget_nifty_stuff’);

}
add_action(‘plugins_loaded’, ‘widget_nifty_stuff_init’);

Going through the code, what’s happening is that we first want to create a wrapper for our widget function.

Without that wrapper, php will attempt to use the function “register_sidebar_widget” before the script containing it has been loaded. Using the ‘plugins_loaded’ action hook to run the init function ensures that everything loads in the right order first.

The lines surrounding the call to nifty_stuff are there because the widget-enabled wordpress themes may use them, and so they must be supported.

The register_sidebar_widget function associates a label for the widget with the actual widget function that will get called if the user adds it to their sidebar. That label is what the user sees in their widgets menu.

Now, that’s all well and good for really simple plugins. But if your widget needs that user input, then keep reading to learn how to add a widget control. continue reading »

September 30 2007 | open-source and technical articles | 4 Comments »

The ISR interview widget for affiliates

In my current full-time job as webmaster for Inside Success Radio, I don’t often get a lot of opportunity to do really cool new programming. However, I had a blast with my latest project, and I was proud enough of it that I’m going to share it here.

Basically, we run an internet talk radio website, and we have members who pay to listen to our exclusive content. Each interview is broken up into 3 segments, with the first segment telling the guest’s story, and then the second segment giving their expert advice (and this is the stuff people are willing to pay for), and a third segment where they offer predictions about developing trends in their fields. Our experts span the gamut from business and finance to parenting and romance. With multiple subtopics, it’s pretty easy to see how content from our site could be a valuable addition to anyone’s weblog.

So anyway, after I happened to mention to my boss that I knew how to write WordPress widgets, he asked me if we could use a widget to let someone easily add a feed from our site to their own blog, and get some free links back in the process. I said that I could, and after we hammered out the specs, we came up with this pretty little widget.

You can see the result of this effort in my own sidebar there to the left. It includes just a tiny amount of information about the guest, a feed for listening to the first segment of the interview, and then a link inviting people to our VIP page, where by giving us just their name and email address we’ll let them listen to the entire interview for free. In addition, we offer them a free trial membership. After the trial period expires, they can pay each month to continue to get access to our huge library of content as well as all of our new shows that we add every week.

Now, the exciting feature for the blog owner is that the link to the VIP page includes an affiliate id. If a person signs up as a member and starts paying us each month, we pay a 35% commission on every payment. With just a few new users each month, this can quickly become a great passive income source. In addition, the blog owner specifies the keywords and topics relevant to their own visitors, ensuring that the interviews displayed will be ones their traffic is most likely to be interested in. The featured interview changes each day. As a handy guide, the widget control lets the blog owner know how many interviews in the database currently match their preferences. They can narrow or generalize their settings as appropriate.

The exciting feature for Inside Success Radio of course is that we get numerous links back to our site to improve our search engine rankings. We get 1 link back to the insidesuccessradio.com homepage, 1 link to the homepage of the particular radio show being featured, and 2 links back to the guest’s own promotional page. The other cool thing is that if we want to promote one particular guest on a particular day, we can modify the feed on our end such that if the widget’s keyword, category, and radioshow preferences match, then that guest we’re promoting will be sure to show up as the featured interview. This way we can quickly get dozens of backlinks and traffic all at once. Isn’t that a cool idea?

Anyway, if you think you’d like to have it on your own blog, you can either become a member yourself and request an affiliate id, or else feel free to use mine – 405203. (Hey, it never hurts to ask, right?)

Here’s what bloggers see when configuring their feed:
Options for configuring the ISR feed widget

September 27 2007 | open-source and php projects | No Comments »

The Experts-Exchange Badge

Though I originally developed this wordpress plugin just for my personal use, I decided to generalize it so anyone can display their rank on experts-exchange.com. Now I’m hoping others find it useful as well.

The point tally automatically updates when you gain new expert points, so it’s never out of date. As you pass milestones like 50K, 150K, 300K and so on, the graphic will switch to show your current shield of courage. It’s a snap to use either as a direct function call in your sidebar.php file or as a widget. And the badge itself is a link back to your experts-exchange profile.

eebadge screenshot

Click this link to download the plugin.

After unzipping the contents, place them inside your wordpress plugins folder. In the admin panel, go to your Plugins menu and activate the Experts Exchange Badge plugin.

To have it display on your page, go to your Presentation menu and click the “Widgets” option. Drag the widget named “Experts Exchange Badge” into your preferred position in the sidebar. Click on the configuration link and complete the link to your profile in the input window. Now click “save changes”. Your badge will now appear for all your wordpress visitors to see.

As an alternate method, if you don’t want to use widgets you can modify your sidebar.php file directly. Again go to the Presentation menu, this time selecting the “Theme Editor” option. Select the sidebar file you wish to modify (or any other template you want to show your badge) and add the following line:
<?php ee_badge(‘[your profile id]’); ?>
(replace [your profile id] with the code that completes the link to your profile: http://www.experts-exchange.com/M_[your profile id].html)

September 19 2007 | open-source | 1 Comment »

WordPress Album Viewer Plugin

My baby daughter is beautiful. And I needed a way to show her off that was simple to use, easy for friends and family to navigate, and I wanted to keep the pictures on her blog. I didn’t want to host them on a file-sharing site because I wanted to keep the pictures out of the general web (with my daughter’s own blog, I’ve used the meta tags to tell the search engines not to spider it), and at the same time, I didn’t want to have to password-protect them from friends and family. And besides, I don’t want my visitors having to click away to an external site.

Anyway, there were already a few wordpress plugins that can help to host a gallery of images, but I had a pretty clear vision of what I wanted, and rather than trying to get someone else’s plugin to do what I wanted, I decided to write my own.

It’s worth pointing out that I didn’t originally expect this to be anything more than a useful tool for myself, but as I learned more about wordpress, I realized that I could easily turn my code into a full-fledged plugin that anyone could use.

Anyway, the plugin can now be downloaded by any and all through sourceforge.net. The link is http://sourceforge.net/projects/wp-album-plugin/

To see it in action, and check out pictures of me, my wife, my daughter, family, friends, and random people standing in the backgrounds, go to http://honorwolf.com. Click on any of the thumbnail links on the left-hand side of the screen.

This is probably the project I had the most fun working on. Even though nobody was paying me to write it, I had a great sense of satisfaction from taking my own vision and making something uniquely mine. And I’m always happy with the result every time I look at it. I create new albums from right inside the wordpress administration area, edit them there if necessary, and with hardly any effort at all I’ve managed to get my parents to stop complaining that they never see any pictures of their only granddaughter.

Creating a new album – step 1

creating a new album - step 1

Creating a new album – step 2

creating a new album - step 2

Selecting an album to edit

selecting an album to edit

[UPDATE 9-27-07: I’ve made Album Viewer version 1.1 available on Sourceforge.net. This marks a significant improvement over the previous version. The plugin has now been “widgetized”, allowing people to share their albums in the sidebar more easily. In addition, it now automatically detects whether users have ImageMagick available on their web hosts, and will default to that for thumbnail creation if they do. Thus, for many users, they are no longer limited to only sharing photos under 1 million pixels.]

August 30 2007 | open-source | 2 Comments »