WHO THIS BOOK IS FOR
This book is for professional web developers who want to make WordPress work exactly how they and their clients want. WordPress has already proven an exceptional platform for building any type of site from simple static pages to networks of full‐featured communities. Learning how to code plugins will help you get the most out of WordPress and have a cost‐effective approach to developing per‐client features.
This book is also for the code freelancers who want to broaden their skill portfolio, understand the inner workings of WordPress functionality, and take on WordPress gigs. Since WordPress is the most popular software to code and power websites, it is crucial that you understand how things run under the hood and how you can make the engine work your way. Learning how to code plugins will be a priceless asset to add to your résumé and business card.
Finally, this book is for hobbyist PHP programmers who want to tinker with how their WordPress blog works, discover the infinite potential of lean and flexible source code, and learn how they can interact with the flow of events. The beauty of open source is that it's easy to learn from and easy to give back in turn. This book will help you take your first step into a community that will welcome your creativity and contribution.
Simply put, this book is for anyone who wants to extend the way WordPress works, whether it is for fun or profit.
WHAT YOU NEED TO USE THIS BOOK
This book assumes you already have a web server and WordPress running. For your convenience, it is preferred that your web server runs on your localhost, as it will be easier to modify plugin files as you read through the book, but an online server is also fine.
Code snippets written in PHP are the backbone of this book. You should be comfortable with reading and writing basic PHP code or referring to PHP's documentation to fill any gaps in knowledge about fundamental functions. Advanced PHP code tricks are explained, so you don't need to be a PHP expert.
You will need to have rudimentary HTML knowledge to fully understand all the code. A basic acquaintance with database and MySQL syntax will help with grasping advanced subjects. To make the most of the chapter dedicated to JavaScript and Ajax, comprehension of JavaScript code will be a plus.
WHAT THIS BOOK COVERS
As of this writing, WordPress 5.5 is around the corner, and this book has been developed alongside this version. Following the best coding practices outlined in this book and using built‐in APIs are keys to future‐proof code that will not be deprecated when a newer version of WordPress is released. We believe that every code snippet in this book will still be accurate and up‐to‐date for several years, just as several plugins we coded many years ago are still completely functional today.
HOW THIS BOOK IS STRUCTURED
This book is, to date, one of the most powerful and comprehensive resources you can find about WordPress plugins. Advanced areas of the many WordPress APIs are covered, such as the REST API, cron jobs, and custom post types. This book is divided into three major parts. Reading the first five chapters is required if you are taking your first steps in the wonders of WordPress plugins. Chapters 6 through 9 will cover most common topics in coding plugins, and understanding them will be useful when reading subsequent chapters. The remaining chapters cover advanced APIs and functions, can be read in any order, and will sometimes refer to other chapters for details on a particular function.
CONVENTIONS
To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.
WARNING Boxes with a warning label like this one hold important, not‐to‐be‐forgotten information that is directly relevant to the surrounding text.
NOTE The note label indicates notes, tips, hints, tricks, and asides to the current discussion.
As for styles in the text:
We italicize new terms and important words when we introduce them.
We show keyboard strokes like this: Ctrl+A.
We show filenames, URLs, and code within the text like so: persistence.properties.
We present code in two different ways:
We use a monofont type with no highlighting for most code examples. We use bold to emphasize code that is particularly important in the present context or to show changes from a previous code snippet.
SOURCE CODE
As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wiley.com/go/prowordpressdev2e
on the Downloads tab.
NOTE Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978‐1‐119‐66694‐3.
ERRATA
We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or faulty piece of code, we would be grateful for your feedback. By sending in errata, you may save another reader hours of frustration, and at the same time, you will be helping us provide even higher‐quality information.
To find the errata page for this book, go to www.wiley.com
and locate the title using the Search box. Then, on the book details page, click the Errata link. On this page, you can view all errata that have been submitted for this book and posted by editors. If you don't spot “your” error on the Errata page, go to support.wiley.com
and follow the directions to contact technical support and open a ticket to submit the error. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent printings of the book.
1 An Introduction to Plugins
WHAT'S IN THIS CHAPTER?
Understanding what a plugin is
Using available WordPress APIs
Finding examples of popular plugins
Separating plugin and theme functionality
Managing and installing plugins
Understanding types of WordPress plugins
WordPress is the most popular open source content management system available today. One of the primary reasons WordPress is so popular is the ease with which you can customize and extend WordPress through plugins. WordPress has an amazing framework in place that gives plugin developers the tools needed to extend WordPress in any way imaginable.
Understanding how plugins work, and the tools available in WordPress, is critical knowledge when developing professional WordPress plugins.
WHAT IS A PLUGIN?
A plugin in WordPress is a PHP‐based script that extends or alters the core functionality of WordPress. Quite simply, plugins are files installed in WordPress to add a feature, or