Registering widgets in WordPress is annoying.
All of the functionality is bundled up nicely in the WP_Widget
class, but you can’t use an object method for the registration. Most PHP classes I see used in the WordPress space are pseudo namespace singletons. They have a helper for registering methods to hooks, and then the object is instantiated and the helper called. The various class methods are hooked in with something like add_action( 'init', array( $this, 'method_name' ) );
. There is nothing inherently wrong with this approach. It provides a nice pseudo namespace for code that is PHP 5.2 compatible. When it comes to widget registration, though, that pattern just doesn’t work.
Continue reading