Download the PHP package wpsmith/plugin without Composer
On this page you can find all versions of the php package wpsmith/plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wpsmith/plugin
More information about wpsmith/plugin
Files in wpsmith/plugin
Package plugin
Short Description Core class for extending WordPress plugins and hiding WordPress plugins on the plugins page.
License GPL-2.0+
Homepage https://github.com/wpsmith/Plugin
Informations about the package plugin
Plugin
A class to use in your WordPress plugin to prevent updates to the plugin, ensure dependency plugin(s) is/are active, and to hide specific plugin(s).
Description
These classes solve three (3) particular problems:
-
Preventing plugins from updating
Plugins and themes are automatically checked by WordPress for updates in the WordPress repository. This poses a special problem for private plugins if the plugin slug happens to match.
-
Hiding Plugins
It is a best practice to move specific functionality to a core functionality plugin. One could use a mu-plugin but most use a standard plugin. However, the client could easily deactivate or delete the plugin. Therefore, hiding the plugin from the plugins page becomes very important.
-
Extending Plugins
Many core functionality plugins extend/modify other plugins. If the dependency plugin that is being extended is deactivated, then the plugin makes the WordPress instance unstable and breaks the whole site.
-
Uninstalling Plugins
It is a best practice to always uninstall your plugin data and files. However, an interface to determine what should be uninstalled needs to be built. This uses WP Pointers to create such an interface giving the user the choice to uninstall just the plugin files or everything.
-
Building Plugins
When building a plugin, this library provides a base class to be extended as the new plugins core class.
Installation
This isn't a WordPress plugin on its own, so the usual instructions don't apply. Instead you can install manually or using composer
.
Manually install class
Copy Plugin/src
folder into your plugin for basic usage. Be sure to require the various files accordingly.
or:
Install class via Composer
- Tell Composer to install this class as a dependency:
composer require wpsmith/plugin
- Recommended: Install the Mozart package:
composer require coenjacobs/mozart --dev
and configure it. - The class is now renamed to use your own prefix to prevent collisions with other plugins bundling this class.
Implementation & Usage
Update Prevention
To prevent the current plugin from updating:
To prevent another plugin (e.g., ACF) from updating:
Hiding Plugin(s)
To hide the current plugin:
To hide another plugin (e.g., ACF):
Extending Plugin(s)
To extend ACF, you would do something like this:
Uninstalling Plugin(s)
To use the UninstallManager
, you would do something like this at the plugin's root:
Simple example
Within the plugin's main file:
A Better Example
Within the main plugin file:
Then in uninstall.php
:
Building a Plugin
For all my plugins, I build a base class for the main plugin. Out of the box, PluginBase
does three things:
- Loads plugin's text domain accordingly.
- Implements
Singleton
so there can only be one. - Provides the following methods:
Plugin::doing_ajax()
orPluginBase::doing_ajax()
- determines whether WP is processing an AJAX request.Plugin::get_version()
- gets the plugin's version. Defaults to0.0.0
.Plugin::get_plugin_name()
- gets the plugin's name. Defaults towps
.~~~~$this->get_template_loader()
- gets the plugin's template loader. See TemplateLoader.$this->add_action()
- Either adds the action to the correct hook or performs the action if the hook has already been done or is being done.
Generally speaking, it goes something like this:
Change Log
See the change log.
License
GPL 2.0 or later.
Contributions
Contributions are welcome - fork, fix and send pull requests against the master
branch please.
Credits
Built by Travis Smith
Copyright 2013-2020 Travis Smith