O'Reilly logo

Building Web Apps with WordPress by Jason Coleman, Brian Messenlehner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preface

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 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 security and localization (which we cover in Chapter 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 http://schoolpress.me, with any open sourced code for that site available at https://github.com/bwawwp/schoolpress.

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

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 a CD-ROM of 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 do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Building Web Apps with WordPress by Brian Messenlehner and Jason Coleman (O’Reilly). Copyright 2014 Brian Messenlehner and Jason Coleman, 978-1-449-36407-6.”

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

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

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 http://oreil.ly/building-apps-wp.

To comment or ask technical questions about this book, send email to .

For more information about our book and online examples see our website at http://bwawwp.com.

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

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

Follow us on Instagram: http://instagram.com/bwawwp

Acknowledgments

Thanks to Jason Coleman and Matt Mullenweg; I could not have written this book without them. I would like to thank Meghan Blanchette and Allyson MacDonald for staying on top of things at O’Reilly Media, and thanks to our technical reviewers. I am thankful of my wife and best friend, Robin Messenlehner, and my children Dalya, Brian Jr., and Nina Messenlehner, for supporting me and my efforts to write this book. I would also like to acknowledge my business partners and friends Brad Williams, Lisa Sabin-Wilson, and the entire WebDevStudios.com team for building the best WordPress development and design shop on earth! And last but not least, I love you, Mom!

— Brian Messenlehner

Thanks to my coauthor Brian for asking me to write this book with him. Thanks to our editors Meghan and Allyson for keeping us on track and helping us to stay true to our original vision. Thanks to our great technical editors Peter MacIntyre and Pippin Williamson for reviewing our code and writing and providing valuable feedback. Thanks to Frederick Townes for his feedback and contributions to our chapter on optimization and scaling. 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.

— Jason Coleman

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required