GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Data Fields | Static Private Attributes
LicenseManager Class Reference

Public Member Functions

 activate_license ( $license_key)
 Activates license. More...
 
 ajax_activate_license (array $payload)
 AJAX request wrapper for the activate_license() method. More...
 
 ajax_deactivate_license (array $payload)
 AJAX request wrapper for the deactivate_license() method. More...
 
 ajax_get_licenses_data (array $payload)
 AJAX request wrapper for the get_licenses_data() method. More...
 
 check_license ( $license_key)
 Checks license key for validity. More...
 
 check_licenses (array $license_keys)
 Checks multiples license keys for validity. More...
 
 configure_ajax_routes (array $routes)
 Configures AJAX routes handled by this class. More...
 
 deactivate_license ( $license_key, $force_removal=false)
 Deactivates license. More...
 
 display_license_info_on_plugins_page ( $plugin_name, $plugin_data)
 Optionally adds notices to installed plugins when license is invalid or expired. More...
 
 get_license_key_status_message ( $status)
 Returns license status message based on the EDD status code. More...
 
 get_licenses_data ()
 Retrieves license data from the database. More...
 
 get_product_license_map ( $key_by='id')
 Returns an object keyed by product ID and associated licenses. More...
 
 get_product_licenses ( $id)
 Returns licenses for a product. More...
 
 get_site_data ()
 Retrieves site data (plugin versions, integrations, etc.) to be sent along with the license check. More...
 
 init ()
 Initializes the class. More...
 
 is_expired_license ( $expiry)
 Determines if the license has expired. More...
 
 mask_license_key ( $license_key)
 Masks part of the license key. More...
 
 migrate_legacy_licenses ( $force_migration=false)
 Migrates licenses for products that do not have Foundation integrated. More...
 
 modify_license_data_for_frontend_output ( $license)
 Adds additional data to the license object for use in the frontend. More...
 
 perform_remote_license_call ( $license, $edd_action)
 Performs remote call to the EDD API. More...
 
 process_hardcoded_licenses ()
 Saves new or removes existing hardcoded licenses from the license data. More...
 
 recheck_all_licenses ( $skip_cache=false)
 Rechecks all licenses and updates the database. More...
 
 save_licenses_data (array $licenses_data)
 Saves license data in the database. More...
 
 update_submenu_badge_count ()
 Optionally updates the Licenses submenu badge count if any of the products are unlicensed. More...
 

Static Public Member Functions

static get_instance ()
 Returns class instance. More...
 

Data Fields

 $_licenses_data
 
const EDD_ACTION_ACTIVATE_LICENSE = 'activate_license'
 
const EDD_ACTION_CHECK_LICENSE = 'check_license'
 
const EDD_ACTION_DEACTIVATE_LICENSE = 'deactivate_license'
 
const EDD_LICENSES_API_ENDPOINT = 'https://www.gravitykit.com'
 
const EDD_LICENSES_API_VERSION = 2
 
const HARDCODED_LICENSE_CONSTANTS = [ 'GRAVITYVIEW_LICENSE_KEY', 'GRAVITYKIT_LICENSES' ]
 

Static Private Attributes

static $_instance
 

Detailed Description

Definition at line 21 of file LicenseManager.php.

Member Function Documentation

◆ activate_license()

activate_license (   $license_key)

Activates license.

Since
1.0.0
Parameters
string$license_keylicense_key
Exceptions
Exception
Returns
array License information.

Definition at line 462 of file LicenseManager.php.

References Framework\get_instance(), LicenseManager\get_license_key_status_message(), LicenseManager\get_licenses_data(), LicenseManager\perform_remote_license_call(), and LicenseManager\save_licenses_data().

Referenced by LicenseManager\ajax_activate_license(), and LicenseManager\migrate_legacy_licenses().

◆ ajax_activate_license()

ajax_activate_license ( array  $payload)

AJAX request wrapper for the activate_license() method.

Since
1.0.0
Parameters
array$payload
Exceptions
Exception
Returns
array License information.

Definition at line 439 of file LicenseManager.php.

References LicenseManager\activate_license(), Framework\get_instance(), and LicenseManager\modify_license_data_for_frontend_output().

◆ ajax_deactivate_license()

ajax_deactivate_license ( array  $payload)

AJAX request wrapper for the deactivate_license() method.

Since
1.0.0
Parameters
array$payload
Exceptions
Exception
Returns
void

Definition at line 513 of file LicenseManager.php.

References LicenseManager\deactivate_license(), Encryption\get_instance(), and LicenseManager\get_licenses_data().

◆ ajax_get_licenses_data()

ajax_get_licenses_data ( array  $payload)

