I will quickly go into how Assignment 2 could be solved.
For the first two items in the assignment (the custom login form and custom admin panel) you could use one of the many available plugins, see  and  in the resources section for my recommendations.
For the third item in the assignment (the custom widget) almost everyone in the class used a poll plugin. This was not what I wanted initially but reading the assignment now I can clearly see I led everyone in the wrong direction :)
The goal was to have a widget where in the admin you could choose your tribes and in the frontend you display them. Here is how the front view and the admin view could look like:
The Widget Barebones
Our widget needs an initial skeleton from where we can built upon. A widget can be created either through a plugin or a theme. In this case we will create a simple plugin that creates our widget. So to start you would create a directory ‘week2assign’ in the plugins directory and have a single file also called ‘week2assign.php’ containing:
This would be enough to have it in the plugins list and enable/disable it.
The Basic Widget
For a widget you normally need two functions, one to register the widget (register_sidebar_widget) and another to register the control function for the widget (register_widget_control). The first function has a basic template which you can see below and that is normally used:
This should be enough to start seeing your widget in Appearance->Widgets section.
The Widget Control
The widget control function is where you display the code for the widget controlling options. In this case it will be a checkbox for each of the possible options:
Because the list of checkboxes checked is kept into an array we need to use the serialize function in order to be able to save the array into the database.
A Small Enhancement
When you click save in the widget options you’ve probably noticed that the tribes you selected are not checked as marked. This is because although they are saved in the database, we didn’t check if they were marked. For that we can make a small enhancement to the control function to do just that:
You’ll notice now there is a is_tribe_selected function which is merely a function to check if a certain tribe is listed as checked. The code for this function is:
The Full Widget
The code for the full widget can be found here or downloaded here.
I hope this has been a useful walkthrough. Cheers and always Enjoy!
You must be logged in to post a comment.