Documentation

License
in package
Uses UtilsProvider

Handle license information for a given plugin and associated blog id.

Table of Contents

Constants

ERROR_CODE_NOT_ACTIVATED  = 'rpm_wpc_not_activated'
INSTALLATION_TYPE_DEVELOPMENT  = 'development'
INSTALLATION_TYPE_NONE  = false
INSTALLATION_TYPE_PRODUCTION  = 'production'
OPTION_NAME_CODE_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-code_'
OPTION_NAME_HINT_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-hint_'
OPTION_NAME_HOST_NAME  = RPM_WP_CLIENT_OPT_PREFIX . '-hostname_'
OPTION_NAME_INSTALLATION_TYPE_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-installationType_'
OPTION_NAME_LICENSE_ACTIVATION_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-licenseActivation_'
OPTION_NAME_NO_USAGE_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-noUsage_'
OPTION_NAME_TELEMETRY_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-telemetry_'
OPTION_NAME_UUID_PREFIX  = RPM_WP_CLIENT_OPT_PREFIX . '-uuid_'
VALIDATE_NEW_HOSTNAME_SKIP  = ['http:', 'https:']
In some cases, the new host gets validated and RPM automatically deactivates the license of the users without any changes to the host. For some reason, the detected hostname is an invalid "URL" like `http:`.
VALIDATE_NEW_HOSTNAME_SKIP_BY_REGEXP  = '/^(?:\\w+-\\d+-\\d+-\\d+-\\d+\\.[^\\.]+\\.(?:[\\w-]+[-.])?amazonaws\\.com|.*temp\\.domains)$/m'
Skip the license deactivation for some exceptions. For example, AWS Lightsail does not automatically redirect the `ec2-192-18[...]` domain to the WordPress domain URL.

Properties

$activation  : LicenseActivation
License activation handler.
$blogId  : int
Blog id for this license.
$currentHostname  : string
Hostname at time of creation of this instance.
$initialized  : mixed
$pluginUpdate  : PluginUpdate
Plugin update handler.
$remoteStatus  : WP_Error|array<string|int, mixed>
Remote status of the activation.
$slug  : string
Plugin slug.
$telemetryData  : TelemetryData
License telemetry data handler.

Methods

__construct()  : mixed
C'tor.
__toString()  : mixed
Make it work with `array_unique`.
activateProgrammatically()  : mixed
Check if there is a programmatically configured license key and activate it if not already.
fetchRemoteStatus()  : mixed
Fetch remote status from the Real Product Manager server. Automatically validates with `#validateRemoteResponse`, too.
getActivation()  : mixed
Get license activation handler.
getAsArray()  : mixed
Get the license as array, useful for frontend needs or REST API.
getBlogId()  : mixed
Get blog id.
getBlogName()  : mixed
Get blog name for this license.
getClient()  : mixed
Get license client.
getCurrentHostname()  : mixed
Getter. See also `getKnownHostname`.
getInitiator()  : mixed
Get initiator.
getKnownHostname()  : string
Get known hostname. Can be empty if none given. The hostname will be set with the first license activation. The value itself is base64-encoded in database to avoid search & replace mechanism to replace the persisted URL.
getPluginConstantPrefix()  : string
Get the prefix of this package so we can utils package natively.
getPluginUpdate()  : mixed
Get plugin update handler.
getProgrammaticActivation()  : mixed
See filter `DevOwl/RealProductManager/License/Programmatic/$slug`.
getSlug()  : mixed
Get plugin slug.
getTelemetryData()  : mixed
Get license telemetry data handler.
getUuid()  : string
Get known UUID. Can be empty if none given. The UUID will be set with the first license activation.
initialize()  : mixed
Initalizes the license once.
isFulfilled()  : mixed
Check if this license needs to have a license key (no usage) and if yes, check if one is given.
isNoUsage()  : bool
Check if this license should not be used. It is mostly useful within Multisite when a non-free plugin should be only used on one sub site.
newVersionInstalled()  : mixed
A new version of the plugin got installed.
probablyMigrate()  : mixed
If given, read the old license key from the previous updater and give it back as hint.
probablySyncWithRemote()  : mixed
The same as `syncWithRemote`, but surely synced only once a day.
receivedRemoteLicenseActivation()  : mixed
We received the remote license activation data. Let's save this to our database so other plugins can act on them.
restore()  : mixed
Restore to previous blog.
setupConstants()  : mixed
Make sure the RPM_WP_CLIENT constants are available.
switch()  : mixed
Switch to this blog.
syncWithRemote()  : mixed
Sync our plugin version, PHP version and WordPress version with our remote system.
update_option_siteurl()  : mixed
If the `site_url` got updated through e.g. the UI, persist the host name as known so that `self::validateNewHost` does not automatically deactivate the license - its still the same WordPress installation.
validateNewHostName()  : mixed
Check if the plugin got migrated to another host and deactivate the license automatically.
validateRemoteResponse()  : mixed
Validate a remote response against their body and probably an error code.

Constants

ERROR_CODE_NOT_ACTIVATED

public mixed ERROR_CODE_NOT_ACTIVATED = 'rpm_wpc_not_activated'

INSTALLATION_TYPE_DEVELOPMENT

public mixed INSTALLATION_TYPE_DEVELOPMENT = 'development'

INSTALLATION_TYPE_NONE

public mixed INSTALLATION_TYPE_NONE = false

INSTALLATION_TYPE_PRODUCTION

public mixed INSTALLATION_TYPE_PRODUCTION = 'production'

OPTION_NAME_CODE_PREFIX

public mixed OPTION_NAME_CODE_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-code_'

OPTION_NAME_HINT_PREFIX

public mixed OPTION_NAME_HINT_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-hint_'

OPTION_NAME_HOST_NAME

public mixed OPTION_NAME_HOST_NAME = RPM_WP_CLIENT_OPT_PREFIX . '-hostname_'

OPTION_NAME_INSTALLATION_TYPE_PREFIX

public mixed OPTION_NAME_INSTALLATION_TYPE_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-installationType_'

OPTION_NAME_LICENSE_ACTIVATION_PREFIX

public mixed OPTION_NAME_LICENSE_ACTIVATION_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-licenseActivation_'

OPTION_NAME_NO_USAGE_PREFIX

public mixed OPTION_NAME_NO_USAGE_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-noUsage_'

OPTION_NAME_TELEMETRY_PREFIX

public mixed OPTION_NAME_TELEMETRY_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-telemetry_'

OPTION_NAME_UUID_PREFIX

public mixed OPTION_NAME_UUID_PREFIX = RPM_WP_CLIENT_OPT_PREFIX . '-uuid_'

VALIDATE_NEW_HOSTNAME_SKIP

In some cases, the new host gets validated and RPM automatically deactivates the license of the users without any changes to the host. For some reason, the detected hostname is an invalid "URL" like `http:`.

public mixed VALIDATE_NEW_HOSTNAME_SKIP = ['http:', 'https:']

VALIDATE_NEW_HOSTNAME_SKIP_BY_REGEXP

Skip the license deactivation for some exceptions. For example, AWS Lightsail does not automatically redirect the `ec2-192-18[...]` domain to the WordPress domain URL.

public mixed VALIDATE_NEW_HOSTNAME_SKIP_BY_REGEXP = '/^(?:\\w+-\\d+-\\d+-\\d+-\\d+\\.[^\\.]+\\.(?:[\\w-]+[-.])?amazonaws\\.com|.*temp\\.domains)$/m'
Tags
see
https://regex101.com/r/OxkZVE/2

Properties

$blogId

Blog id for this license.

private int $blogId

$currentHostname

Hostname at time of creation of this instance.

private string $currentHostname

$initialized

private mixed $initialized = false

$remoteStatus

Remote status of the activation.

private WP_Error|array<string|int, mixed> $remoteStatus

$slug

Plugin slug.

private string $slug

Methods

__construct()

C'tor.

public __construct(PluginUpdate $pluginUpdate, string $currentHostname, int $blogId) : mixed
Parameters
$pluginUpdate : PluginUpdate
$currentHostname : string
$blogId : int
Tags
codeCoverageIgnore

activateProgrammatically()

Check if there is a programmatically configured license key and activate it if not already.

public activateProgrammatically([bool $force = false ]) : mixed

If there is already an error, it will return that error (expect you pass $force = true).

Parameters
$force : bool = false

fetchRemoteStatus()

Fetch remote status from the Real Product Manager server. Automatically validates with `#validateRemoteResponse`, too.

public fetchRemoteStatus([bool $force = false ]) : mixed
Parameters
$force : bool = false

getActivation()

Get license activation handler.

public getActivation() : mixed
Tags
codeCoverageIgnore

getAsArray()

Get the license as array, useful for frontend needs or REST API.

public getAsArray() : mixed

getBlogId()

Get blog id.

public getBlogId() : mixed
Tags
codeCoverageIgnore

getBlogName()

Get blog name for this license.

public getBlogName() : mixed

getClient()

Get license client.

public getClient() : mixed

getCurrentHostname()

Getter. See also `getKnownHostname`.

public getCurrentHostname() : mixed

getInitiator()

Get initiator.

public getInitiator() : mixed

getKnownHostname()

Get known hostname. Can be empty if none given. The hostname will be set with the first license activation. The value itself is base64-encoded in database to avoid search & replace mechanism to replace the persisted URL.

public getKnownHostname() : string
Return values
string

getPluginConstantPrefix()

Get the prefix of this package so we can utils package natively.

public getPluginConstantPrefix() : string
Return values
string

getPluginUpdate()

Get plugin update handler.

public getPluginUpdate() : mixed
Tags
codeCoverageIgnore

getProgrammaticActivation()

See filter `DevOwl/RealProductManager/License/Programmatic/$slug`.

public getProgrammaticActivation() : mixed

getSlug()

Get plugin slug.

public getSlug() : mixed
Tags
codeCoverageIgnore

getTelemetryData()

Get license telemetry data handler.

public getTelemetryData() : mixed
Tags
codeCoverageIgnore

getUuid()

Get known UUID. Can be empty if none given. The UUID will be set with the first license activation.

public getUuid() : string
Return values
string

initialize()

Initalizes the license once.

public initialize() : mixed

isFulfilled()

Check if this license needs to have a license key (no usage) and if yes, check if one is given.

public isFulfilled() : mixed

If you want to check strictly if a license is active do something like !empty($license->getActivation()->getCode()).

isNoUsage()

Check if this license should not be used. It is mostly useful within Multisite when a non-free plugin should be only used on one sub site.

public isNoUsage() : bool
Return values
bool

newVersionInstalled()

A new version of the plugin got installed.

public newVersionInstalled() : mixed

probablyMigrate()

If given, read the old license key from the previous updater and give it back as hint.

public probablyMigrate() : mixed

probablySyncWithRemote()

The same as `syncWithRemote`, but surely synced only once a day.

public probablySyncWithRemote() : mixed

receivedRemoteLicenseActivation()

We received the remote license activation data. Let's save this to our database so other plugins can act on them.

public receivedRemoteLicenseActivation(array<string|int, mixed> $licenseActivation) : mixed

Use cases:

  • Enable/Disable functionality depending on client properties (Feature flags)
Parameters
$licenseActivation : array<string|int, mixed>

setupConstants()

Make sure the RPM_WP_CLIENT constants are available.

public static setupConstants() : mixed

syncWithRemote()

Sync our plugin version, PHP version and WordPress version with our remote system.

public syncWithRemote() : mixed

update_option_siteurl()

If the `site_url` got updated through e.g. the UI, persist the host name as known so that `self::validateNewHost` does not automatically deactivate the license - its still the same WordPress installation.

public update_option_siteurl() : mixed

validateNewHostName()

Check if the plugin got migrated to another host and deactivate the license automatically.

public validateNewHostName() : mixed

validateRemoteResponse()

Validate a remote response against their body and probably an error code.

public validateRemoteResponse(WP_Error|array<string|int, mixed> $response) : mixed

It automatically revokes the license if expired/revoked remotely.

Parameters
$response : WP_Error|array<string|int, mixed>

        
On this page

Search results