This article describes how to implement server-side protection using Composer (PHP package manager).
As a customer I would like to implement Queue-it KnownUser server-side protection on a WordPress site so that I can use Actions and triggers to protect specific pages of my site or my entire site.
- A functional WordPress installation
- SSH Access to be able to run commands on the server
- Composer is installed (if not find out more about Composer on the web)
- Access to the root folder of the Wordpress installation including permission to change the main index.php file (usually located at the root install folder of WP) and to create new files and/or subfolders with new files.
- Install the Queue-it SDK
- Create a “middleware” class
- Add the Queue-it SDK
- Note about getting the full request URI
- Optional steps
Install the Queue-it SDK using Composer
Summary of the steps described in the Queue-it documentation found here: PHP SDK
At the root folder of your WordPress install then run the composer command:
composer require queueit/knownuserv3
This will install the necessary Queue-it folders and dependencies to your WordPress install.
Create a “middleware” class
Middleware is a term used to describe an architecture pattern to implement logic/code that is run before or after a request is processed. In our case, we want to run the Queue-it protection before the request is processed to the WordPress application.
You can create this class according to your development standards, but this example describes creating a simple class that is in the root folder of the WordPress installation.
Let’s create a new class called qprotect.php
From the root folder of the WP install: touch qprotect.php
Inside this new file copy the code from the example in the README from the PHP SDK above
Note: You must add the integrationconfig.json that is downloaded from the GO platform as instructed into the root folder of your WordPress installation. If you choose another location to store this file, then be sure to include the correct location of the file and change the following line to reflect the correct location:
Now let’s add the Queueit SDK to the new middleware.
Adding the Queue-it SDK
Include the Queue-it SDK to the new middleware class (qprotect.php).
To do this simply require the composer vendor autoload:
Remove/Comment out the require_once for Models and KnownUser:
Include the new middleware class at the top of the main index.php of WordPress found at the root:
A note about retrieving the Request URI
The getFullRequestUri() function is provided as an example in the README. You can use your own function to retrieve the URI or you can copy this code into the middleware class (qprotect.php) or create it in a new file.
Alias the namespace for the KnownUser and QueueItHelpers methods so that you can call them without the full path. This is not necessary to change and only included here as additional information.
Below the require of the vendor/autoload.php include the following lines:
Now you can change calls to methods in these classes without the full QueueIT\KnownUserV3\SDK path like this: