MediaGrabber Pro

Framework Recipes

Copy-paste license validation for WordPress, Node.js/serverless, and Next.js.

The validation logic is the same everywhere; only the plumbing differs. Pick your platform below.

WordPress runs PHP, so call the Public API directly with wp_remote_post and cache the result in a transient.

function check_license( $license_key ) {
    $response = wp_remote_post( 'https://licenses.yourplugin.com/public/validate', [
        'headers' => [ 'Content-Type' => 'application/json' ],
        'body'    => json_encode([
            'licenseKey'  => $license_key,
            'fingerprint' => md5( get_site_url() ),
            'domain'      => parse_url( get_site_url(), PHP_URL_HOST ),
        ]),
        'timeout' => 5,
    ] );
 
    if ( is_wp_error( $response ) ) return false;
 
    $body = json_decode( wp_remote_retrieve_body( $response ), true );
    return $body['allowed'] ?? false;
}
 
function is_license_valid() {
    $cached = get_transient( 'my_plugin_license_valid' );
    if ( $cached !== false ) return $cached;
 
    $valid = check_license( get_option( 'my_plugin_license_key' ) );
    set_transient( 'my_plugin_license_valid', $valid, HOUR_IN_SECONDS );
    return $valid;
}

Cache aggressively (an hour or more). Validation tolerates brief staleness, and you don't want an API call on every page load.

General guidance

  • Always cache validation results; never block a hot path on a network call.
  • Fail open or closed deliberately. Decide what happens when the portal is unreachable — the SDK's offline cache helps you fail open safely.
  • One fingerprint per install. Reusing a fingerprint across installs makes them share an activation slot.

Next

On this page

Framework Recipes | MediaGrabber Pro