Anatomy of a Textpattern Plugin, part 1

A PHP developer’s guide to writing Textpattern plugins.

Audience

The remainder of this series assumes some experience with both Textpattern and PHP.

If you’re not already comfortable with PHP, I’d recommend against trying to learn it by writing Textpattern plugins. Though they’re not difficult to write, testing and debugging a plugin requires some knowledge and experience beyond that of a simple “hello world” script.

In particular, you should be familiar with PHP’s scoping rules, associative arrays, and have some experience at debugging before you start your first plugin.

PHP Resources

Some recommended reading, if you need to brush up on PHP or MySQL:

For novice programmers, PHP and MySQL Web Development comes highly recommended.

For those who already know another programming language, but need an introduction to PHP, Beginning PHP 5 and MySQL is probably your best bet. Don’t let the title fool you – it’s aimed at beginners to PHP, not novice developers.

The O’Reilly books are easy to find, but a bit of a mixed bag. Learning PHP 5 is a decent introduction for beginners, and inexpensive, but incomplete. The PHP Cookbook includes plenty of useful examples, but is not well suited for beginners – it includes obsolete code and some unfortunate errors.

If you’re already a PHP developer, I highly recommend the New Riders PHP Functions Essential Reference. It’s a consise reference, not a tutorial, and thus not good for beginners, but indispensible as an everyday tool. Think of it as your offline copy of php.net.

On the MySQL front, I have an older edition of MySQL by Paul DuBois. It’s main flaw is its age; the 3rd ed was published in 2005, so should remedy that.

Online, you’ll find php.net is your first stop. The tutorial is concise but helpful.

If bookmarks wore out, I would’ve replaced the manual three times over by now. The lanugage reference section is dry but essential. You’ll find every function listed in the function reference – including those in optional extensions, so watch your dependencies. Also be wary of the advice in comments submitted by readers; there’s a mix of good and bad in there, so be skeptical and test carefully.

Textpattern documentation & tutorials

If you’re familiar with PHP but not Textpattern, you’ll want to get comfortable with txp before you start.

The Textpattern FAQ (written largely by yours truly) covers the most common problems and “How do I..” scenarios. The Now what? question gives a quick overview of how the main concepts fit together.

Textbook is the main source of user documentation for Textpattern. It’s incomplete but growing.

And finally, Textpattern Resources provides a directory of links to plugins, themes and documentation.

Conventions

Throughout this series I’ll present several different types of examples: PHP code, Textpattern template tags, and XHTML output. To distinguish between them, they are presented slightly differently. The exact appearance might depend on your browser:

echo "This is PHP code";
<txp:older>This is Textpattern template code</txp:older>
<h3>This is XHTML output</h3>

In this series


Commenting is closed for this article.