Building an object-oriented plugin

Up to this point, we created several plugins in previous chapters. However, we used the procedural approach, where we define the necessary hooks and functions directly inside the main plugin file or sub-files. As the website or application gets complex, we will have a hard time managing the development with the procedural method. So, we need a way to use best development practices and modularize the code into necessary classes. In this section, we are going to look at the basic structure for creating a plugin with object-oriented concepts. Let's consider the following code for the OOP-based plugin structure:

if( !class_exists( 'WPQuick_CPT' ) ) {     class WPQuick_CPT{       private static $instance; public static ...

Get WordPress Development Quick Start Guide 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.