-
-
Notifications
You must be signed in to change notification settings - Fork 29
CoreConfig Setup Guide
The CoreConfig.php
file is the foundation of the SLM Plus license management integration, providing global configuration, constants, and utility methods for secure API interactions.
This file contains critical settings and methods for managing requests to the SLM Plus API. Key components include:
- API URL and Secret Key: Essential for secure API communication.
- Utility Methods: Functions for sanitizing input, processing responses, logging errors, and handling API requests.
To configure CoreConfig.php
, follow these steps:
-
Open
CoreConfig.php
in your project. -
Locate the constants for API URL and secret key at the top of the file:
const API_URL = 'https://yourwebsite.com'; const SECRET_KEY = 'YOUR_SECRET_KEY';
-
Update these values to match your configuration:
-
API URL: Replace
'https://yourwebsite.com'
with the full URL of your WordPress site where SLM Plus is installed. - Secret Key: Use the same secret key configured in the SLM Plus plugin for secure API requests.
-
API URL: Replace
Tip: Ensure that
API_URL
useshttps://
to secure all communications.
The following utility methods streamline and secure API operations:
-
getApiUrl($action): Constructs the full API endpoint URL by appending an action to the base URL.
-
processResponse($response): Validates and interprets the API response, handling success, error, and fallback cases.
- Success: Returns data from a successful response.
- Error: Logs any errors received from the API and returns an error message.
- Fallback: Provides a generic error message for unexpected response formats.
-
logError($message): Logs error messages to aid in troubleshooting.
-
Details: By default, this method uses PHP’s
error_log
function. You can replace it with other logging solutions if needed.
-
Details: By default, this method uses PHP’s
-
sanitizeFields($fields): Sanitizes input data to secure API requests.
- Example: Each field in the request is cleaned based on its type (e.g., email, integer, text) to prevent malicious content.
-
apiRequest($action, $data): Handles API requests by building the request and processing the response.
-
Parameters:
-
$action: Specifies the API action (e.g.,
slm_create_new
,slm_check
). - $data: An associative array of the data required for the request.
-
$action: Specifies the API action (e.g.,
-
Parameters:
Once CoreConfig.php
is set up, refer to individual action guides to use each feature:
Updated and maintained by Epikly