Topic: Object-Oriented Programming

Blurbette Plugin: An Object-Oriented Project

Download the Blurbette Plugin

In this series I’ll take a comprehensive look at creating a plugin from scratch. The concept is to create a custom post type called a Blurbette, which can be inserted into any posts, pages or widgets, and to offer a number of management utilities to create and control. You can download the source using the ... 

Read article

Blurbette Plugin: Copy Metabox

In this chapter, I’ll create the metabox enabling a user to copy any post to a new Blurbette. This action shouldn’t force the user to leave the edit panel, so copying ought to take place via AJAX. And, for good measure, why not track whether a post has already been copied to a Blurbette, and link to it?

My plan is ... 

Read article

Blurbette Plugin: Metabox Abstract

One of the biggest benefits of OOP is the ability to extend classes. Depending on how the classes are organized and structured, one class can take care of a lot of tedious or repetitive work, enabling you to benefit by extending it and simply defining a few additional elements.

An abstract class is one that can only be extended — it ... 

Read article

Blurbette Plugin: Admin Control Panel

In this chapter I’ll proceed a bit differently: I’ll make a few changes to WPCX_Blurbette_Def and WPCX_Blurbette_Registry first, then define the new class below.

The sole aim of this admin control panel is to update a list of options. WordPress provides a Settings API that provides output helpers and manages groups of individual settings; but for no ... 

Read article

Blurbette Plugin: Widget

Creating a widget is very simple, because WordPress provides a WP_Widget class you can simply extend and define. Four methods are required:

__construct(): the constructor which simply defines some strings and calls the parent method, form(): presents the draggable widget form in the admin panel, update(): operates when the form is updated, widget(): performs the output in the sidebar.

I’ll discuss each of the four ... 

Read article

Blurbette Plugin: TinyMCE Control

This time I’ll define a TinyMCE Control class that must be instantiated.

The last one, the Shortcode class, works fine without instantiating because all its properties are one-offs, and its public elements are available to all scopes (global and function).

This class defines a ‘thing’ that has unique properties, and there might be more than one of these ‘things,’ so it must ... 

Read article

Blurbette Plugin: Shortcode

The next class in our blueprint is the shortcode — the workhorse of the blurbette.

I’ll be sure to relegate all blurbette output to this shortcode, so proper control can be maintained and code isn’t duplicated elsewhere. In other words, if some other code wants to output a blurbette directly, it can call do_shortcode( '[blurbette id="1234"]' );.

First, I’ll design the shortcode. ... 

Read article

Blurbette Plugin: Organization and First Classes

Almost ready to start building. I’ll first decide how the files within the plugin directory are going to be organized.

WordPress requires at least one ‘main’ PHP file within a plugin directory, which begins with a standardized header. This header is essentially a copy-and-pastable ‘form’ you can replace with descriptive information; mine looks like this:

View the WordPress ... 

Read article

Blurbette Plugin: The Blueprint

In this chapter I’ll walk through an initial analysis and design phase. I’ll start with the rough concept, and end up with a wireframe we can use to build our classes in remaining chapters.

The rough concept: create a plugin that provides “Blurbettes,” which are small content clippings that can be included anywhere in a blog. Change a Blurbette, and the ... 

Read article

Blurbette Plugin: Options Metabox

The last class in the project blueprint is the Options metabox on the Blurbette admin edit panel. The aim is to present all possible contexts in which a Blurbette could appear, and offer checkboxes for each. As a bonus, if the Blurbette was copied from a post, indicate so with a link back to the post’s edit panel.

Here’s an example: ... 

Read article