WordPress Plugin Integration

Add license validation to your WordPress plugin in just a few lines of code.

How It Works

Your customers buy your plugin on your website (using Stripe), and KeyKit automatically creates a license key. Your plugin checks this key to verify the customer has a valid license.

Basic Integration

1. Add License Check Function

function check_license($license_key, $site_url) {
    $response = wp_remote_post('https://keykit.app/api/validate', [
        'headers' => [
            'Content-Type' => 'application/json',
            'x-org-id' => 'your-org-id',
            'x-keykit-signature' => 'your-signature'
        ],
        'body' => json_encode([
            'token' => $license_key,
            'siteId' => $site_url
        ])
    ]);
    
    if (is_wp_error($response)) {
        return false;
    }
    
    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);
    
    return $data['valid'] ?? false;
}

2. Use in Your Plugin

// Check license when plugin loads
add_action('init', function() {
    $license_key = get_option('my_plugin_license_key');
    $site_url = home_url();
    
    if (!check_license($license_key, $site_url)) {
        // Show license error or disable features
        add_action('admin_notices', function() {
            echo '<div class="notice notice-error"><p>Invalid license key. Please check your license.</p></div>';
        });
    }
});

3. Add License Input Field

// Add license field to settings page
add_action('admin_menu', function() {
    add_options_page(
        'Plugin License',
        'Plugin License',
        'manage_options',
        'plugin-license',
        function() {
            if (isset($_POST['license_key'])) {
                update_option('my_plugin_license_key', sanitize_text_field($_POST['license_key']));
                echo '<div class="notice notice-success"><p>License key saved!</p></div>';
            }
            
            $current_key = get_option('my_plugin_license_key', '');
            echo '<form method="post">';
            echo '<table class="form-table">';
            echo '<tr><th>License Key</th><td><input type="text" name="license_key" value="' . esc_attr($current_key) . '" class="regular-text" /></td></tr>';
            echo '</table>';
            echo '<input type="submit" class="button-primary" value="Save License" />';
            echo '</form>';
        }
    );
});

That's It!

Your WordPress plugin now validates licenses automatically. When customers buy your plugin, they'll get a license key that your plugin can verify.

Need Help?

If you need assistance with WordPress integration, check our documentation or contact support.