Skip to main content

gfpdf_addon_hardcoded_license_key

Description

This filter overrides the license key used by Gravity PDF extensions, and takes precedence over both the GPDF_LICENSE_KEY constant and any key saved on the License settings page. Use it when the key needs to come from somewhere the constant can't reach e.g. an environment variable, a secrets manager, or a per-site lookup on Multisite.

When using this filter the License settings field becomes read-only and the Deactivate License button is hidden.

Version

This filter was introduced in Gravity PDF 6.16.

Parameters

$license_key | string | array | null

  • The current key. This is the value of the GPDF_LICENSE_KEY constant when it's defined, otherwise null

Three return types are supported:

  • A string applies the same key to every installed Gravity PDF extension. Use this for a license that includes multiple products
  • An array keyed by extension slug applies a different key to each extension e.g. [ 'gravity-pdf-core-booster' => '...' ]
  • An array can also include a * key, which is used as the fallback for any extension not explicitly listed

Return an empty value to fall back to the key saved on the License settings page.

$slug | string

  • The slug of the extension requesting the key e.g. gravity-pdf-core-booster

$addon | Helper_Abstract_Addon

  • The extension object requesting the key

Usage

This snippet reads a single license key from an environment variable and applies it to all installed extensions:

add_filter( 'gfpdf_addon_hardcoded_license_key', function( $license_key, $slug, $addon ) {
return getenv( 'GPDF_LICENSE' ) ?: $license_key;
}, 10, 3 );

This snippet sets a different key per extension, with a fallback for anything not listed:

add_filter( 'gfpdf_addon_hardcoded_license_key', function( $license_key, $slug, $addon ) {
return [
'gravity-pdf-core-booster' => 'NpMmzRwVpkudnXQRfuEdk7wEi2W88Fz6',
'gravity-pdf-previewer' => '6NZMdPGmwUTgzfUh6qmfVgGp4kZA7jQ4',
'*' => 'kQ8sT2vXbNjW4pR7yLmC5dHfG9zA3eUx',
];
}, 10, 3 );

Source Code

This filter is located in the Helper_Abstract_Addon::get_license_key_from_constant() method of /src/Helper/Helper_Abstract_Addon.php.