Create your own WordPress plugin

Wordpress has a really nifty system for adding functionality: the WP plugins. There are a ton of them around, but if you have some knowledge of SQL and PHP you can make your own plugins! You of course have to know how to display stuff, how to add a configuration panel to the Options or Manage tab, … When I read the code of some well-developed plugins, I thought: it should be easy to come up with a WordPress plugin template generator. So that’s what I did: here’s the first (far from complete) version of the WordPress Plugin Generator!

Currently it supports the following features:

  1. return the result as
    • REPLACE TAG: replace all occurences of <!--myplugin_tag--> by a certain text/html
    • AFTER/BEFORE POST: add after/before each post (e.g. for tags, DiggMe buttons, Adsense, …)
    • CALL FUNCTION: call the myplugin_showhtml() function (e.g. in sidebar.php)
    • BY PLUGIN PAGE: the result is displayed when the wp-content/plugins/myplugin/myplugin.php page is called (e.g. for results in XML or TXT format)
  2. add the result only to posts, pages, search and/or archive pages
  3. add a config page to the “Options” or the “Manage” panel
    (here I need to do some work to create a good way to generate the display code and the form processing – showing and changing parameters of your plugin)
  4. add optional GPL license text

I of course try to use the guidelines published by WordPress and Installer. I’ll write something about that later.

A first plugin that I made myself with the wizard is pfmirror. What does this (mini) plugin do? It grabs an external HTML page, replaces all relative links by absolute links (e.g. “images/test.jpg” becomes ““) and parses only the part between <body> and </body> It then returns the remaining HTML. So I need to execute:
echo pfmirror_showhtml("") (either in a PHP file of the theme, or by using the RunPHP plugin, in any post page).
Obvious improvements that I could do:
– more flexible parsing (show only everything between pattern#1 and pattern #2)
– disable JavaScripts (they mostly don’t work properly when transported anyway)
But most of all, it was a proof of concept of the template generator.

Any suggestions for improving my WP-plugin wizard?

💬 Wordpress