Introduction to user management
Usually, other popular PHP development frameworks such as Zend, CakePHP, CodeIgniter, and Laravel don't provide built-in user modules. Developers tend to build their own user management modules and use them across many projects of the same framework. WordPress offers a built-in user management system to cater to common user management tasks in web applications. Such things include:
- Managing user roles and capabilities
- Built-in user registration
- Built-in user login
- Built-in forgot password
Developers are likely to encounter these tasks in almost all web applications. On most occasions, these features and functions can be effectively used without significant changes to the code. However, web applications are much more advanced, and hence we might need various customizations on these existing features. It's important to explore the possibility of extending these functions so that they are compatible with advanced application requirements. In the upcoming sections, we are going to learn how to extend these common functionalities to suit varying scenarios.
Preparing the plugin
As developers, we have the option of building a complete application with standalone plugins or using various independent plugins to cater for specific modules. Throughout this book, we will be developing several independent modules as specific plugins to make things simple. We are going to create a specific plugin for user-related functionalities of our application. So, let's get started by creating a new folder named wpwa_user_manager
inside the /wp-content/plugins
folder.
Then, create a PHP file inside the folder and save it as class-wpwa-user-manager.php
. Now it's time to add the plugin definition as shown in the following code:
<?php /* Plugin Name: WPWA User Manager Plugin URI: Description: User management module for the portfolio management application. Author: Rakhitha Nimesh Version: 1.0 Author URI: http://www.innovativephp.com/ */
In the previous chapter, we created a plugin with procedural functions calls. Now we are going to go one step further by building an object-oriented plugin. Basically, this plugin consists of one main class that handles the plugin initialization. The following code shows the implementation of the plugin class inside the wpwa-user-manager.php
file:
class WPWA_User_Manager { public function __construct() { // Initialization code } } $user_manege = new WPWA_User_Manager();
Once the class is defined, we can make an object to initialize the plugin within the same file. All the initialization code resides in the plugin constructor.