Using a Plugin Template

When you start writing WordPress plugins, you find that you spend a significant amount of time rewriting the same things. Typically, most plugins have the same basic structure and are set up the same way, meaning that they all deal with settings pages, storing options, and interacting with particular plugins, among other things. You eventually conclude that a valuable use of your time is to create a template for all the plugins to save you hours of work each time you start a new plugin.

Such a template varies from person to person, and to you, depending on programming styles, preferences, and the types of plugins the developer wants to include. For instance, if you often write plugins that use your own database tables, you should include this in your template. Similarly, if your plugins almost never require options pages, leave those out of your template.

image When making a template, keep in mind your personal plugin preferences and tendencies.

To create your own template, determine what functionality and structure your plugins usually contain. Follow these steps:

  1. Create your file structure.

    As you write more plugins, you find yourself repeating the same general filenames. If you find that you're including enough JavaScript and CSS in your plugins to necessitate their own files or directories, include these in your template. For example, if you're using a lot ...

Get WordPress® All-in-One For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.