Skip to content

CoreConfig Setup Guide

Michel edited this page Nov 4, 2024 · 1 revision

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.

Core Components

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.

Setting Up CoreConfig.php

To configure CoreConfig.php, follow these steps:

1. Setting API URL and Secret Key

  1. Open CoreConfig.php in your project.

  2. 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';

  3. 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.

Tip: Ensure that API_URL uses https:// to secure all communications.

2. Utility Methods in CoreConfig.php

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.
  • 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.

Next Steps

Once CoreConfig.php is set up, refer to individual action guides to use each feature: