PHP Classes for WordPress

PHP Classes for WordPress

Rubix Cube with WordPress LogoUsually in WordPress, a PHP class (other than those loaded by PHP itself) is either part of WordPress Core or bundled with a plugin or theme. That is a very poor design because it often results in many copies of the same class being included in different plugins and themes. Over time it results in different version of the same class, with only one version actually being the version that loads, and you have no control over which.

It also can result in legal problems. If I sell a commercial plugin that includes a GPL licensed class in my plugin, then I am in violation of the GPL license. But if my commercial plugin only makes use of the API of a GPL class installed on the system but does not include the class itself, then I am not in violation of the GPL license.

This is why having a PSR-4 Autoloader in WordPress is so important. It means only one copy of a class needs to be installed (the logical thing to do because only one copy can be loaded by PHP anyway) and it resolves the legal issues related to what license a class is distributed under.

All of the open source classes I have written and will write for WordPress are available in a single collection of classes. Generally they are under an MIT license, but when I extend another class or create a new class by modifying another class, I tend to use the same license used by the class I am extending or modifying.

All files including PHP will have a PHPdoc description at the top of the file (after any declare directives) that will always specify the license of that file.

To install a PSR-4 autoloader for WordPress, see my Class Autoloader page.

This page describes the classes currently in my personal collection, named after my top level namespace, AWonderPHP.


Namespace: \AWonderPHP
Fully Qualified Class Name: \AWonderPHP\AWMFontBuilder

The main page for this class: AWonderPHP-AWMFontBuilder.

This class simplifies the use of web fonts served from Google Fonts API compatible font servers.


Namespace: \AWonderPHP
Fully Qualified Class Name: \AWonderPHP\Compat

The main page for this class: AWonderPHP-Compat.

This is a static class that provides compatibility solutions with some deprecated and/or problematic PHP functions.


Namespace: \WonderPHP\Exceptions

The classes in that namespace are only meant to be used by my classes and plugins. They extend core PHP exceptions with more meaningful messages. For your own code, if generic PHP exceptions are not good enough, you probably should create your own that meet your needs.


Namespace: \AWonderPHP\Groovytar
Fully Qualified Class Names: \AWonderPHP\Groovytar\Groovytar, \AWonderPHP\Groovytar\WordPressGroovytar

The main page for these classes: AWonderPHP-Groovytar

These classes provide an alternative to Gravatar that has better anonymity and does not track users.


Namespace: \AWonderPHP\OpenGraph

These classes are a work in project and not yet ready to be used.

They will be used in an OpenGraph plugin being authored, but some of them will be usable by those writing their own OpenGraph plugins.


Namespace: \AWonderPHP\PluggbleUnplugged
Fully Qualified Class Names: \AWonderPHP\PluggableUnplugged\AdminMenu, \AWonderPHP\PluggableUnplugged\Misc, \AWonderPHP\PluggableUnplugged\PunycodeStatic, \AWonderPHP\PluggableUnplugged\UnpluggedStatic, \AWonderPHP\PluggableUnplugged\WPCoreReplace

These classes are used by my PluggableUnplugged WordPress plugin. Some of these classes provide useful features outside the context of that plugin.

The main page for these classes: Not yet written.


Bare with me, work in progress

Anonymity protected with AWM Pluggable Unplugged