Zen-Dreams

Zen-Dreams.com

Write your own plugin for Wordpress [Chapter 2]

  • Français

As promised before here is next article from the Create your own Wordpress plugin series.

  1. Introduction to plugins
  2. Plugin’s skeletton
  3. Activation, Hooks & Filters
  4. Widgets Definition

In this article, I’ll explain the structure of a plugin. More exactly the skeletton of a plugin file used to create them and also some specific concepts.

Plugin’s skeletton

A Plugin is composed of at least one php file (it’s not necessary to have more than one, but it’s better to split your code in multiple files for reusability). This file has a specific structure.

Filename is totally unimportant as only the content of the file will be used to define the plugin. For example, you can have a plugin named My_Plugin_That_Rocks described in a file called toto.php. The definition of the plugin’s name will be done inside the file itself using tags.

So here the structure to put inside one of your plugin’s file. This informations will be even more important if you plan to publish your plugin on Wordpress’s Extend section.

/*
Plugin Name[1]: The_Name_Of_Your_Plugin
Plugin URI[2]: http://yoursite.com/plugin_url
Description[3]: Description of the plugin
Version[4]: 1.0.0
Author[5]: Anthony PETITBOIS
Author URI[6]: http://www.zen-dreams.com/
*/

  1. The name of the plugin as it will be published inside Wordpress plugins administration panel, but also on wordpress.org. Therefore, it’s important to choose it well so that it can be retrieved easily amongst all other plugins.
  2. Corresponds to the URL that will be used as a link inside Wordpress’ plugin admin panel.
  3. That’s where you put the description of your plugin. A short extract of what it does is sufficient because that’s what will be displayed inside the admin panel.
  4. Version number of your plugin. This is very important because it’s used by Wordpress automatic updater to check if your currently installed version is the last compared to Wordpress/extend. It will also allow automatic update of the plugin.
  5. that’s where you’ll put your name (also displayed in the admin panel)
  6. And finally that’s where you generally put your blog’s url. This will be used to create the link to you where your name is displayed.

Once this header is placed inside your php file, it will be recognized as a plugin by Wordpress. It’s not because it’s recognized that it will work out of the box. In order to make it work, you have to plug it into wordpress’ core (Using hooks and filters, but that’s next chapter).If you don’t plug it in, it will run the php code directly at the engine loading.

If you want to have a plugin that’s correctly written, you have to define a class, or functions and plug them to the corresponding events. For example before the display of a post, while inserting comments, at wordpress init, and so on…

But as I said before, let’s keep that for next post.

By Anthony

2 Comments

  1. Posted 19 July 2008 at 14:21 | Permalink

    Ahah ^^ la suite est pour quand ? :p
    Ca fait un moment que je veut créer un plugins, il me manque juste le reste maintenant =)

  2. Posted 19 July 2008 at 15:11 | Permalink

    La suite devrais arriver dans la semaine, j’avoue que je n’ai pas préparé les articles à l’avance mais que je préfère les faire quand j’ai trouvé tout ce que j’allais dire dans l’article, mais soit rassuré, la suite ne sera pas un simple tutorial, mais détaillera la création d’un nouveau plugin (qui sera donc publié sur le wordpress/extend ainsi que le détail de la création ici même).

Post a Comment

Your email is never shared. Required fields are marked *

*
*