Toppa Plugin Libraries for WordPress

Support development of Toppa Plugin Libraries

I am currently no longer developing or supporting my WordPress plugins. I may resume development and support in the future, but I’m not sure when.

The Toppa Plugin Libraries for WordPress include several utilities for plugin developers. They facilitate the use of Agile coding techniques for developing WordPress plugins. They are also required for using SimpleTest for WordPress, and for upcoming revisions to my other plugins. Each is written to conform to an object interface. This means that if you code your plugin against the interfaces, you can write unit tests for your plugin, and potentially use it outside of WordPress (you would need to write non-WordPress specific versions of the Toppa Library classes that conform to the interfaces, but you would not need to alter your plugin itself). The following libraries are included.


This gives you an easy way to autoload class files for WordPress plugins. It conforms to the PSR-0 standard for autoloading in PHP, except it does not yet support namespaces (since WordPress currently is not intended for use with features that were introduced in PHP 5.3). Here’s how it’s used:

// Include the autoloader class file (relative to where
// you're calling it from is typically the best way)
require_once(dirname(__FILE__) . '/../toppa-libs/ToppaAutoLoaderWp.php');

// Register an autoloader for your plugin (this example
// is from my Shashin plugin). Pass it the parent directory
// for your plugin, relative to the plugin directory.
$shashinAutoLoader = new ToppaAutoLoaderWp('/shashin');

// Design your main class to accept the autoloader registered
// for it. Save the autoloader as a property of the class.
$shashin = new ShashinWp($shashinAutoLoader);

// Now you can call "new" on other classes in your plugin
// without having to explicitly include the files for them.
// You will need to conform to the PSR-0 naming standard
// for your classes.


This class creates a facade (wrapper) for functions that are custom to WordPress. This allows you to write your plugins without calling WordPress functions directly. This gives you the power to do 2 things: 1. write unit tests for your plugin, and 2. make your plugin potentially usable outside of WordPress. This is a new library, and coverage of WordPress functions is currently very limited.

It also includes several “helper” methods, which simplify common tasks. The most useful of these is for making plugins mult-site compatible. You can read the details in this post.

Example usage:

class Admin_ShashinMenuDisplayerAlbums extends Admin_ShashinMenuDisplayer {
    // ...

    function __construct(ToppaFunctionsFacade $functionsFacade) {
        $this->functionsFacade = $functionsFacade;
        // ...

    // ...

    public function generateSyncLink() {
        // ...
        // this facade method calls the wp_nonce_url function
        $noncedUrl = $this->functionsFacade->addNonceToUrl($url, $nonceName);
        // ...

    // ...


This is similar in concept to ToppaFunctionsFacade, but focuses on database interactions. In addition to creating wrappers for WordPress database calls, it includes enhanced functionality for tasks such as creating custom tables.

Example usage:

class Lib_ShashinAlbum extends Lib_ShashinDataObject {
    // ...

    public function __construct(ToppaDatabaseFacade $dbFacade) {
        $this->dbFacade = $dbFacade;
        // ...

    // ...

    public function flush() {
        // the sqlInsert() method wraps the $wpdb->query() function, but provides
        // additional functionality. It can write the query based on a passed in array
        // of data, and the 3rd argument indicates it should make an "on duplicate
        // key update" query, so we can automatically handle updates as well
        $insertId = $this->dbFacade->sqlInsert($this->tableName, $this->data, true);
        // ...


This is a lightweight utility for creating HTML form fields. It is not a complete form builder. Instead it is intended to make it very easy to create form fields in a standardized way, and then lets you use them however you like. It has no WordPress dependencies – you can use it with or without WordPress. Here is an example of its usage:

// 'rssUrl' is the name applied to the input field
// $refData['dataUrl'] is an array that contains data necessary to build the field
echo ToppaHtmlFormField::quickBuild('rssUrl', $refData['dataUrl']);

// the resulting output is
// <input type="text" name="rssUrl" id="rssUrl" size="100" maxlength="255" />
// maxlength conforms to the maximum size allowed in the database fields
// this library is especially useful for more complex "select" and "radio" inputs

Want to Contribute?

The latest revisions are always available at GitHub. Code contributions through GitHub are welcome. Stable releases are available at

Leave a Reply