If you’d like to know how the WordPress Extension Manager plugin works this page should get you started. This page is a living document and will be extended in the future, i.e. don’t expect too much and if you’d like to know how something works, have a look at the code.
Components
This plugin consists of these basic components:
- DownloadManager
- This class can be used to download files from a HTTP or FTP location into a download directory. It’s able to delete downloaded files too.
- ExtensionManager
- This abstract class manages extensions for WordPress, i.e. plugins and themes.
- PluginManager
- This class is derived from the ExtensionManager and can be used to manage plugins.
- ThemeManager
- This class is derived from the ExtensionManager and can be used to manage themes.
- Helper
- The classes FileHelper, ZipFileHelper, DateHelper and PhpHelper contain some helper methods.
Furthermore there’s the extension-manager.php which bundles the above classes into a plugin for WordPress.
Plugin and theme locations
I use a script to crawl the information about plugins and generate an XML file. Currently it just crawls the plugins from the official WordPress Repository. In the future the XML file may contain plugins from other repositories too.
The XML file format is very straightforward:
<plugins> <plugin name="Some Plugin" version="1.2.3" download="http://downloads.wordpress.org/plugin/[...].zip" href="http://wordpress.org/extend/plugins/[...]/"/> </plugins>
There’ll be a similar file for themes in the future.
Basic usage
If a user clicks on Install Plugins or Install Themes he’s presented with the information from the XML file. If he then chooses to install a plugin or a theme, we’ll download the ZIP file to the corresponding directory (either plugins or themes) and unzip it into the directory for plugins or themes where WordPress will find it. After that the user can activate the new plugin or theme.
If the user clicks on the Maintenance button he can trigger these actions:
- remove installed plugin or theme
- remove downloaded plugin or theme
Since we keep downloaded plugins and themes in a directory the user can delete these files here.
Tests
There’re some test classes too. You can find them in the tests directory. If you’d like to run them, you’ll have to use phpunit.