A Plugin-in is a piece of software or custom code that extends an application. Reich Web Consulting specializes in creating custom WordPress plugins, for example.

Posts

Creating a WordPress Plugin, Part 1: Naming Your Plug-in

[amazon_enhanced asin=”0470916222″ /]

The first and arguably most important step in creating a WordPress Plugin is choosing a name for it. If you plan to share your plug-in with others it should obviously be catchy, but more importantly it should also be unique for two very good reasons explained below.

Make Your Plugin Stand Out

WordPress has a vast number of free and commercial plugins available. If you choose to share your plug-in with others you’ll want your plug-in to stand out from the rest. Before you decide on a name for your plug-in, use Google and the WordPress Plugin Directory to do some research. Rather than call our recipe plug-in that we’ll be creating simply Recipes, we’re going to call it Delicious Recipes, by Reich Web Consulting.

Namespacing

Regardless of whether or not you choose to share your plugin with others, when you begin coding you’ll have to make decisions about naming things like functions, classes, constants, and other identifiers.  Identifiers must be unique not just within your plugin but to PHP, WordPress, your active theme, and any other active plug-ins.  Defining two identifiers with the same name will result in a namespace collision: an error condition in which two or more identifiers have the same name.  Lets say we’ve written the following PHP code:

// Intentially cause a namespace collision: 
function printf( $args ) { 
    // Function definition
}

Because the printf() function already exists in PHP, the following error is generated:

An example of a PHP namespace collision error.

Using the PHP and WordPress documentation you can safely avoid namespace collisions with PHP and WordPress, but how do you avoid colliding with the thousands of other plugins and themes that you and others might install alongside of your own? The answer is to namespace your plugin code. 

How do you namespace your plug-ins?  It’s as simple as choosing a prefix that’s presumably unique to your plug-in and appending it to all global identifiers. The name of my company is Reich Web Consulting and the plug-in we will be developing is for managing recipes, so I’m going to choose RC_Recipes as my namespace:

