How can we help?

Use license keys in your WordPress plugin

Mindspun Payments can generate license keys using a licensing server. For setup, see the Generate license keys how-to.

After that, you have to decide how you want to enforce having a license key.

At a minimum, you need to:

  • Check the license key when the user installs the plugin.
  • Check the license key when the plugin checks for available updates.

If the license key is invalid, then you should fail the action.

If the license key is subscription-based and not a lifetime license, you may want to periodically validate it and take additional steps if it isn’t valid. Exactly what happens if the license key expires depends upon you. Possible examples are showing an error for shortcodes or no longer register blocks. Make sure you don’t do anything destructive! You want users to update their license key and continue using your plugin.

Check the license key on installation

The license key is usually stored in a WordPress option. You can validate it using code like:

$params = array(
    'slm_action' => 'slm_check',
    'secret_key' => VERIFY_SECRET_KEY,
    'license_key' => $license_key,
);
$url = add_query_arg( $params, $this->url );

$response = wp_remote_get($url,varray('timeout' => 20));
if ( is_wp_error( $response ) ) {
    // Network error.
    return $response;
}

$license_data = json_decode( wp_remote_retrieve_body( $response ), true );
if ( 'success' !== ( $license_data['result'] ?? null ) ) {
     // Invalid/expired license.
     $error = $license_data['message'] ?? 'Unknown error';
     return new WP_Error( 'license_invalid_result', $error );
}

// License is valid and $license_data has additional information.

For complete details see the GitHub page for the software licensing server plugin. The Postman demos are also particularly helpful.

Checking for a valid license is the minimum implementation. You’ll likely also want to register the domain and or the device. If you have multiple products or will someday, also validate that the license is for the correct product.