WordPress REST API Documentation

Integrate license validation and automatic updates into your WordPress plugins using our comprehensive REST API.

Overview

The InnovaPlugins REST API allows you to integrate license validation, activation, and automatic updates directly into your WordPress plugins. This ensures that only licensed users can access premium features while providing a seamless user experience.

License Validation

Verify license keys and check activation status

Secure Authentication

JWT-based authentication for API security

Easy Integration

Simple REST endpoints with comprehensive docs

Authentication

All API requests require authentication using a license key. Include the license key in the Authorization header as a Bearer token.

Authorization: Bearer YOUR_LICENSE_KEY

Base URL

https://api.innovaplugins.com/v1/

License Validation

Validate a license key and check if it's active for the current site. This should be called periodically to ensure the license is still valid.

Endpoint

POST /licenses/validate

Request Body

{
  "license_key": "INV-A1B2C3D4-E5F6G7H8-I9J0K1L2-M3N4O5P6",
  "site_url": "https://yoursite.com",
  "plugin_slug": "your-plugin-name"
}

Response

{
  "valid": true,
  "status": "active",
  "expires_at": "2025-01-15T00:00:00Z",
  "sites_used": 2,
  "sites_allowed": 5,
  "plan_name": "Professional"
}

PHP Example

<?php
// License validation example for WordPress plugins
class InnovaPlugins_License_Validator {
    private $api_url = 'https://api.innovaplugins.com/v1/';
    private $license_key;
    private $plugin_slug;
    
    public function __construct($license_key, $plugin_slug) {
        $this->license_key = $license_key;
        $this->plugin_slug = $plugin_slug;
    }
    
    public function validate_license() {
        $response = wp_remote_post($this->api_url . 'licenses/validate', array(
            'headers' => array(
                'Content-Type' => 'application/json',
                'Authorization' => 'Bearer ' . $this->license_key
            ),
            'body' => json_encode(array(
                'license_key' => $this->license_key,
                'site_url' => site_url(),
                'plugin_slug' => $this->plugin_slug
            ))
        ));
        
        if (is_wp_error($response)) {
            return array('valid' => false, 'error' => $response->get_error_message());
        }
        
        $body = wp_remote_retrieve_body($response);
        $data = json_decode($body, true);
        
        return $data;
    }
}

// Usage in your plugin
$validator = new InnovaPlugins_License_Validator(
    get_option('your_plugin_license_key'),
    'your-plugin-slug'
);

$validation_result = $validator->validate_license();

if ($validation_result['valid']) {
    // License is valid, enable premium features
    update_option('your_plugin_license_status', 'valid');
} else {
    // License is invalid, disable premium features
    update_option('your_plugin_license_status', 'invalid');
}

License Activation

Activate a license key for a specific site. This registers the site with the license and enables premium features.

Endpoint

POST /licenses/activate

PHP Example

<?php
// License activation example
function activate_innovaplugins_license($license_key) {
    $response = wp_remote_post('https://api.innovaplugins.com/v1/licenses/activate', array(
        'headers' => array(
            'Content-Type' => 'application/json'
        ),
        'body' => json_encode(array(
            'license_key' => $license_key,
            'site_url' => site_url(),
            'site_name' => get_bloginfo('name'),
            'plugin_version' => YOUR_PLUGIN_VERSION
        ))
    ));
    
    if (is_wp_error($response)) {
        return array(
            'success' => false,
            'message' => $response->get_error_message()
        );
    }
    
    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);
    
    if ($data['success']) {
        update_option('your_plugin_license_key', $license_key);
        update_option('your_plugin_license_status', 'active');
        return array(
            'success' => true,
            'message' => 'License activated successfully!'
        );
    } else {
        return array(
            'success' => false,
            'message' => $data['message'] ?? 'License activation failed'
        );
    }
}

Plugin Updates

Integrate with WordPress's built-in update system to provide automatic updates for your premium plugins.

Check for Updates

GET /plugins/{plugin_slug}/version

PHP Example

<?php
// Check for plugin updates using license validation
function check_for_plugin_updates() {
    $license_key = get_option('your_plugin_license_key');
    
    if (empty($license_key)) {
        return false;
    }
    
    $response = wp_remote_get('https://api.innovaplugins.com/v1/plugins/your-plugin-slug/version', array(
        'headers' => array(
            'Authorization' => 'Bearer ' . $license_key
        )
    ));
    
    if (is_wp_error($response)) {
        return false;
    }
    
    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);
    
    if ($data['success'] && version_compare($data['version'], YOUR_PLUGIN_VERSION, '>')) {
        return array(
            'new_version' => $data['version'],
            'download_url' => $data['download_url'],
            'changelog' => $data['changelog']
        );
    }
    
    return false;
}

// Hook into WordPress update system
add_filter('pre_set_site_transient_update_plugins', 'check_plugin_updates');

function check_plugin_updates($transient) {
    if (empty($transient->checked)) {
        return $transient;
    }
    
    $update_data = check_for_plugin_updates();
    
    if ($update_data) {
        $transient->response[plugin_basename(__FILE__)] = (object) array(
            'new_version' => $update_data['new_version'],
            'package' => $update_data['download_url'],
            'slug' => 'your-plugin-slug'
        );
    }
    
    return $transient;
}

Frontend Integration

You can also validate licenses on the frontend using JavaScript for real-time feature toggling.

JavaScript Example

// JavaScript/jQuery example for frontend license validation
function validateLicense(licenseKey) {
    return fetch('/wp-json/innovaplugins/v1/validate-license', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-WP-Nonce': wpApiSettings.nonce
        },
        body: JSON.stringify({
            license_key: licenseKey,
            site_url: window.location.origin
        })
    })
    .then(response => response.json())
    .then(data => {
        if (data.valid) {
            console.log('License is valid');
            // Enable premium features in frontend
            document.querySelectorAll('.premium-feature').forEach(el => {
                el.style.display = 'block';
            });
        } else {
            console.log('License is invalid:', data.message);
            // Show upgrade notice
            showUpgradeNotice();
        }
        return data;
    })
    .catch(error => {
        console.error('License validation error:', error);
    });
}

function showUpgradeNotice() {
    const notice = document.createElement('div');
    notice.className = 'notice notice-warning';
    notice.innerHTML = `
        <p>Your license is invalid or expired. 
        <a href="https://innovaplugins.com/pricing">Upgrade now</a> to access premium features.</p>
    `;
    document.querySelector('.wrap').prepend(notice);
}

Error Handling

The API uses standard HTTP status codes to indicate success or failure. Always check the response status and handle errors appropriately.

400 - Bad Request

Invalid request format or missing required fields

401 - Unauthorized

Invalid or missing license key

403 - Forbidden

License key valid but expired or suspended

429 - Rate Limited

Too many requests, please slow down

Best Practices

  • • Cache validation results to avoid excessive API calls
  • • Implement graceful degradation when API is unavailable
  • • Use WordPress transients for caching license status
  • • Validate licenses on plugin activation and periodically

Need Help?

Our team is here to help you integrate the license API into your WordPress plugins. Get in touch if you have questions or need assistance.