A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.

Overview

WordPress Plugin Boilerplate

A standardized, organized, object-oriented foundation for building high-quality WordPress Plugins.

Contents

The WordPress Plugin Boilerplate includes the following files:

  • .gitignore. Used to exclude certain files from the repository.
  • CHANGELOG.md. The list of changes to the core project.
  • README.md. The file that you’re currently reading.
  • A plugin-name directory that contains the source code - a fully executable WordPress plugin.

Features

  • The Boilerplate is based on the Plugin API, Coding Standards, and Documentation Standards.
  • All classes, functions, and variables are documented so that you know what you need to change.
  • The Boilerplate uses a strict file organization scheme that corresponds both to the WordPress Plugin Repository structure, and that makes it easy to organize the files that compose the plugin.
  • The project includes a .pot file as a starting point for internationalization.

Installation

The Boilerplate can be installed directly into your plugins folder "as-is". You will want to rename it and the classes inside of it to fit your needs. For example, if your plugin is named 'example-me' then:

  • rename files from plugin-name to example-me
  • change plugin_name to example_me
  • change plugin-name to example-me
  • change Plugin_Name to Example_Me
  • change PLUGIN_NAME_ to EXAMPLE_ME_

It's safe to activate the plugin at this point. Because the Boilerplate has no real functionality there will be no menu items, meta boxes, or custom post types added until you write the code.

WordPress.org Preparation

The original launch of this version of the boilerplate included the folder structure needed for using your plugin on WordPress.org. That folder structure has been moved to its own repo here: https://github.com/DevinVinson/Plugin-Directory-Boilerplate

Recommended Tools

i18n Tools

The WordPress Plugin Boilerplate uses a variable to store the text domain used when internationalizing strings throughout the Boilerplate. To take advantage of this method, there are tools that are recommended for providing correct, translatable files:

Any of the above tools should provide you with the proper tooling to internationalize the plugin.

License

The WordPress Plugin Boilerplate is licensed under the GPL v2 or later.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

A copy of the license is included in the root of the plugin’s directory. The file is named LICENSE.

Important Notes

Licensing

The WordPress Plugin Boilerplate is licensed under the GPL v2 or later; however, if you opt to use third-party code that is not compatible with v2, then you may need to switch to using code that is GPL v3 compatible.

For reference, here's a discussion that covers the Apache 2.0 License used by Bootstrap.

Includes

Note that if you include your own classes, or third-party libraries, there are three locations in which said files may go:

  • plugin-name/includes is where functionality shared between the admin area and the public-facing parts of the site reside
  • plugin-name/admin is for all admin-specific functionality
  • plugin-name/public is for all public-facing functionality

Note that previous versions of the Boilerplate did not include Plugin_Name_Loader but this class is used to register all filters and actions with WordPress.

The example code provided shows how to register your hooks with the Loader class.

What About Other Features?

The previous version of the WordPress Plugin Boilerplate included support for a number of different projects such as the GitHub Updater.

These tools are not part of the core of this Boilerplate, as I see them as being additions, forks, or other contributions to the Boilerplate.

The same is true of using tools like Grunt, Composer, etc. These are all fantastic tools, but not everyone uses them. In order to keep the core Boilerplate as light as possible, these features have been removed and will be introduced in other editions, and will be listed and maintained on the project homepage.

Credits

The WordPress Plugin Boilerplate was started in 2011 by Tom McFarlin and has since included a number of great contributions. In March of 2015 the project was handed over by Tom to Devin Vinson.

The current version of the Boilerplate was developed in conjunction with Josh Eaton, Ulrich Pogson, and Brad Vincent.

The homepage is based on a design as provided by HTML5Up, the Boilerplate logo was designed by Rob McCaskill of BungaWeb, and the site favicon was created by Mickey Kay.

Documentation, FAQs, and More

If you’re interested in writing any documentation or creating tutorials please let me know .

Comments
  • Public theme functions

    Public theme functions

    Hi!

    Love this boilerplate. Began using it a few days ago on a new plugin project and while it takes some getting used to there's just so much to gain.

    I have a question about best practice: The user should be able to call a function from within their theme (think of it as a function that outputs some interactive elements). Where and how would you put this?

    My current solution is to have a static public function inside the public class (public/class-plugin-name-public.php) and let them call it by

    Plugin_Name_Public::the_public_function();
    

    But it doesn't feel right.. Should I put another file in the public folder which just contains these functions (not in a class) and include it via the load_dependencies() function? By my logic that should mean that they'll be able to call it with just:

    the_public_function();
    

    P.S. I do realize the function name has to be very unique in that case

    opened by jonathan-dejong 38
  • Separate actions: front, admin and common?

    Separate actions: front, admin and common?

    I use this snippet to set actions/filters only when they are needed (no admin actions if we are no there and vice versa):

    protected function __construct() {
        $this->_actionsCommon();
    
        if ( is_admin() ) {
            $this->_actionsAdmin();
        }
        else {
            $this->_actionsFront();
        }
    }
    

    Here, in 2.8.0, admin has its own class, which is great. I already asked about is_admin in the previous issue. What about common actions? What about not setting front actions when is_admin?

    Thank you!

    2.x.x - Retired 
    opened by tivnet 29
  • Feature request

    Feature request

    It would be really handy if you could throw in a plugin slug, plugin name, plugin author etc. etc. and have it automatically spit out a plugin with everything named correctly at http://wppb.io/.

    opened by ryanhellyer 26
  • Setup

    Setup

    In short: Moved everything to uninstall.php. Imho that file should be renamed to setup.php. Or if someone wants to really, really use that crap, which is called "WordPress Coding Standards", then it should be class-plugin-name-setup.php.

    I moved everything - including the callback hooked to the wpmu_new_blog hook - into that file. The file itself contains a class. All the logic that has previously been in place (like looping though blogs/blog IDs and calling single site actions/callbacks) have been moved as well. This makes the main file much more consistent.

    opened by franz-josef-kaiser 24
  • Incorrect directory for language files

    Incorrect directory for language files

    In the class-plugin-name.php file, loading the text-domain is pointing to the wrong folder. Since moving the file into a public folder, the relative link being computed is public/languages/.

    When WordPress tacks on WP_PLUGIN_DIR the final path is /home/www/wp-content/plugins/public/languages/ instead of /home/www/wp-content/plugins/plugin-name/languages/

    opened by gMagicScott 14
  • Privatize __clone()?

    Privatize __clone()?

    I usually privatize the __clone() magic method in singletons I write. Technically, if I understand cloning correctly, PHP will still make the shallow copy of the cloned object in memory, but then when it calls the __clone() method, since it's private, it creates a fatal error.

    It's probably overkill, but adding the following to the classes (usually as the last thing in the class to keep it out of the way) isn't so bad:

    private function __clone() { }
    

    Thoughts?

    2.x.x - Retired 
    opened by dashifen 14
  • Should we move the class files to their own subdirectory?

    Should we move the class files to their own subdirectory?

    I believe when core scans the plugin directory it looks at all PHP files in the root of each subfolder. (citation needed)

    It's probably a negligible performance impact, but would there be a benefit to moving these two files to a classes sub-directory, performance or organization-wise? As people add classes it helps to have a separate inc or classes directory to keep everything organized.

    class-plugin-name.php
    class-plugin-name-admin.php
    

    This would involve modifying the include paths for these files and anything using dirname or basename in the classes.

    These PHP files would remain in the root:

    plugin-name.php
    uninstall.php
    index.php
    
    opened by jjeaton 14
  • refactor using native add_action and add_filter functions

    refactor using native add_action and add_filter functions

    See issue: https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/issues/396

    By using native add_action and add_filter functions you're able to use IDE benefits and stick to WordPress conventions, decreasing the learning curve to new plugin developers.

    opened by yaronguez 13
  • @author and PHP Documentation Standards

    @author and PHP Documentation Standards

    According to the PHP Documentation Standards, the @author tag should not be used in plugins, 'except in the case of maintaining it in external libraries'.

    opened by GlennM 13
  • Should we move the assets directory?

    Should we move the assets directory?

    At this point, I'm interested in moving the assets directory above the root of the plugin directory.

    This is the follow the new practices of the WordPress Theme repository (as @GaryJ) has pointed out not long ago.

    The typical Subversion repository structure is:

    • assets
    • branches
    • tags
    • trunk

    As far as I'm concerned, plugin-name is analagous to the trunk directory, so this means that assets should be moved up one level; however, this places the directory with the changelog and the README which doesn't make sense.

    Instead, it feels almost like we should create a trunk directory of sorts, but I'm looking for some additional input on how to best handle this.

    opened by tommcfarlin 13
  • [How To] - Correctly perform a plugin dependency check.

    [How To] - Correctly perform a plugin dependency check.

    Hey guys, I'm after a little assistance please.

    I am writing a plugin to extend the functionality of another, I would like to set up a proper "plugin dependency check within boilerplate but unfortunately lack the knowledge of where to perform such checks as well as what the best practice for performing said checks are.

    The plugin I am extending is WooCommerce how would i go about checking that WooCommerce is installed and currently active.

    I'm assuming a check would need to be performed when my plugin is activated, other than this would there be any other instances where i would need to perform such a check?

    Could I politely ask for some assistance from my fellow, more knowledgeable developers out there! Thanks Lee.

    opened by Terminal-Access 12
  • Composer and PSR-2 refactoritzation

    Composer and PSR-2 refactoritzation

    Added Composer so that this project can be based on namespaces and dependencies, enabling more complex solutions. Also, applied the PHP PSR-2 coding standard.

    Plugin tested on local environment.

    opened by albeertito7 0
  • Installation & Naming Conventions

    Installation & Naming Conventions

    In the installation instructions it clearly states to replace "plugin_name" with "my_plugin_name". However in many example uses of this boilerplate I see $plugin_name not renamed and in fact $plugin_name is usually defined as such "$plugin_name = my_plugin_name". I've seen this as part of the construct when including additional class files, and also in the root of new classes. This is really confusing - what is the proper naming convention and are there are any instances of "plugin_name" that should not be replaced, such as those that are not exact matches and/or begin with special characters ('>', '$', etc.). If so, why is this not documented in the installation instructions?

    opened by stevegiorgi 1
  • Added support for WordPress built in functions when creating hooks

    Added support for WordPress built in functions when creating hooks

    Currently a hook defined as below would throw an error under Php 8

    $this->loader->add_filter( 'woocommerce_single_product_zoom_enabled', null, '__return_false' );

    This change let someone set the hook component as null, thus making built in WordPress functions accessible within the plugin using $this->loader->add_action or $this->loader->add_filter methods

    opened by prabch 0
  • Why not using singleton pattern?

    Why not using singleton pattern?

    I just picked up the code to use it for my plugin. I have this urge to turn some of the core classes to singletons. Before doing so, was wondering why it's not like that already.

    Any specific reason?

    opened by essentique 1
