FontAwesome_Loader
in package
Loader class, a Singleton. Coordinates potentially multiple installations of the Font Awesome plugin code, and ensures that the latest available semantic version is selected for execution at runtime. Exposes a few public API methods for initialization (activation), deactivation, and uninstallation of plugin code.
Font Awesome plugin installations may be installed either directly as a plugin appearing in the plugins table, or as a composer dependency of any number of themes or other plugins.
We only have in mind various installations of this code base, of course. Not other non-official Font Awesome plugins. We don't try to anticipate what other potentially conflicting plugins might be installed.
All Font Awesome plugin installations should attempt to load themselves via this loader, which will ensure that the code for plugin installation with the latest semantic version is what actually runs. It also ensures appropriate handling of initialization, deactivation and uninstallation, so that the actions of one plugin installation don't interfere with another's.
Refer to integrations/plugins/plugin-sigma
in this repo for an example of how to load the Font Awesome plugin code
via this Loader when including it as a composer dependency.
The client code should require_once
the index.php
found
in the root of this code base:
require_once __DIR__ . '/vendor/fortawesome/wordpress-fontawesome/index.php';
For example, suppose the following scenario: A later version of the plugin is installed from the WordPress plugins directory and appears in the plugins table. It is activated. Then suppose a page builder plugin is installed and activated. That page builder plugin includes this plugin code as a composer dependency. In that case, the plugin code with the later semantic version will be the one loaded and executed at runtime. The page builder plugin should work just as expected, even though it would be running against a newer version of the Font Awesome plugin code than it had shipped in its own vendor bundle.
Now suppose that the site owner deactivates and deletes the plugin that appears in the plugins table, the one that had been installed from the WordPress plugins directory. Because this loader knows that the page builder plugin's installation is still present, that deactivation and uninstallation will not cause the Font Awesome plugin's options and transients to be removed from the database. And as soon as that plugin installation is removed, the Font Awesome plugin installation included in the page builder plugin's composer vendor bundle is automatically promoted and runs as expected with no change to the plugin's state in the database.
This loader pattern follows that of wponion. Thanks to Varun Sridharan.
Tags
Table of Contents
Methods
- initialize() : mixed
- Initializes the Font Awesome plugin's options.
- instance() : FontAwesome_Loader
- Creates and/or returns the static instance for this Singleton.
- loaded_path() : mixed
- Returns the path to the plugin installation that is actively loaded.
- maybe_deactivate() : mixed
- Deactivates, cleaning up temporary data, such as transients, if this represents the last installed copy of the Font Awesome plugin being deactivated.
- maybe_uninstall() : mixed
- Runs uninstall logic for the plugin, but only if its invocation represents the last plugin installation trying to clean up.
Methods
initialize()
Initializes the Font Awesome plugin's options.
public
static initialize() : mixed
If multiple installations of the plugin are installed, such as by composer dependencies in multiple plugins, this will ensure that the plugin is not re-initialized.
If the plugin's options are empty, this will initialize with defaults. Otherwise, it will leave them alone.
Any theme or plugin that uses this plugin as a composer dependency should call this method from its own activation hook. For example:
register_activation_hook(
__FILE__,
'FortAwesome\FontAwesome_Loader::initialize'
);
Tags
instance()
Creates and/or returns the static instance for this Singleton.
public
static instance() : FontAwesome_Loader
It is probably not necessary for a theme or plugin that depends upon the Font Awesome plugin to invoke this. It's probably more convenient to access the Loader's functionality through the its public static methods.
Tags
Return values
FontAwesome_Loaderloaded_path()
Returns the path to the plugin installation that is actively loaded.
public
loaded_path() : mixed
Tags
maybe_deactivate()
Deactivates, cleaning up temporary data, such as transients, if this represents the last installed copy of the Font Awesome plugin being deactivated.
public
static maybe_deactivate() : mixed
However, if this loader is aware of any remaining installations, it does not clean up temporary data, since one of those other Font Awesome plugin installations, if active, will be promoted and end up relying on the data.
Any theme or plugin that includes this Font Awesome plugin as a library dependency should call this from its own uninstall hook. For example:
register_deactivation_hook(
__FILE__,
'FortAwesome\FontAwesome_Loader::maybe_deactivate'
);
Tags
maybe_uninstall()
Runs uninstall logic for the plugin, but only if its invocation represents the last plugin installation trying to clean up.
public
static maybe_uninstall() : mixed
Deletes options records in the database.
If there would be other remaining installations previously added to this loader via , it does not delete the plugin options, since one of those others will end up becoming active and relying on the options data.
Any theme or plugin that includes this Font Awesome plugin as a library dependency should call this from its own uninstall hook. For example:
register_uninstall_hook(
__FILE__,
'FortAwesome\FontAwesome_Loader::maybe_uninstall'
);