Preface - Building Web Apps with WordPress (2014)

Building Web Apps with WordPress (2014)


As we write this, WordPress powers 20% of the Internet, and that number is growing. Many developers want to do more with their WordPress sites but feel that they need to jump ship to a more traditional application framework like Ruby on Rails, Yii, Zend, or Codeigniter to build “real” web apps. This sentiment is wrong, and we’re here to fix it.

Despite starting out as a blogging platform and currently existing primarily as a content management system, WordPress has grown into a flexible and capable platform for building web apps. This book will show you how to use WordPress as an application framework to build any web app, large or small.

Who This Book Is For

This book will be most useful for WordPress developers looking to work on heavier applications and PHP developers with some WordPress experience looking for a PHP-based application framework.

Commercial plugin and theme developers, or anyone working on large distributed WordPress projects, will also find the concepts and techniques of this book useful.

If you are a PHP or language-agnostic developer using another framework and jealous of the large library of WordPress plugins and themes, you may be surprised to learn how well WordPress can work as a general application framework. Reading and applying the lessons in this book could change your work life for the better.

We assume that readers have an intermediate understanding of general PHP programming. You should also have a basic understanding of HTML and CSS, and familiarity with MySQL and SQL queries. Basic understanding of JavaScript and jQuery programming will help with the JavaScript and AJAX chapter and related examples.

Who This Book Is Not For

This book is not for people who want to learn how to use WordPress as an end user. There will be brief introductions to standard WordPress functionality, but we assume that readers have already experienced WordPress from a user’s perspective.

This book is not meant for nonprogrammers. While it is possible to build very functional web applications by simply combining and configuring the many plugins available for WordPress, this book is written for developers building their own plugins and themes to power new web apps.

This book will not teach you how to program but will teach you how to program “the WordPress way.”

What You’ll Learn

Our hope with this book is that you will learn the programming and organizational techniques and best practices for developing complex applications using WordPress.

Chapter 1 defines what we mean by “web app” and also covers why or why not to use WordPress for building web apps and how to compare WordPress to other application frameworks. We also introduce SchoolPress, the WordPress app that we use as an example throughout the book.

Chapter 2 covers the basics of WordPress. We go over the various directories of the core WordPress install and what goes where. We also explain each database table created by WordPress, what data each holds, and which WordPress functions map to those tables. Even experienced WordPress developers can learn something from this chapter and are encouraged to read it.

Chapter 3 is all about plugins. What are they? How do you make your own plugins? How should you structure your app’s main plugin? When should you leverage third-party plugins or roll your own?

Chapter 4 is all about themes. How do themes works? How do themes map to views in a typical model-view-controller (MVC) framework? What code should go into your theme, and what code should go into plugins? We also cover using theme frameworks and UI frameworks and the basics of responsive design.

Chapter 5 covers custom post types and taxonomies. We go over the default post types built into WordPress, why you might need to build your own, and then how to go about doing that. We also cover post meta and taxonomies, what each is appropriate for, and how to build custom taxonomies and map them to your post types. Finally, we show how to build wrapper classes for your post types to organize your code utilizing object-oriented programming (OOP).

Chapter 6 covers users, roles, and capabilities. We show how to add, update, and delete users programmatically, and how to work with user meta, roles, and capabilities. We also show how to extend the WP_User class for your user archetypes like “customers” and “teachers” to better organize your code using OOP techniques.

Chapter 7 covers a few of the more useful WordPress APIs and helper functions that didn’t fit into the rest of the book but are still important for developers building web apps with WordPress.

Chapter 8 is all about securing your WordPress apps, plugins, and themes.

Chapter 9 covers using JavaScript and AJAX in your WordPress application. We go over the correct way to enqueue JavaScript into WordPress and how to build asynchronous behaviors in your app.

Chapter 10 covers the XML-RPC API for WordPress and how to use it to integrate WordPress with outside apps.

Chapter 11 covers how to use WordPress to power native apps on mobile devices by creating app wrappers for iOS and Android.

Chapter 12 covers some third-party PHP libraries, services, and APIs that are often used in web apps and how to integrate them with WordPress.

Chapter 13 covers WordPress multisite networks, including how to set them up and things to keep in mind when developing for multisite.

Chapter 14 covers localizing your WordPress plugins and themes, including how to prep your code for translation and how to create and use translation files.

Chapter 15 covers ecommerce. We go over the various types of ecommerce plugins available and how to choose between them. We then go into detail on how to use WordPress to handle payments and account management for software as a service (SaaS) web apps.

Chapter 16 covers how to optimize and scale WordPress for high-volume web apps. We go over how to test the performance of your WordPress app and the most popular techniques for speeding up and scaling sites running WordPress.

About the Code

All examples in this book can be found at Please note that these code examples were written to most clearly convey the concepts we cover in the book. To improve readability, we often ignored best practices for security and localization (which we cover inChapter 8 and Chapter 14 of this book) or ignored certain edge cases. You will want to keep this in mind before using any examples in production code.

The sample app SchoolPress can be found at, with any open sourced code for that site available at

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, datatypes, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.


This element signifies a tip, suggestion, or general note.


This element indicates a warning or caution.