Wordpress Plugin Tutorial Part XII - Finishing Touches

Once a Wordpress Plugin is installed there is no guarantee that the user will keep it forever. There is possibility that the plugin will be uninstalled and when that happens we must make sure that we remove all traces of the plugin from the database. Doing this is not that difficult.
To do this, add a file named 'uninstall.php' into the custom-comment-message directory and put the following content in that file.
<?php
    global $wpdb;

    //delete the option that contains
    //the default message
    delete_option('ccm_title_reply');

    //delete the per-post comment messages
    $wpdb->query("DELETE FROM $wpdb->postmeta WHERE 
                  meta_key = 'ccm_title_reply'");


?>
Now when the plugin is uninstalled (or deleted), Wordpress will run this file and remove the entries from the database. The $wpdb object provides an interface to the Wordpress database. Take a look at this article on the wpdb class to learn more about it.

Next we will look at the header comment again. If you remember, we only put the 'Plugin Name:' on the header section. There are other fields that we have to put in order to make sure that the plugin is standards compliant. Take a look at this article to know what should be included. To learn about the coding standards take a look at this section of the article.

Also if you plan to host your plugin at the Wordpress plugins repository, you will have to create a readme file of a specific format.

More information can be found on this article on Writing a Plugin.

It is recommended that a page is created for your plugin on your website with instructions on installation etc.. I have created this page to  provide such information. If you are interested in downloading the full source code of the plugin developed in this tutorial series, you can download it here.

No comments:

Post a Comment