It’s been less than a year since I first published my B2Template plugin to help people start building their own plugins for WordPress. I received some great feedback and so I’ve updated the plugin to address some new features in WordPress 3, and improve on some of the methods I took in the previous version. The new version of the B2Template Plugin is available from the WordPress Plugin directory. The plugin has been commented to within an inch of its life, and is hopefully laid out in a way that is easy to follow.
This plugin covers the following topics:
- Creating a Plugin within a class structure to better encapsulate your plugin and avoid conflicts with other plugins
- Creating actions and filters
- Creating an install script that runs on plugin activation and deactivation, and also performing the important step of removing all traces of your plugin upon deletion.
- Internationalizing your plugin so that it can be translated by the WordPress community, and also how to create language files
- Creating administration pages, registering settings, saving settings, properly loading JavaScript and CSS into admin pages, adding a link to the plugins settings page on the plugin activation page.
- Using action and filters
- Executing actions with and without Ajax from user-facing and admin-facing pages in a clean consistent manner.
- How to load Ajax Elements
- Registering and creating a WordPress 3.0 multi-widget
- Interacting with the database, proper input sanitization
- Returning error messages to the user with the WP_Error object
Please check out the plugin and let me know if you find it helpful, or if you can think of ways in which it can be improved.
Download the B2Template Plugin 2.0 from the WordPress Plugin Directory.

5 Comments »
[...] WordPress 2.7 and below. For WordPress 2.8 and above, use version 2.0 of the Plugin. Learn more by reading this updated post. I will try to support this plugin better than I did with Version 1.0. [...]
Hi Dan,
Thanks so much for providing this. It is very useful. I did find, however, that there were a few things not working completely upon install.
The activation hook did not work from me, so I changed it from:
add_action(‘activate_B2Template/B2Template.php’,array($this,’Activate’));
To:
add_action( ‘activate_’ . preg_replace( ‘/.*wp-content.plugins./’,”,__FILE__ ), array($this,’Activate’) );
Also the widget instance data was not being saved, so I added the following to the update function:
$instance['word_count'] = $new_instance['word_count'];
$instance['reading_level'] = $new_instance['reading_level'];
$instance['syllables'] = $new_instance['syllables'];
$instance['syllables_per_word'] = $new_instance['syllables_per_word'];
$instance['words_per_sentence'] = $new_instance['words_per_sentence'];
Also, the RouteActions function threw a warning, so I changed $action = $_GET['B2Template_Action'] to $action = isset($_GET['B2Template_Action']) ? $_GET['B2Template_Action'] : NULL;
After that, all seemed to work great. Again, thanks so much!
Thijs.
Hey Dan,
I’m a mature age student currently studying web development at collage and for an assignment I decided to make a WordPress plugin. I went online and started to go through tutorials and the WordPress Codex but I found that alot of the information is out of date incorrect or just plan confusing, there’s nothing worse that spending hours going through a tutorial to find at the end that it doesn’t work, I did that a couple of times.
Then I stumbled across your B2Template, being abit disheartened by this point I wasn’t expecting much, but to my surprise your template turned out to be the best resource for me, great easy to understand comments, well formatted code, links to good info and even a table of contents.
THANK YOU SO MUCH for the time and effort you put in to this, your work is very much appreciated.
Cheers….Eben
Hey I just started learning WordPress plugin development and this helper plugin is AMAZING! Thanks so much!
Thanks very much for the kind comments. I will have another learning plugin available soon!
Leave a comment