Design Tenets

 

The aim of this template code is to provide a code pattern for managing complexity of a WordPress plugin and following best practices. High-level issues are the following.

Life Cycle Management

By default, a plugin can’t tell if it’s being installed, been installed already, or even being upgraded. Maybe you want to create a DB table during installation and later you add a column to the table when the user upgrades to version 1.6. But you don’t want the plugin to try these things every time it is accessed or activated.

Your XXX_Plugin class inherits from a class called XXX_PluginLifeCycle. This class has functions for installation, activation, deactivation, upgrade, uninstall and more. Overriding them in your class gives you a hook to write code to happen during these events. Also included is a check for your minimally-required PHP version.

Easier Options Handling

Practically every plugin has options (a.k.a “settings”) for users to set. The plugin template code provides a quick way to define a set up options and their values. An options page for the plugin can be automatically installed in the administration menus. Options are automatically deleted on uninstall. Options that define roles (like what role is minimally required to perform a function) are easy to define and enforce.

Prefixing Options

Part of being a good plugin citizen is avoiding having the same name for an option as any other plugin. Otherwise, they collide in the wp_options table. This plugin provides alternative to get_option, add_option, update_option, delete_option  functions: getOption, addOption, updateOption, deleteOption which will automatically add a prefix to the option name stored in the DB to avoid collisions. getOption also allows you to return a default value if the option is not set.

Short Code Support

Support for creating and loading multiple short codes. Includes a technique to avoid loading scripts needed by a short code into pages where the short code does not appear (a best practice)

More Easy to Understand Roles for Security

Provides easier role names to work with (Administrator, Editor, Author, Contributor, Subscriber, Anyone) with easy way to map to WP “capability”. Convenience functions like isUserRoleEqualOrBetterThan($roleName) make programmatic security checks easy. Options include a notion of “role options” where an option can be set with a choice of roles. That can be used by an administrator to set role security on a plugin’s operations (the ones you write).

Support for Internationalization

Template code includes internationalized strings and the plugin initialization automatically gets set up to load your text domain and translation files.

Convenience Functions

Convenience functions are provided for common operations

Object-Oriented Design

Use of Object-Oriented Design to support code re-use and abstraction through inheritance (This means it requires PHP 5 or later).

  4 Responses to “Design Tenets”

  1. […] menu Skip to primary content Skip to secondary content HomeDesign TenetsGetting StartedDownload Template Plugin CodeFiles OverviewInstall/Uninstall ActionsCreating Database […]

  2. […] Read more about the design tenets. […]

  3. You might design/explain upgrading a plugin to a newer version of your Plugin Template – eg. how to replace XXX_OptionsManager.php or just createFormControl() when you add more input field types.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>