◆ check_license()

check_license (   $license_key)

Checks license key for validity.

Since
1.0.0
Parameters
string$license_key
Exceptions
Exception
Returns
array License data.

Definition at line 401 of file LicenseManager.php.

References LicenseManager\perform_remote_license_call().

◆ check_licenses()

check_licenses ( array  $license_keys)

Checks multiples license keys for validity.

Since
1.0.0
Parameters
array$license_keys
Exceptions
Exception
Returns
array Licenses data.

Definition at line 420 of file LicenseManager.php.

References LicenseManager\perform_remote_license_call().

Referenced by LicenseManager\migrate_legacy_licenses(), LicenseManager\process_hardcoded_licenses(), and LicenseManager\recheck_all_licenses().

◆ configure_ajax_routes()

configure_ajax_routes ( array  $routes)

Configures AJAX routes handled by this class.

Since
1.0.0
See also
Core::process_ajax_request()
Parameters
array$routesAJAX route to class method map.
Returns
array

Definition at line 105 of file LicenseManager.php.

◆ deactivate_license()

deactivate_license (   $license_key,
  $force_removal = false 
)

Deactivates license.

Since
1.0.0
1.0.7 Added $force_removal parameter.
Parameters
string$license_key
bool$force_removal(optional) Forces removal of license from the local licenses object even if deactivation request fails. Default: false.
Exceptions
Exception
Returns
void

Definition at line 547 of file LicenseManager.php.

References Arr\get(), LicenseManager\get_licenses_data(), LicenseManager\is_expired_license(), LicenseManager\perform_remote_license_call(), and LicenseManager\save_licenses_data().

Referenced by LicenseManager\ajax_deactivate_license().

◆ display_license_info_on_plugins_page()

display_license_info_on_plugins_page (   $plugin_name,
  $plugin_data 
)

Optionally adds notices to installed plugins when license is invalid or expired.

Since
1.0.0
Parameters
string$plugin_name
array$plugin_data
Returns
void

Definition at line 868 of file LicenseManager.php.

References $url, ProductManager\get_instance(), Framework\get_instance(), and LicenseManager\get_licenses_data().

◆ get_instance()

static get_instance ( )
static

◆ get_license_key_status_message()

get_license_key_status_message (   $status)

Returns license status message based on the EDD status code.

Since
1.0.0
Parameters
string$statusEDD status code.
Returns
mixed

Definition at line 267 of file LicenseManager.php.

Referenced by LicenseManager\activate_license().

◆ get_licenses_data()

get_licenses_data ( )

◆ get_product_license_map()

get_product_license_map (   $key_by = 'id')

Returns an object keyed by product ID and associated licenses.

Since
1.0.0
Parameters
string$key_by(optional) Key (product ID or text domain) to use for the returned array. Choices: 'id' or 'text_domain'. Default: 'id'.
Returns
array

Definition at line 209 of file LicenseManager.php.

References LicenseManager\get_licenses_data().

Referenced by LicenseManager\get_product_licenses().

◆ get_product_licenses()

get_product_licenses (   $id)

Returns licenses for a product.

Since
1.0.0
Parameters
int | string$idProduct ID or text domain.
Returns
array

Definition at line 250 of file LicenseManager.php.

References LicenseManager\get_product_license_map().

◆ get_site_data()

get_site_data ( )

Retrieves site data (plugin versions, integrations, etc.) to be sent along with the license check.

Since
1.0.0
Returns
array

Definition at line 950 of file LicenseManager.php.

References GV_PLUGIN_VERSION, Core\ID, and Arr\only().

Referenced by LicenseManager\perform_remote_license_call().

◆ init()

init ( )

◆ is_expired_license()

is_expired_license (   $expiry)

Determines if the license has expired.

Since
1.0.0
Parameters
int | string$expiryUnix time or 'lifetime'.
Returns
bool

Definition at line 1068 of file LicenseManager.php.

Referenced by LicenseManager\deactivate_license(), and LicenseManager\modify_license_data_for_frontend_output().

◆ mask_license_key()

mask_license_key (   $license_key)

Masks part of the license key.

Since
1.0.0
Parameters
string$license_key
Returns
string

Definition at line 626 of file LicenseManager.php.

Referenced by LicenseManager\modify_license_data_for_frontend_output().

◆ migrate_legacy_licenses()

migrate_legacy_licenses (   $force_migration = false)

Migrates licenses for products that do not have Foundation integrated.

Since
1.0.0
Parameters
bool$force_migrationWhether to force migration even if it was done before.
Returns
void

Definition at line 722 of file LicenseManager.php.

