Preface

As we write this, WordPress powers 32% of all sites on 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, Symfony, Yii, or Laravel to build “real” web apps. This sentiment is wrong, and we’re here to fix it.

Despite starting out as blogging software 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 Chapter 9 and any 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 you 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 rather 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, Building Web Apps with WordPress

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, WordPress Basics

Covers the basics of WordPress. We go over the various directories of the core WordPress installation 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 if you are an experienced WordPress developer, you can learn something from this chapter, and we encourage you to read it.

Chapter 3, Using WordPress Plugins

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, Themes

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, Custom Post Types, Post Metadata, and Taxonomies

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, Users, Roles, and Capabilities

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, Working with WordPress APIs, Objects, and Helper Functions

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, Secure WordPress

Is all about securing your WordPress apps, plugins, and themes.

Chapter 9, JavaScript Frameworks and Workflow

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, WordPress REST API

Covers the REST API for WordPress and how to use it to integrate WordPress with outside apps.

Chapter 11, Project Gutenberg, Blocks, and Custom Block Types

Covers the block editor and how to make your own blocks.

Chapter 12, WordPress Multisite Networks

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

Chapter 13, Localizing WordPress Apps

Covers localizing your WordPress plugins and themes, including how to prepare your code for translation and how to create and use translation files.

Chapter 14, WordPress Optimization and Scaling

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.

Chapter 15, Ecommerce

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 you can use WordPress to handle payments and account management for software as a service (SaaS) web apps.

Chapter 16, Mobile Apps Powered by WordPress

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

Chapter 17, PHP Libraries, Web Service Integrations, and Platform Migrations

Covers some third-party PHP libraries, services, and APIs that are often used in web apps as well as how to integrate them with WordPress, including full migrations.

Chapter 18, The Future

Discusses the future of WordPress, what kinds of apps we expect to see running on WordPress, what kinds of updates we see coming for WordPress, and which tools and frameworks to keep an eye on for the future.

About the Code

You can find all examples in this book at https://github.com/bwawwp. 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 coding standards, security, and localization (which we cover in Chapters 8 and 13) or ignored certain edge cases. You will want to keep this in mind before using any examples in production code.

You can find the sample app SchoolPress at https://schoolpress.me, with any open sourced code for that site available at this book’s GitHub site.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

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.

Note

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

Warning

This element indicates a warning or caution.

Using Code Examples

As mentioned in “About the Code”, you can find all code examples in this book at https://github.com/bwawwp.

If you have a technical question or a problem using the code examples, please send email to .

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Building Web Apps with WordPress, Second Edition, by Brian Messenlehner and Jason Coleman (O’Reilly). Copyright 2020 Brian Messenlehner and Jason Coleman, 978-1-491-99008-7.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

O’Reilly Online Learning

Note

For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed.

Our unique network of experts and innovators share their knowledge and expertise through books, articles, conferences, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, please visit http://oreilly.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata and any additional information. You can access this page at https://oreil.ly/building-apps-wp2.

Email to comment or ask technical questions about this book.

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

From Brian: Thanks to Jason Coleman and Matt Mullenweg; I could not have written this book without them! A very special thanks to Alicia Young for staying on top of things at O’Reilly Media. A special thanks to our technical reviewers for making sure everything in the book is legit. Thanks to Scott Bolinger from AppPresser.com and Jaffe Worley from AlphaWeb.com for putting up with me. A shout out to family and friends who have always been there for me and never stopped believing in me. Most of all, I’m thankful for my children, Dalya; Brian, Jr.; Nina; Cam; and Aksel Messenlehner—they give me a purpose, and without them I probably wouldn’t even know what WordPress was.

From Jason: Thanks to my coauthor Brian for asking me to write this book with him. Thanks to our original editors Meghan and Allyson for keeping us on track and helping us to stay true to our original vision. Thanks to Alicia Young for editing the second edition of this book and sitting through our explanations of “WP Drama.” Thanks to all of the great technical editors we’ve had across both editions of the book: Sam Hotchkiss, Peter MacIntyre, Pippin Williamson, John James Jacoby, and Andrew Lima. Thanks to Frederick Townes for his feedback and contributions to our chapter on optimization and scaling. Thanks to Chris Lema for the wonderful forward to this book, his feedback on the book, and advice in general. Thanks to everyone in the WordPress community who answered all of my random tweets and may or may not have known they were helping me to write this book. Thanks to my wife, Kim, for supporting me as always during yet another adventure in our life. Thanks to my daughter, Marin, for missing me when I was away to write, and my son, Isaac, for constantly asking me if I had “finished the book yet.” Last but not least, thanks to my family, who have always supported my writing: Mom, Dad, Jeremy, and Nana Men are all excited to be the first nonprogrammers to read Building Web Apps with WordPress.

Get Building Web Apps with WordPress, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.