Skip to content

Phase 13: Global Helper Functions

Provide a simple, procedural API that theme and plugin developers can call without knowing about the DI container or service class hierarchy.

  • src/functions.php

All 30 functions follow the same pattern:

  1. function_exists() guard so the file can be included multiple times safely.
  2. Retrieve the relevant service from the container via Plugin::get_instance()->container()->make(...).
  3. Delegate to the service method.
  4. Return the service’s return value directly.
if ( ! function_exists( 'wplm_validate' ) ) {
function wplm_validate( string $token, array $context = [] ): array {
return \WPLM\Plugin::get_instance()
->container()
->make( \WPLM\Services\LicenseService::class )
->validate( $token, $context );
}
}
FunctionReturnsDelegates to
wplm_get_license(int $id)License|nullLicenseRepository::find()
wplm_get_license_by_key(string $key)License|nullLicenseRepository::find_by_hash()
wplm_validate(string $token, array $ctx)arrayLicenseService::validate()
wplm_create_license(array $attrs)License|WP_ErrorLicenseService::create()
wplm_revoke_license(int $id)bool|WP_ErrorRevocationService::revoke()
wplm_suspend_license(int $id)bool|WP_ErrorRevocationService::suspend()
wplm_terminate_license(int $id)bool|WP_ErrorRevocationService::terminate()
FunctionReturnsDelegates to
wplm_activate(string $token, array $device)array|WP_ErrorActivationService::activate()
wplm_deactivate(int $machine_id)boolActivationService::deactivate()
wplm_heartbeat(int $machine_id)boolHeartbeatService::renew_lease()

All meta functions use $wpdb->prepare() directly against wp_wplm_license_meta:

FunctionNotes
wplm_get_license_meta(int $id, string $key)Returns single meta value
wplm_update_license_meta(int $id, string $key, $value)Upsert
wplm_delete_license_meta(int $id, string $key)Delete single key
wplm_get_all_license_meta(int $id)Returns associative array
FunctionReturns
wplm_get_subscription(int $id)Subscription|null
wplm_get_user_subscriptions(int $user_id)Subscription[]
wplm_get_user_licenses(int $user_id)License[]
FunctionNotes
wplm_generate_key(int $generator_id)Single key string
wplm_get_crl()Signed CRL array
wplm_log_audit(string $action, array $ctx)Write audit log

src/functions.php is included at the top of Plugin::boot():

require_once WPLM_PLUGIN_DIR . 'src/functions.php';

This ensures functions are available on all WordPress requests where the plugin is active, not just REST API requests.