Creating a gadget - Intermediate tutorial
For this tutorial I am going to walk us through the creation of a Sticky note type of gadget.
The gadget will allow us to enter notes which will be retained until they are edited or deleted at a later date. The notes can be something as simple as a reminder to yourself, a link to a website to check out, or a message to another user or blog administrator.
This example will make more use of the ajax side of the MyDashboard plugin and thus will require a bit of knowledge of Javascript.
Are we ready, then let us begin as we did in the last tutorial with a basic plugin template.
Creating the plugin template
The first thing we will do is to create the template for a new plugin. More indepth instructions on WordPress plugin development can be found at the WordPress codex site.
If you are following along with the tutorial, create a new file in your favourite text editor called "stickynotegadget.php" and paste the code below into it.
<?php
/*
Plugin Name: Sticky note gadget
Plugin URI: http://dev.clearskys.net/MyDashboardGadgets/GadgetDevelopmentIntermediateTutorial
Description: This plugin adds a sticky note gadget to MyDashboard.
Version: 1.0
Author: clearskys.net
Author URI: http://blog.clearskys.net
*/
class stickynotegadget {
function stickynotegadget() {
// This is the creator function
}
// the rest of the plugin code will go here
}
$SNgadget =& new stickynotegadget();
?>
Adding our placeholder functions
As detailed in the Basic tutorial the MyDashboard system requires that each gadget has a minimum of three functions, which are called at varying times depending on the way a user interacts with your gadget.
So as in the previous tutorial, we will create the required functions within our plugin. Underneath the comment "the rest of the plugin code will go here", add the following lines of code. I will go through how and when each function is used, and the differences between this and the basic tutorial, when we add code to them below.
function create_my_gadget($args = false) {
}
function edit_my_gadget($args = false) {
}
function display_my_gadget($args = false) {
}
Continues soon....