Integrate Licfy Into Your Own Plugin or Theme

Licfy is a license management platform: you sign up, register your own plugin or theme as a product, and sell license keys to your customers. This guide shows you exactly how to add license protection to your product's code using the Licfy REST API — no need to build your own licensing system from scratch.

How it fits together: Your Licfy account → your Product (your plugin/theme) → a Package (defines validity & max activations) → a License (issued to one of your Clients). Your product's code then calls the Licfy /verify endpoint to confirm a customer's license key is valid before unlocking premium features or updates.

1. Register Your Product

After creating your account, Go to Licfy → Products and add your plugin or theme. Give it a unique product slug (for example my-awesome-plugin) — you will use this exact slug in your verification requests, so make sure it matches the one you hard-code into your product.

2. Get Your API Token

After registering your product, go to Licfy → API Token in your WordPress admin and generate a token. This token identifies you (the seller) when your product calls the verification API — it is not the same as a customer's license key, and it should never be shown to your customers.

Keep it secret: store the API token as a constant in your plugin's code or in a private config file. Never expose it in JavaScript or client-side requests.

3. Issue Licenses to Customers

Create a Package under Licfy → Packages to define how many domains a license can be activated on and how many days it stays valid. Then, every time someone buys your product, create a License under Licfy → Licenses for that client — Licfy generates a unique license key you deliver to your customer (for example inside their purchase receipt email).

4. Add a License Field to Your Product

Inside your own plugin or theme, add a simple settings field where your customer pastes the license key you sent them:

<form method="post">
    <input type="text" name="my_plugin_license_key" placeholder="Enter your license key" />
    <button type="submit">Activate License</button>
</form>

When this form is submitted, your plugin sends the key to Licfy for verification (next step).

5. Verify Licenses From Your Code

Call the /verify endpoint from your product's PHP code using wp_remote_post(). Send your API token (from step 1) as a Bearer header, and the customer's license key plus your product slug in the body:

function my_plugin_verify_license( $license_key ) {
    $response = wp_remote_post( 'https://licfy.com/api/licfy/v1/verify', array(
        'timeout' => 15,
        'headers' => array(
            'Authorization' => 'Bearer YOUR_LICFY_API_TOKEN', // from Licfy → API Token
            'Content-Type'  => 'application/json',
        ),
        'body' => wp_json_encode( array(
            'email'        => get_option( 'admin_email' ),
            'license_key'  => $license_key,
            'product_slug' => 'my-awesome-plugin',   // must match your Licfy product slug
            'website_name' => get_bloginfo( 'name' ),
            'website_url'  => home_url(),
        ) ),
    ) );

    if ( is_wp_error( $response ) ) {
        return array( 'status' => 'error', 'message' => $response->get_error_message() );
    }

    return json_decode( wp_remote_retrieve_body( $response ), true );
}

A successful response looks like this:

{
    "status": "200",
    "license_status": "valid",
    "message": "License verified",
    "package_name": "Pro Yearly",
    "license_key": "506067C1-F855664F-3C9121CA-4B9D7026",
    "domains": ["https://example.com"],
    "expired_date": "2027-01-01 00:00:00",
    "left_days": 365
}

6. Cache the Result & Gate Your Features

Don't call the API on every page load. Cache the result with a transient and re-check periodically (for example once a day):

function my_plugin_is_licensed() {
    $cached = get_transient( 'my_plugin_license_status' );
    if ( false !== $cached ) {
        return 'valid' === $cached;
    }

    $license_key = get_option( 'my_plugin_license_key' );
    if ( ! $license_key ) {
        return false;
    }

    $result = my_plugin_verify_license( $license_key );
    $status = ( ! empty( $result['license_status'] ) && 'valid' === $result['license_status'] ) ? 'valid' : 'invalid';

    set_transient( 'my_plugin_license_status', $status, DAY_IN_SECONDS );

    return 'valid' === $status;
}

// Anywhere in your plugin:
if ( my_plugin_is_licensed() ) {
    // unlock premium features / updates
}

Full Integration Example

A complete, drop-in class you can adapt for your own plugin:

class My_Plugin_Licfy_Client {

    const API_URL      = 'https://licfy.com/api/licfy/v1/verify';
    const API_TOKEN     = 'YOUR_LICFY_API_TOKEN';
    const PRODUCT_SLUG  = 'my-awesome-plugin';

    public static function verify( $license_key ) {
        $response = wp_remote_post( self::API_URL, array(
            'timeout' => 15,
            'headers' => array(
                'Authorization' => 'Bearer ' . self::API_TOKEN,
                'Content-Type'  => 'application/json',
            ),
            'body' => wp_json_encode( array(
                'email'        => get_option( 'admin_email' ),
                'license_key'  => $license_key,
                'product_slug' => self::PRODUCT_SLUG,
                'website_name' => get_bloginfo( 'name' ),
                'website_url'  => home_url(),
            ) ),
        ) );

        if ( is_wp_error( $response ) ) {
            return array( 'status' => 'error', 'message' => $response->get_error_message() );
        }

        return json_decode( wp_remote_retrieve_body( $response ), true );
    }

    public static function is_active() {
        $cached = get_transient( 'my_plugin_license_status' );
        if ( false !== $cached ) {
            return 'valid' === $cached;
        }

        $license_key = get_option( 'my_plugin_license_key' );
        if ( ! $license_key ) {
            return false;
        }

        $result = self::verify( $license_key );
        $status = ( ! empty( $result['license_status'] ) && 'valid' === $result['license_status'] ) ? 'valid' : 'invalid';
        set_transient( 'my_plugin_license_status', $status, DAY_IN_SECONDS );

        return 'valid' === $status;
    }
}

REST API Reference

All endpoints are namespaced under https://licfy.com/api/licfy/v1.

Verify & Activate a License

MethodEndpointAuthDescription
POST /verify Your API token Verify a customer's license key for a product and domain.

Request Body

FieldDescription
emailCustomer or site admin email.
license_keyThe license key entered by the customer.
product_slugThe slug of your product in Licfy.
website_nameName of the site activating the license.
website_urlURL of the site activating the license.

Common Responses

StatusMessageMeaning
200License verifiedLicense is valid and activated for this domain.
404License has expiredThe package validity period has passed.
404Domains limit exceededThe license already reached its max domain activations.
404Not foundNo license matches this key and product slug.

Frequently Asked Questions

Do I need to store the API token in every product I sell?

Yes. Embed your Licfy API token in each product you protect — it identifies your seller account when verifying any of your products' licenses.

What happens when a customer's license expires?

The /verify call returns a non-valid status once the package's validity period has passed. Your plugin should stop unlocking premium features until the customer renews.

Can I limit how many sites a license can activate?

Yes. Set the "Max Domains" value on the package used to generate the license.

How often should I re-check a license?

Once every 12–24 hours is enough. Cache the result (e.g. with a transient) and avoid calling the API on every page load.