Create your own WordPress plugin

wp-plugins
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 “http://www.example.com/some/path/images/test.jpg“) and parses only the part between <body> and </body> It then returns the remaining HTML. So I need to execute:
echo pfmirror_showhtml("http://www.example.com/some/path/page.html") (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?

4 thoughts on “Create your own WordPress plugin”

  1. This is generator is great, thank you! I’ve just started looking into creating my own plugin and as-is your generator is a great tool for a beginner. I’m most interested in the config page option since that’s one thing I was having a hard time with: writing to the database using the hooks and whatnot. I look forward to the development of this web tool!

  2. The plugin is awesome.

    Just wonder about the options table.

    Wouldn’t it be easier if you ask in the form for values, and the plugin creator creates an options page with this values, and left inputs for the keys to each value…

    that would make it more flexible.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.