If you are holding this book in your hands now, you are probably aware—in one way or the other—of the tremendous success WordPress platform has seen over the past few years. It has become the most widespread blogging and publishing platform in the world today.
When I first installed WordPress, I was still looking around for a platform to start my personal site and also for an opportunity to do more online development work.
After seeing the simple installation procedure (which takes just a few minutes), I realized that the guys behind WordPress are on to something big. It has indeed proven to be so, and as the days passed by, I have enjoyed every aspect of WordPress—publishing, social, and development.
And I am thrilled to share these nits and bits of WordPress development information with you, showing you the power and flexibility that allowed WordPress to become so popular.
Thanks to its open source architecture, ease of use, and customization possibilities, WordPress has succeeded in differentiating itself from other weblog publishing platforms and even other open source solutions.
Its a huge community of users and developers
The millions of WordPress blogs
Major sites using it, including a number of US government agencies
Security issues treated almost instantly
Unmatched flexibility with thousands of available plugins
High level of customizability with thousands of available themes
Search engine friendly functionalities
Ease of use, maintenance, and upgrade
A great way to meet new people!
With such a list, it is no wonder that—every day—more and more private users and companies are turning to WordPress for their publishing needs. This of course presents a fertile ground for WordPress developers to show off their skills.
The opportunity for a WordPress developer in these circumstances becomes obvious.
With such a huge number of sites running it, the market is hungry for WordPress experts, and not just development experts. If you are proficient in the installation and setup of WordPress, you may easily have your hands full of work.
This also means that you can be fairly certain about the future of WordPress. Your investment in time and efforts, first in reading this book, and then in enhancing your development skills, is likely to pay off with WordPress.
This makes everyone even more comfortable and confident in using WordPress.
The opportunity is there for everyone—from beginners (developing useful plugins) to professionals (creating total WordPress makeovers such as e-commerce, marketing, or job portal sites—where you can hardly recognize that the site is running a WordPress installation).
Search Engine Optimization (SEO) is an important aspect of today's Internet presence. Just creating a site is not enough anymore, as there are now hundreds of millions of competing websites out there.
Using a platform such as WordPress will be really valuable, especially in the long term. WordPress has significant built-in SEO features and also most of the other aspects of modern SEO technologies available through custom plugins (and you can always write one to match your needs!)
After the five minute installation, most users immediately feel comfortable in the WordPress administration panels. Writing a post and organizing categories is as simple as it should be.
The whole WordPress installation consists of putting the files on the server and setting the assigned database, and it is very easy to back up or move it to another server.
WordPress and its plugins can be upgraded with a click of a button; all this makes the job of maintaining a WordPress website (or even several at the same time), a breeze.
If you are a WordPress developer, the chances are that you will have your own hosted WordPress blog. Having a personal blog creates a great opportunity to create many new contacts—both business and friends.
With such a huge user base, a well written plugin will probably be downloaded tens of thousands of times.
This will create awareness about you as a plugin author and your site as a probable source for some cool stuff. Having in mind how difficult it is to get noticed on the Internet today, this becomes a very important aspect of plugin development that you get for free.
Creating fresh, new, and usable plugins can help you go a long way. It has really helped me a lot in my field of work and has created a lot of opportunities one certainly being, the pleasure of writing this book.
You may sometimes wish to create a plugin just for yourself, to fulfil a specific need that can arise at a given moment. This is how I started writing plugins initially, as I needed certain functionalities that were not available in WordPress at the time.
The term dogfooding describes a dog food company that is ready to eat its own dog food. It means the company is confident about its own product and uses it for the purpose it was produced for.
In WordPress' terms, it means that you should always strive to create a plugin that satisfies your needs. On my personal site, I still use almost all of the plugins I created, and I only update them over time, as and when WordPress is updated, or my needs change.
This has a positive side effect of ensuring that your plugins will probably be attractive to many other users as well. Assuming that you are critical about your own work, and your confidence in using your own plugins sends out a clear message on how good they are.
Developing WordPress plugins is not always an easy job. It brings a number of challenges that you will need to overcome.
This book will cover all the aspects of the API with practical examples, and the development of six concrete plugins (chapters 2-7). Through step-by-step guides to creating these plugins, you will discover how to use API in typical situations, from displaying output on the site in the beginning, to turning WordPress into a CMS at the end.
Each new chapter and each new plugin will introduce different features of WordPress, and how to put them to good use, thereby allowing you to gradually advance your knowledge.
As much as WordPress team takes care of the WordPress core, you need to take care of security in your plugins. Always remember that your plugin is given the ultimate authority on the user's site. This is a great feature that allowed WordPress to become popular; but with that it also carries a great deal of responsibility.
This book will show the methods and functions best suited to the given situations, and underline the security implications. There are not too many issues to worry about, so make sure you remember the implications and best practices and apply them to your plugins.
Once the development work is done and the plugin is finished, a lot of authors face the question: What now? If you plan to release the plugin to the public, there are a few extra steps you need to take care of.
This book will give you practical tips in this area—refer to Chapter 8.
It will cover the process that takes you from the end of the development phase to the first users coming back to you with feedback and questions. I have learned much from my own plugin development experience, and I will also be referencing some of the resources available online .
At the moment, WordPress is translated into more than 50 languages worldwide. The number of users using WordPress in their native language is growing each day, and they usually prefer using plugins that support their own language.
Localization in WordPress is easy, and the best thing is that you will not have to do any translation. There will always be users interested in translating your plugin to their own language and sending you the file back. This is the way it works, and it is mutually beneficial.
I will also cover the necessary steps to manage your plugin using SVN (Subversion), and submit it to the WordPress Plugin Repository—the central repository of all WordPress plugins which currently hosts thousands of plugins and has served millions of downloads.
You can expect hundreds of user questions pouring in after you release a plugin. So, making sure that you have a well written documentation will save you a lot of time in answering those questions.
I will also give some practical tips on how to organize your plugin page.
I will give you tips on how to promote your plugin once it is published. If you have created a really useful plugin, you can expect a snowball effect when users start to write about it on their blogs and tell their friends about it.
This introduction chapter is followed by seven chapters; six of which describe the creation of WordPress plugins and a final chapter dealing with post-development issues:
The purpose of this plugin will also be to introduce you to the basic concepts of WordPress plugin development.
We will access some of the basic WordPress API functions, and talk about filters and actions which are the WordPress mechanisms for controlling the workflow of the site.
The second plugin comes from the idea of making the default blogroll look a little bit more exciting.
jQuery and Ajax technologies help our plugins become more engaging, and we will learn the basic concepts of using them through a series of practical examples.
This chapter is all about WP Wall; a plugin that creates a shoutbox on your blog's sidebar, where users can leave comments and shouts.
I will also try to engage you to think about WordPress plugin development in a slightly different way.
If plugins can be classified by beauty, this would be the most beautiful plugin in the book. It will display your blog archives in a way you probably have not seen before.
During the creation of the plugin, we will explore how to interact with posts, create plugin options, and manage them through a settings page in the administration. We will then use all that knowledge to produce a beautiful representation of your blog's archives.
Insights plugin will add to the productivity of the blog owner by offering quick access to common information in the Write Post screen.
In this chapter, we will learn how to change the WordPress Write Post screen and interact with the built-in TinyMCE editor. We will use Ajax to get information delivered directly into our post while we write it!
The final plugin of the book will see us working more closely with the WordPress backend, and explore ways to transform WordPress into a versatile Content Management System (CMS).
We will learn how to customize the administration menus and pages, use custom fields to store additional information, explore user capabilities system, and use localization.
After all the hard work in developing those plugins, comes a chapter dedicated to all the post-development work (after-hour party!).
The purpose of this chapter will be to explain localization, documentation, code management, and plugin promotion. It will also give you some information regarding WordPress MU development. Wordpress MU is a multi user version of WordPress that is becoming more popular each day.
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!
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.
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.
For this matter, I've been using Total Commander as a proven tool. Again, you might have your own preference.
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.
The most important Firefox add-on we want to install is called Firebug (you can download it from http://getfirebug.com).
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.
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.
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/.
PHP Search for Ubiquity:http://npattison.com/ubiquity/ubiq_php.html
WP Codex Search for Ubiquity:http://www.prelovac.com/vladimir/ubiquity-plugins/wp-codex-search
Before we start with development, let's have a quick reminder on how to install and manage WordPress plugins. Also I'll mention a handy tip for quickly accessing code examples.
Upload the plugin folder (for example
wp-wall)to your server's
Go to your WordPress administration section, and select Plugins from the menu. This will give you a list of all the installed plugins. Scroll down the list until you find yours, and click Activate.
If you intend to manually update the plugin files on a live site, it is advisable to deactivate the plugin first using the Plugins menu.
Strictly speaking, on a development blog where you are the only user, this can be skipped to save time.
If you need more information regarding plugin management, you can refer to the latest WordPress manual found at http://codex.wordpress.org/Managing_Plugins.
Luckily, you will have this book on your hand either in paper or in a PDF form, so you can take a quick look. Then, you also have the WordPress online documentation found at http://codex.wordpress.org/Main_Page.
Due to the rapid speed at which WordPress has been developing, not all the functions have been documented.
I also tend to keep a local copy of the entire plugin repository on my computer (you can find more details on how to do that in Chapter 8) so that I can search through the entire plugin repository and find instances of this function used by other plugin authors (and you can always find new and creative uses as well).
We learned about the advantages of WordPress development, and what WordPress has to offer to plugin authors. We have also seen that there are certain challenges along the way, which we will address in this book.
The six plugins that we will create in the following chapters will show you exactly how to create a WordPress plugin from scratch and have it perform the concrete functionality you need, whether it's on the front page or in the administration backend.
Having armed ourselves with useful development tools, we are ready to start developing some cool WordPress plugins!