This Plugin is used to install and activate multiple plugins in one go. I was facing problem uploading plugins one by one so I developed this to solve my problem. Hope you will enjoy using this plugin.

=== Bulk Plugin Installer === Contributors: jawadarshad Donate link: https://jawadarshad.io/ Tags: bulk plugin installer, import multiple plugins, up

Muhammad Jawad Arshad 2 Sep 20, 2022
A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

Dropndot Limited 91 Dec 26, 2022
📦 A zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.

create-guten-block is zero configuration dev-toolkit (#0CJS) to develop WordPress Gutenberg blocks in a matter of minutes without configuring React, w

Ahmad Awais ⚡️ 3.1k Dec 23, 2022
Rabbit Framework - A modern way of building WordPress plugins

Rabbit Framework - A modern way of building WordPress plugins. About Rabbit Framework is a modern framework designed to be a solid foundation for your

VeronaLabs 8 Nov 20, 2022
Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace

Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace, in order to prevent conflicts with other plugins loading the same dependencies in different versions.

Coen Jacobs 362 Dec 23, 2022
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!

WP React Starter: WordPress React Boilerplate DEPRECATED: WP React Starter was a "research project" of devowl.io for the development of our WordPress

devowl.io GmbH 344 Jan 1, 2023
A WordPress package for updating custom plugins and themes based on an API response from a custom update server.

WordPress Update Handler A WordPress package for updating custom plugins and themes based on an JSON REST API response from a custom update server. Ch

WP Forge 7 Oct 5, 2022
A custom update API for WordPress plugins and themes

A custom update API for WordPress plugins and themes. Intended to be used in conjunction with my plugin-update-checker library.

Yahnis Elsts 717 Dec 31, 2022
This WP plugin will update GitHub, Bitbucket, GitLab, and Gitea hosted plugins and themes

Transition from GitHub Updater 9.x to Git Updater 10.x Due to the renaming of the plugin folders and files, after the initial update, the plugin will

Andy Fragen 3k Jan 5, 2023
Classy is a framework for building WordPress themes, based on Blade template engine

Classy is a framework for building WordPress themes, based on Blade template engine. It's fast with beautiful architecture that allows you to write le

DigitalKwarts 75 Nov 23, 2022
Hozokit - Theme Building Framework for WordPress

Hozokit - Theme Building Framework for WordPress Hozokit gives you the power to create unique WordPress themes without the WordPress hassle.

cristiano 16 Nov 15, 2022
The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

Pronamic 1 Oct 19, 2021
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
This WordPress Plugin Boilerplate is meant for you to develop your own plugin on.

WordPress Plugin Boilerplate This plugin boilerplate is meant for you to develop your own plugin on. Support & collaboration Features OOP plugin core

richardev 2 May 10, 2022
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

Pierre Saikali 3 Dec 7, 2022
A WordPress plugin to re-use the same domain name for both your website and your Rebrandly links

By installing this plugin and configuring it to connect with your Rebrandly account, you will be able to create branded links using the same domain yo

null 3 Jan 19, 2022
WordPress plugin that lets you use Discourse as the community engine for a WordPress blog

WP Discourse Note: the wp-discourse plugin requires >= PHP-5.4.0. The WP Discourse plugin acts as an interface between your WordPress site and your Di

Discourse 497 Dec 10, 2022
Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation. Some of

weLaika 1.4k Dec 9, 2022
❓ A WordPress plugin to display your site's environment type in the admin bar

Where A WordPress plugin to display your site's environment type in the admin bar. Available Filters where_env_should_add_env_type - Defaults to true

Brad Parbs 7 Mar 29, 2022