Writing plugins using object-oriented PHP
So far, all plugin examples that have been covered in this chapter have been written using the procedural PHP programming style, with all the functions declared directly in the main body of the plugin and the hook registration functions having direct access to these functions.
WordPress can also be written using an object-oriented PHP approach. This recipe explains how to convert the code from the previous recipe into a class-based version of the same functionality.
Getting ready
You should have already followed the Loading a style sheet to format plugin output recipe to have a starting point for this recipe. Alternatively, you can download the resulting code (Chapter 2/ch2-private-item-text/ch2-private-item-text-v2.php
) for that recipe from the Packt Publishing website (https://www.packtpub.com/support).
How to do it...
- Log in to the administration page of your WordPress installation.
- Click on
Plugins
in the left-hand navigation menu. - Check whether the...