package playne

imports "programmer"

Initial Plugin Setup – WordPress Development

Initial Plugin Setup

Here is a short description of the plugin setup and the why on how we have done things the way we have.

Plugin Namespace

It is up to each developer to ensure that their plugins will not collide with anyone elses. This is usually done with a prefix being added to class and function declarations, for example:

<?php

function myplugin_be_awesome() {
}

Although if you can guarantee PHP 5.3 (or make it a plugin requirement) you can use PHP’s builtin namespace.

<?php

namespace myplugin;

function be_awesome() {
}

These articles will assume that you are using PHP 5.3 and will use some of the cool new features of this version.

Hooks and Filters

WordPress has a very mature plugin system that allows users to modify just about anything they want with a very large collection of plugins from the WordPress Plugin Directory. There are plugins there that do just about everything and there are usually several to choose from.

Plugin development is a very flexible thing with many different ways to do things (single file, multiple files, lots of resources) and things can vary depending on the size of your plugin.

You can create your own hooks to have other plugins alter the way yours works. The functions you want here are:

  • add_filter() – Adds a function of your own to change the output of another function
  • remove_filter() – Removes a filter if it is no longer needed
  • apply_filters() – Allow others to change your code
  • add_action() – Add your function to modify default behaviour
  • do_action() – allow others to modify your behaviour
  • remove_action() – get rid of it when it is no longer needed