Dusk over the highway

Using WordPress Transients To Speed Up Your PHP-Heavy Templates: Introduction

This post serves as background to an upcoming post, describing how to use transients to selectively cache WordPress markup.

WordPress is a powerful content management system, and over the years its ability to render very complex data in pleasing, human- and machine-readable formats has been greatly improved.

Thanks to changes in the taxonomy model, as well as improvements in the core functions that surround templates / themes, a designer doesn’t run into nearly as many cases these days of having to run lots of PHP code in a template file.

Even so, sometimes you just can’t avoid having to use a template file to run a complex WP Query, or otherwise put together a bunch of PHP to get something onto your WordPress-based site.

As you’ve no doubt discovered, depending on how code-heavy your template proves, and what resources your Web server has, this can lead to very long processing times, meaning very slow page loads.

Worse, on-template PHP code often can’t be cached, especially if it isn’t centered around a single post / page or a particular taxonomy term.

Continue reading

Beach To Beacon 10K finish line by Ben McCanna. All rights reserved, used by permission.

Make Your First WordPress Plugin: A WordCamp Maine 2014 Presentation

This post is a companion to my WordCamp Maine 2014 talk, “Make Your First WordPress Plugin.”

It’s effectively a recap of an earlier post, Making A Simple WordPress Plugin, with elements from Hooking WordPress Taxonomy Changes With The Plugins API.

If you know how to make, or hack, a WordPress theme, you have all the skills you need to write a plugin.

All it takes is a little knowledge of how to write PHP, a basic understanding of how WordPress goes about making Web pages, and a little trial and error. Oh, and the same, basic tools you use to make any website:

A decent text editor is the only “must have.”

For Macintosh, TextWrangler will work fine; I prefer its full-featured sibling, BBEdit. Protip: Download these directly from BareBones; the Apple Store versions don’t support all features and can make upgrading difficult.

For PC, I use Notepad++; others swear by Sublime Text.

A Web development IDE, such as Dreamweaver, WebMatrix or even Visual Studio will work, too; although these tools, in their zeal to make things easier, can significantly complicate writing plugin code.

Regardless of whether you use a Mac or PC, don’t use the built-in text editors (TextEdit and Notepad, respectively); they tend to introduce file encoding that can prove problematic when trying to write plugins.

Optionally, it’s good to have an FTP program. While this isn’t strictly necessary, it makes salvaging a plugin installation that has gone horribly wrong a lot easier. If you’re an OS guru you can, of course, just use your Web browser for FTP, or maybe install an FTP plugin; but I prefer to use FileZilla on PC and Transmit on Mac.
Continue reading

These are the properties of a WordPress post. Source: WordPress Codex, XML-RPC WordPress API/Posts

Using The WordPress XML-RPC API With PHP: The Post Model’s Properties

Part 4 in a series on working with the WordPress XML-RPC API with PHP.

Previously I discussed the reasons for creating a data model (aka a class), that looks like a WordPress post, in order to streamline and simplify working with the WordPress XML-RPC API.

In this post, we’ll create the properties, or data, that goes into that model. This will help us make heads and tails out of what we need to send to the XML-RPC API, and what we’ll get back, when working with posts.
Continue reading

Hooking WordPress Taxonomy Changes With The Plugins API

Captain Hook twirls his moustache at Breakfast in the Park with Minnie & Friends at the Plaza Inn by Loren Javier, on Flickr

So you’ve developed a plugin, or a theme function, in WordPress that needs to know when a taxonomy term — in a category, tag or custom taxonomy — is added, edited or deleted.

Unfortunately, the WordPress Codex barely mentions how to do this, and the examples you see out there on the Web basically regurgitate the same odd instructions, which boil down to passing in some integer parameters that can’t possibly be correct for every example.

Like this:

add_action('create_stores', 'my_create_stores', 10, 1);

That’s unfortunate. So let’s clear up the mystery of how WordPress notifies plugins and theme functions of a taxonomy change, and how we can go about writing a sensible treatment for those events.
Continue reading

This is where you set the PHP version for your Azure website. Note that version 5.4 is the default version selected when you create an Azure website.

Microsoft Azure Doesn’t Load The SQL Server PDO Driver In PHP Version 5.5

Another of those “learn from my mistakes” moments: Azure Web Sites don’t include the SQL Server PDO extension if your site is running PHP 5.5.

This I learned the hard way today.

I set up my site to run PHP 5.5.11, the version that as of this writing Azure uses. But my script halted without warning; knowing from experience that this meant there was a PHP error, I quickly popped into my site’s log and saw this entry:

[23-Jun-2014 12:52:36 America/Los_Angeles] PHP Warning:  PHP Startup: Unable to load dynamic library 'D:\Program Files (x86)\PHP\v5.5\ext\php_sqlsrv.dll' - The specified module could not be found.

Continue reading