Book Image

WordPress 3 Plugin Development Essentials

Book Image

WordPress 3 Plugin Development Essentials

Overview of this book

WordPress is one of the most popular platforms for building blogs and general websites. By learning how to develop and integrate your own plugins, you can add functionality and extend WordPress in any way imaginable. By tapping into the additional power and functionality that plugins provide, you can make your site easier to administer, add new features, or even alter the very nature of how WordPress works. Covering WordPress version 3, this book makes it super easy for you to build a variety of plugins.WordPress 3 Plugin Development Essentials is a practical hands-on tutorial for learning how to create your own plugins for WordPress. Using best coding practices, this book will walk you through the design and creation of a variety of original plugins.WordPress 3 Plugin Development Essentials focuses on teaching you all aspects of modern WordPress development. The book uses real and published WordPress plugins and follows their creation from the idea to the finishing touches in a series of easy-to-follow and informative steps. You will discover how to deconstruct an existing plugin, use the WordPress API in typical scenarios, hook into the database, version your code with SVN, and deploy your new plugin to the world.Each new chapter introduces different features of WordPress and how to put them to good use, allowing you to gradually advance your knowledge. WordPress 3 Plugin Development Essentials is packed with information, tips, and examples that will help you gain comfort and confidence in your ability to harness and extend the power of WordPress via plugins.
Table of Contents (19 chapters)
WordPress 3 Plugin Development Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Tools for web development


The tools you need to develop plugins for WordPress are essentially the same tools you need for developing almost any web application, specifically:

  • WordPress

  • Text editor

  • FTP client

  • MySQL client (optional)

WordPress

If you are going to develop plugins for WordPress, you need WordPress itself and an environment that can run it. Download the latest version of WordPress from http://wordpress.org/download. It is then just a matter of finding a suitable place to install it.

WordPress 3 runs on a web server (most commonly Apache) that can run at least PHP 4.3 and MySQL 4.1.2—WordPress 3.2 requires PHP 5.2 and MySQL 5.0.15. Since both PHP and MySQL are widespread web technologies and WordPress is such a popular blogging tool, most hosting providers can support running WordPress on their servers. If in doubt, consult your web host's FAQ.

Another option is to run WordPress in a "sandbox" environment on your own computer. This can be more involved since you have to set up your computer as a web server and configure several other inter-related technologies, but thankfully there are bundled packages available that do much of the difficult work for you—we have listed a few options for these types of packages below.