<!--?php /*  * Define a namespaced class.  */ class RC_Recipe_Plugin {      // Class code } /*   * Define a namespaced function.    */ function rc_recipe_plugin_function( $args ) {      // function code  } /*   * Define a namespaced constant.   */ define( 'RC_RECIPE_CONST', 0 ); ?-->

If you’re experienced with PHP you might be wondering why we don’t solve the problem of namespacing by using PHP’s built-in namespace feature. The reason it’s not used is because, at of the time this tutorial was written, WordPress requires version 5.2.4 of PHP, which does not support namespaces. While you could still write your plug-in using PHP namespaces you would be seriously limiting the number of people that could use it by requiring a version of PHP newer than that which WordPress itself requires.

Summary

Before you go all gung-ho slinging code it pays to takes a few minutes to consider the design and marketing implications of naming your plugin.  Choose something unique but catchy, and use your plug-in name to create a unique namespace for your code.   In the next part of this tutorial we’ll be creating the directory and file structure for out plugin.  Catch you then!

Choosing a WordPress Backup Plugin

One of the first things you should do after installing a new WordPress blog is configure backups. Though WordPress does feature an export feature that allows you to save much of your content to XML, there isn’t a full-blown backup feature built into the WordPress Core. You’ll need to download a WordPress backup plugin.

Features to Look For in a WordPress Backup PlugIn

These are the minimum features that I look for in a backup plug-in.  You may have different requirements than my own but if your backup plug-in doesn’t provide these features, you will eventually find it lacking.

  • Backs up the entire database, not just the core WordPress tables. In the event that your site crashes and needs to be restored, you’re going to need a backup of your database.  The last thing you want is to restore your database and find that plug-in content such as purchase records in a shopping cart plugin or images stored in a gallery plug-in no longer exist.
  • Backup the entire WordPress Directory. Some backup plug-ins only backup the database, but there is plenty of content that’s stored on the filesystem and not the database including uploaded media, plugins, and theme customizations. Choose a plugin that backs up the entire file system for your blog. That way when a crisis occurs, you can simply dump the files and database back to the server and continue business as usual.
  • Scheduling. Your backup plug-in should provide some sort of scheduling feature that can automatically perform backups as a daily, weekly, or monthly task. You shouldn’t have to remember to manually backup you blog, though a manual backup feature is helpful as well.
  • “Off-Site” Backup.Your backup plug-in should have some way of saving your backup off site. It could be by emailing them to you, uploading them to an FTP site: anything that duplicates your blog data to a second server in case your server is physically damaged. A plug-in that simply saves the backup to the same server that hosts your blog doesn’t protect you from the all-to-common hard drive failure, your hosting company going belly-up, or any other scenario that prevents you from getting access to  your data.

Backing Up WordPress to DropBox

I use DropBox to store business records and other important files, and so I’ve settled into using the WordPress Backup to DropBox plugin for most of my sites.  The plug-in provides all of the features that I mentioned above.  In addition it gives me access to those backups from my PC via the DropBox desktop application, and gives me confidences that my backups are occurring when I scheduled them because I can see the files updating in real-time.

Another excellent and popular plugin is Backup Scheduler. It allows you to specify what gets backed up (database, files, or everything), and has the option to send you the backup via email.

Converting My Business to Linux, Part 3: Adobe Acrobat

(Back to Converting My Business to Linux, Part 2: Installation)

If tonight’s experience is any indication, my goal of 100% transformation from Windows to Linux is probably not going to happen.

Tonight I was asked my one of my clients to change a single page of a PDF document hosted on their website. No problem in the pay-to-play land of Windows, right?  You fire up your ridiculously-priced copy of Adobe Acrobat Professional and use the Replace Page menu option.  Dead simple.  On Linux? Not so much.

Editing PDFs on Linux

If all you need to do with PDF on Linux is view and print, your options are numerous and quite stable.  If you don’t like Ubuntu’s built-in PDF viewing support you can opt to download and install Adobe Reader from the Canonical Software Repository. Of course, that’s only if you miss all of the bloated and unnecessary features that make Adobe Reader what it is today.

If you have to create or edit existing PDF documents, you’re options are few and finicky.  I tried two methods: the first was to install PDF Edit from the Ubuntu Software Center.  PDF Edit has lots of features, but it couldn’t open the document that I needed to modify.  Upon further research I found that OpenOffice.org has a PDF Import extension.  I installed the extension, and it too had problems opening my document. Perhaps something was wrong with my docuement?

The Problem

I installed Adobe Reader as described above so I could verify that my PDF file would open using an Adobe product and so I could view it’s metadata.  Reader opened the document without any problems, but within the document metadata I noticed that the document had been created using the HP scanning software at my client’s office.  I tried opening other documents created with that software and verified that they opened in Adobe Reader, but not in PDF Edit or in OpenOffice.

The Solution

This isn’t so much a solution considering I still had to have Windows and Acrobat Professional available to solve the problem.  I opened the documents in Acrobat Professional and performed a “Save As.”  The new documents were now editable under both PDF Edit and OpenOffice.org’s PDF Import extension.

PDF Edit was able to quickly and easily replace the page that had changed within the document.  If it is able to open my documents in the future, this is what I’ll use to make changes to PDF documents on Linux.  The OpenOffice.org plug-in still has a long way to go.  It does exactly what I expected and what Microsoft Word import utilities have done for years: butchers your document.  But at least it opened!

Summary

I may find myself updating this post in the future as I have more experience editing PDF’s on Linux.  My initial impression is that “it’s close, but no cigar. PDF Edit almost worked, and if it is able to open and edit my PDF’s in the future I’ll consider this a success.  OpenOffice.org’s plug-in works just as good as other PDF Conversion utilities:  it will import your document and keep most of your text intact, but any graphics or stray marks in your PDF document will make your converted document almost completely unusable.

(Continue to Converting my Business to Linux, Part 4: Updating my IPhone)