References LicenseManager\activate_license(), LicenseManager\check_licenses(), Arr\get(), LicenseManager\get_licenses_data(), Framework\ID, and LicenseManager\save_licenses_data().

Referenced by LicenseManager\ajax_get_licenses_data(), and LicenseManager\init().

◆ modify_license_data_for_frontend_output()

modify_license_data_for_frontend_output (   $license)

Adds additional data to the license object for use in the frontend.

  • Encrypts license key
  • Formats expiration date or message if license is expired
Since
1.0.0
Parameters
$license
Returns
array

Definition at line 588 of file LicenseManager.php.

References Encryption\get_instance(), Core\get_request_unique_string(), LicenseManager\is_expired_license(), and LicenseManager\mask_license_key().

Referenced by LicenseManager\ajax_activate_license(), and LicenseManager\ajax_get_licenses_data().

◆ perform_remote_license_call()

perform_remote_license_call (   $license,
  $edd_action 
)

Performs remote call to the EDD API.

1.0

Parameters
string | array$license
string$edd_action
Exceptions
Exception
Returns
array Response body.

Definition at line 301 of file LicenseManager.php.

References LicenseManager\get_site_data(), and Helpers\query_api().

Referenced by LicenseManager\activate_license(), LicenseManager\check_license(), LicenseManager\check_licenses(), and LicenseManager\deactivate_license().

◆ process_hardcoded_licenses()

process_hardcoded_licenses ( )

Saves new or removes existing hardcoded licenses from the license data.

Since
1.0.0
Returns
void

Definition at line 645 of file LicenseManager.php.

References LicenseManager\check_licenses(), LicenseManager\get_licenses_data(), and LicenseManager\save_licenses_data().

Referenced by LicenseManager\ajax_get_licenses_data(), and LicenseManager\init().

◆ recheck_all_licenses()

recheck_all_licenses (   $skip_cache = false)

Rechecks all licenses and updates the database.

Since
1.0.0
Parameters
bool$skip_cacheWhether to skip returning products from cache.
Returns
void

Definition at line 812 of file LicenseManager.php.

References LicenseManager\check_licenses(), LicenseManager\get_licenses_data(), Framework\ID, and LicenseManager\save_licenses_data().

Referenced by LicenseManager\ajax_get_licenses_data(), and LicenseManager\init().

◆ save_licenses_data()

save_licenses_data ( array  $licenses_data)

Saves license data in the database.

Since
1.0.0
Parameters
array$licenses_data
Returns
bool

Definition at line 181 of file LicenseManager.php.

References Encryption\get_instance(), and Framework\ID.

Referenced by LicenseManager\activate_license(), LicenseManager\deactivate_license(), LicenseManager\migrate_legacy_licenses(), LicenseManager\process_hardcoded_licenses(), and LicenseManager\recheck_all_licenses().

◆ update_submenu_badge_count()

update_submenu_badge_count ( )

Optionally updates the Licenses submenu badge count if any of the products are unlicensed.

Since
1.0.0
Returns
void

Definition at line 1029 of file LicenseManager.php.

References $update_count, ProductManager\get_instance(), Framework\get_instance(), and Framework\ID.

Referenced by LicenseManager\init().

Field Documentation

◆ $_instance

$_instance
staticprivate

Definition at line 39 of file LicenseManager.php.

◆ $_licenses_data

$_licenses_data

Definition at line 46 of file LicenseManager.php.

Referenced by LicenseManager\get_licenses_data().

◆ EDD_ACTION_ACTIVATE_LICENSE

const EDD_ACTION_ACTIVATE_LICENSE = 'activate_license'

Definition at line 28 of file LicenseManager.php.

◆ EDD_ACTION_CHECK_LICENSE

const EDD_ACTION_CHECK_LICENSE = 'check_license'

Definition at line 26 of file LicenseManager.php.

◆ EDD_ACTION_DEACTIVATE_LICENSE

const EDD_ACTION_DEACTIVATE_LICENSE = 'deactivate_license'

Definition at line 30 of file LicenseManager.php.

◆ EDD_LICENSES_API_ENDPOINT

const EDD_LICENSES_API_ENDPOINT = 'https://www.gravitykit.com'

Definition at line 22 of file LicenseManager.php.

◆ EDD_LICENSES_API_VERSION

const EDD_LICENSES_API_VERSION = 2

Definition at line 24 of file LicenseManager.php.

◆ HARDCODED_LICENSE_CONSTANTS

const HARDCODED_LICENSE_CONSTANTS = [ 'GRAVITYVIEW_LICENSE_KEY', 'GRAVITYKIT_LICENSES' ]

Definition at line 32 of file LicenseManager.php.


The documentation for this class was generated from the following file: