Download Template Plugin Code

This page provides a form to download template code for writing a WordPress plugin. However, you don’t need any of this to write a WordPress plugin. Especially a simple one. You can get along OK by following the standard directions on how to create a plugin.

So why bother? If you write a more complex plugin, or several plugins, you have to figure out how to manage things like actions that should only happen on the first install, actions to take when upgrading from version X to version Y, and creating some boiler plate code related to creating an administrative options page, short codes and more. You also want to exercise best practices. See more on the Design Tenets page.

This template code and supporting documentation is my cut at template code that provides a code pattern for managing complexity, boiler plate code, convenience functions, and best practices for being a “good plugin citizen.”

Thanks, very handy! Any chance of an announce list to be notified when you add new features?

If interested in suggestions, I’d find a few more input field types on settings pages useful. And in the generate form, maybe put a checkbox to include some commonly used snippets like defining a post type and custom taxonomy.

* Plugins may be activated once for all present and _future_ blogs (Network activation) or activated for individual blogs

* Plugin data can be stored in tables at the Network level or in tables as individual blogs

* Network support additional features including
** superusers who manage a Network
** Network options
*** Plugin authors must decide what are plugin options that are typically available two blog administrators in a back end administrator menu and what are network options that are only available to supers users in the network administrator menu.

* Plugin code is called in the context of a blog with a $blog_id. This is important for reading and persisting data. For example, post data would be recalled from the current blog.

The implications for your template can be viewed through the lens of the files

* my-cool-plugin.php
** Comments to indicate that the author may set “Network: true” if the plugin is multisite compatible

* MyCoolPlugin_Plugin.php
** Must optionally check for deployment within a Network and have a different behaviour

* MyCoolPlugin_LifeCycle.php
** Lots of changes, needs to support Network Activation and/or activation of a single site within a Network

* MyCoolPlugin_OptionsManager.php
** Must support Network Options

At the moment it is true to say

* “this template does not support multisite plugins”

because there is not template code to support operation in a network.

I am not sure it is true to say

“this template is not multisite compatible”

The later sentence implies that a plugin written using this template _must_ break. I think that this is not true. I have tested “Network activation” of plugin in a multisite network and it fails gracefully. That is to say that it simply returns with no message. When the plugin is activated on the site it works fine.

If upon review and further testing you agree with my conclusion you may wish to change your communication to,

“Multisite Compatibility
A multisite network offers several capabilities to a plugin author such as network activation, network data storage and network options, that are not supported by this template. However a plugin written using this template should work correctly when activated within an individual site on the network.”

This is amazing, thanks so much – saved me a LOT of time.
One question that’s driving me mad….

I’m trying to populate the drop-down select options using a WP_Query.
I have an array of IDs from the query and have tried to implode this array so that the string matches the format of your example options but the whole string shows as a single option instead of a new option for each comma in the string.

I see you don’t monetize your page, don’t waste your traffic, you
can earn additional bucks every month because you’ve
got high quality content. If you want to know how to make extra $$$, search
for: Boorfe’s tips best adsense alternative