Book Image

WordPress Plugin Development: Beginner's Guide

Book Image

WordPress Plugin Development: Beginner's Guide

Overview of this book

If you can write WordPress plug-ins, you can make WordPress do just about anything. From making the site easier to administer, to adding the odd tweak or new feature, to completely changing the way your blog works, plug-ins are the method WordPress offers to customize and extend its functionality. This book will show you how to build all sorts of WordPress plug-ins: admin plug-ins, Widgets, plug-ins that alter your post output, present custom "views" of your blog, and more. WordPress Plug-in Development (Beginner's Guide) focuses on teaching you all aspects of modern WordPress development. The book uses real and published WordPress plug-ins and follows their creation from the idea to the finishing touches, in a series of carefully picked, easy-to-follow tutorials. You will discover how to use the WordPress API in all typical situations, from displaying output on the site in the beginning to turning WordPress into a CMS in the last chapter. In Chapters 2 to 7 you will develop six concrete plug-ins and conquer all aspects of WordPress development. Each new chapter and each new plug-in introduces different features of WordPress and how to put them to good use, allowing you to gradually advance your knowledge. This book is written as a guide to take your WordPress skills from the very beginning to the level where you are able to completely understand how WordPress works and how you can use it to your advantage.
Table of Contents (14 chapters)
WordPress Plugin Development
Credits
About the Author
About the Reviewer
Preface
Index

Tools for the job


Before we get started, we need to have some tools set up, so let's go through a short check list.

Whatever way you decide to set up your development environment, make sure you are comfortable using it. Plugin development can be a full-time job, so make sure you enjoy it as much as you can!

WordPress

Obviously, we will need WordPress installed. It is advisable to have a separate version of WordPress for development purposes (that is, do not use your blog as a testing ground; your visitors will not like it very much).

To prepare your local version, you can always download the latest version of WordPress from http://wordpress.org/download/.

Then you need to decide if you are going to host it on the Internet or locally. I prefer to have it on Internet as I can easily show it to other people if necessary, no matter where I am at that moment. The advantage of local installation is that it works much faster. You can of course combine both.

If you are going to set it up on your local computer, and you are using Windows, using packages such as EasyPHP (http://www.easyphp.org) will make your job much easier. This is a software package that incorporates PHP and MySQL for Windows systems, and is free to use.

Installing WordPress is a simple matter. I recommend going to http://codex.wordpress.org/Installing_WordPress for the latest guide to the installation process.

If you would like to set up the latest development version, I suggest you read the section Using SVN in Chapter 8.

Text editor

Obviously, you are going to need a text editor. Any editor will do, and you probably have a preference by now.

You do not need your text editor to do anything fancy. Indentation support and syntax highlighting for PHP, HTML and JavaScript is almost all you need from an editor at this point.

I have been using UltraEdit for years, and it has been always my weapon of choice for a quick, small, and powerful editor. There also are other text editors that are available for free, such as, Netbeans IDE for PHP, Zend Studio, and so on.

FTP client

The second thing you will need to have is an FTP client. Uploading plugins can be a boring job if you do it from the FTP command line; so visual FTP client is advisable.

For this matter, I've been using Total Commander as a proven tool. Again, you might have your own preference.

Web browser

Finally, since we are developing web based software, we will need a web browser. You will be spending a lot of time in the browser window; so make sure you are comfortable with it.

I do not want to instigate browser wars at this moment, but there is one browser that is very flexible and has tons of add-ons, much like WordPress in that respect, and that is Firefox.

There are some pretty cool add-ons for Firefox that can really increase productivity to the level of rapid web development. This step is optional if you do not use Firefox, but I would nevertheless recommend giving it a try.

Firebug

The most important Firefox add-on we want to install is called Firebug (you can download it from http://getfirebug.com).

Firebug allows you to preview, edit and debug CSS, HTML, JavaScript and Ajax requests in real time. This is really a great time saver. For example, when it comes to debugging, JavaScript or misaligned CSS can be really troublesome, without the use of features provided by Firebug.

In the next picture, you can see an example of Firebug in action, debugging JavaScript with a breakpoint in the execution of the script.

Ubiquity

This is an add-on produced by Mozilla Labs and it can do a lot of fancy stuff. But for our purposes, we are going to use it for two simple things—fast search of PHP and WordPress documentation.

You will need to install Ubiquity from https://wiki.mozilla.org/Labs/Ubiquity and also install these two plugins:

The way these two Ubiquity commands work is that when you press Ctrl and Space in the browser (this opens Ubiquity window) and then type php search_phrase or wp search_phrase, it takes you immediately to the PHP or WordPress documentation for the given phrase.

The amount of time this can save is huge, especially if you need to take a peek at the documentation every minute or so like I do (I can't keep everything in my head!).

Screengrab

You can grab Screengrab from http://www.screengrab.org, and this plugin allows you to take screenshots from your browser window easily. It can capture an entire page, a visible portion, or a user selection on the page.

Once you get used it, you will use it extensively for creating images for your plugin documentation. I have used it for almost all the images in this book.

IE tab

This Firefox add-on allows you to quickly change the rendering engine between Firefox and the installed version of the Internet Explorer. It allows you to quickly check if your plugin behaves well in this browser.

You can get it from http://ietab.mozdev.org/.