Custom WordPress Plugin for widget area and staff list widget

Staff List WordPress Plugin

Widget widget widget. Sorry I just had to get a few more in there I guess. This WordPress Plugin tutorial is a little bit more advanced then the others but I’ll do my best to break it down to small pieces so that you can edit/customize it to your own needs. First let me tell you what exactly this plugin achieves. I was working on a site and needed to display the Editors/Authors in the sidebar and while I’m sure you may know about wp_list_authors, it would probably do the trick for most situations but some of the Editors needed to have different roles listed and it just wouldn’t be able to work without a lot of extra if’s and else’s. I needed a simple way to input a list and it show up where I need it, so I made this plugin.

Basically what it does is creates a Widget Area named “Staff Lists” and a widget named “Your Staff List Widget”. This way I can have as many “Staff Lists” in the widget area as I want (Editors, Authors, Contributors, Pets and so on) or I can use the staff list widget in any other widget area (sidebar etc). To make my life even easier I made the Staff List widget area show up using a short code so that if I ever wanted to show it in a page or post I could do so easily.

This part sets up the widget area, you’ll notice later I don’t actually use ‘before_widget’ or ‘after_widget’ to their proper potential(you can blame laziness here) so why don’t you do some additional research and improve your version of the plugin later.

As the comment suggests this portion is what is seen on your website’s viewer’s end. I’ll explain how I built the list part next.

$listclass = $str = strtolower($listname);

First I grabbed the list’s name and made it lower case so that I can apply it to a class without throwing off my designer’s code.

$allusers = $instance['user'];
$users = explode("\n", $allusers);

Here I grab the text that is in the textarea named ‘user’ and with the explode function I make an array breaking it up by each line(\n). So basically if I input this in to the textarea in the admin field:

It’s pretty simple, an input field for the list name and a text field for the users|roles. I could have made it more advanced but really it didn’t need to be. Simplicity is sometimes the best solution, especially if multiple people are going to be editing it later.

The change in the short code will now let you use the “title” and “class” attributes allowing you to change the staff list’s div class and style it however you wish. Note: the default “title” is now blank as well.