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.
File Written
Section titled “File Written”src/functions.php
Design
Section titled “Design”All 30 functions follow the same pattern:
function_exists()guard so the file can be included multiple times safely.- Retrieve the relevant service from the container via
Plugin::get_instance()->container()->make(...). - Delegate to the service method.
- 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 ); }}Function Reference
Section titled “Function Reference”License functions
Section titled “License functions”| Function | Returns | Delegates to |
|---|---|---|
wplm_get_license(int $id) | License|null | LicenseRepository::find() |
wplm_get_license_by_key(string $key) | License|null | LicenseRepository::find_by_hash() |
wplm_validate(string $token, array $ctx) | array | LicenseService::validate() |
wplm_create_license(array $attrs) | License|WP_Error | LicenseService::create() |
wplm_revoke_license(int $id) | bool|WP_Error | RevocationService::revoke() |
wplm_suspend_license(int $id) | bool|WP_Error | RevocationService::suspend() |
wplm_terminate_license(int $id) | bool|WP_Error | RevocationService::terminate() |
Activation functions
Section titled “Activation functions”| Function | Returns | Delegates to |
|---|---|---|
wplm_activate(string $token, array $device) | array|WP_Error | ActivationService::activate() |
wplm_deactivate(int $machine_id) | bool | ActivationService::deactivate() |
wplm_heartbeat(int $machine_id) | bool | HeartbeatService::renew_lease() |
Meta functions
Section titled “Meta functions”All meta functions use $wpdb->prepare() directly against wp_wplm_license_meta:
| Function | Notes |
|---|---|
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 |
Subscription functions
Section titled “Subscription functions”| Function | Returns |
|---|---|
wplm_get_subscription(int $id) | Subscription|null |
wplm_get_user_subscriptions(int $user_id) | Subscription[] |
wplm_get_user_licenses(int $user_id) | License[] |
Utility functions
Section titled “Utility functions”| Function | Notes |
|---|---|
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 |
Loaded from Plugin.php
Section titled “Loaded from Plugin.php”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.