A third option is to run a virtual machine on your local computer using emulation software like Parallels (http://www.parallels.com), VMware (http://www.vmware.com) or VirtualBox (http://www.virtualbox.org). This can be a great way to mimic your intended production environment precisely and still get all the benefits of hosting your site locally, but it does require some solid system administration skills, so this option is mainly recommended for seasoned developers.

If you plan to run a "sandbox" testing ground on your own computer, you have a few options depending on the platform.

Mac

Since Mac OS X ships with Apache and PHP—and MySQL can be compiled to run natively—you can run WordPress directly on your Macintosh. However, this requires a fair amount of non-trivial sysadmin skills, so we strongly recommend that you download an all-in-one pre-configured PHP-MySQL package.

Two solid options are:

Both are free packages that include all you need to get your Mac ready for WordPress.

Windows

On Microsoft Windows, there are several options. You can try:

All of the above options are free and will get the job done. For reference, the Microsoft Web Platform uses IIS as the web server instead of Apache. Refer to the relevant website for instructions on how to install and set up any of this software.

Text editor

You don't need anything special when it comes to a text editor, just something that can write plain, unformatted text files. Don't try using a word processor such as Microsoft Word because it will add all kinds of formatting. We strongly recommend, however, that you go a little bit beyond the basic requirement of authoring text files and find an editor that offers the following features:

  • Syntax highlighting: This could save you hours of frustration by helping you spot variables, missing quotes, or other errata.

  • Locate matching parentheses, brackets, or braces: Many times syntax errors are caused when you inadvertently omit a curly brace or a parenthesis. Being able to locate the matching unit of these paired symbols will help you track down these types of errors more quickly.

  • Find and replace across multiple files: A massively timesaving operation.

  • Displays line numbers: PHP will reference line numbers when it encounters errors.

On a Mac, TextWrangler (http://www.barebones.com/products/textwrangler) is a free application that lets you work on multiple files simultaneously, made by the same folks who make the venerable BBEdit (which is a viable option if you need more features and are willing to spend a bit of money). TextMate (http://macromates.com) is on par with BBEdit and is a direct competitor. A tremendous editor for Mac OS X is Coda (http://www.panic.com/coda). It really is the Swiss Army Knife of web development applications. Coda keeps your files organized, lets you preview HTML and CSS, does syntax highlighting on all kinds of files, offers auto complete on function calls, acts as an FTP, SSH, and a lightweight SVN client, and even has plugins that will help you check your code for errors. If you have a budget for your projects, Coda is a time-saving application.

On Windows, there are several free text editors worth examining, including NotePad++ (http://notepad-plus-plus.org), PSPad (http://www.pspad.com), and NotePad2 (http://www.flos-freeware.ch/notepad2.html). One excellent commercial offering is UltraEdit (http://www.ultraedit.com).

Using an IDE

You may consider using a full blown Integrated Development Environment (IDE) such as Eclipse (http://www.eclipse.org), Sun's NetBeans (http://netbeans.org), Jet Brain's PhpStorm (http://www.jetbrains.com/phpstorm/), or the Zend Studio IDE (http://www.zend.com/products/studio), all of which run on Mac, Windows, or Linux.

These are powerful programs, but they aren't easy to use so their complexity may be off-putting. Compare a 16 MB footprint for a standalone text editor such as TextEdit to the behemoth 470 MB of the Zend Studio IDE and you get some idea of the resources required to run each program. The more development you do, the more you will gravitate toward IDE applications because they offer unmatched features, but they're not generally recommend for first time developers. NetBeans is free and relatively resource friendly, so it is a good option if you are looking to explore the world of IDEs.

On the lightweight end of the spectrum, you can use one of the feature rich and battle-tested command line editors: vi or eMacs. They offer enormous flexibility and features directly from any *nix command line. Although it is extremely useful for a developer to be capable of editing files from a command line, the keyboard-only interface and steep learning curve of these editors precludes them from mainstream use, so we don't recommend you use them as your primary editing application.

Tip

No matter which editor you choose, make sure it helps you get your work done instead of becoming a chore unto itself. Refer to each vendor's site for instructions on how to install and configure them.

FTP client

In order to transfer files from your local computer to your destination web server and back again, you need an FTP client (or an SSH client) to facilitate the copying. The application need not be fancy, but it should be easy to use because chances are good that you will be using it a lot.

On Mac OS X, the aforementioned text editor Coda includes FTP functionality; CyberDuck (http://cyberduck.ch) offers a fine standalone client with the ability to bookmark sites and access Amazon S3 folders. Though not free, Transmit (http://www.panic.com/transmit) has a slick interface and it stands out as one of the only FTP clients that offers the OS X "column view" of files and folders.

On Windows, FileZilla (http://filezilla-project.org) is a solid offering. There's also the venerable WinSCP (http://winscp.net), as well as Core FTP LE (http://www.coreftp.com). All three of these programs are free.

MySQL client

Depending on the level of developing that you do with WordPress, you may not need a MySQL client, but it is extremely handy to have one available, and it can be good to have this window into your database. After all, the database has much of your content and settings, so eventually you will want to see what's going on in there.

On a Mac, if you installed the MAMP package, it comes with phpMyAdmin. This works in a pinch, albeit clumsily because it is a web application. Sequel Pro (http://www.sequelpro.com) is one of only a handful of options for desktop SQL clients on Mac OS X.

SQLyog (http://www.webyog.com) is the Windows-only benchmark—it's a powerful desktop client with an intuitive interface and sensible shortcuts.

phpMyAdmin is also available for many Windows installations, including XAMPP and EasyPHP, so don't feel obligated to purchase software if it's not in your budget.