WC_Integration_MaxMind_Geolocation::validate_license_key_field()publicWC 1.0

Checks to make sure that the license key is valid.

Method of the class: WC_Integration_MaxMind_Geolocation{}

No Hooks.




$WC_Integration_MaxMind_Geolocation = new WC_Integration_MaxMind_Geolocation();
$WC_Integration_MaxMind_Geolocation->validate_license_key_field( $key, $value );
$key(string) (required)
The key of the field.
$value(mixed) (required)
The value of the field.

WC_Integration_MaxMind_Geolocation::validate_license_key_field() code WC 8.9.0

public function validate_license_key_field( $key, $value ) {
	// Trim whitespaces and strip slashes.
	$value = $this->validate_password_field( $key, $value );

	// Empty license keys have no need test downloading a database.
	if ( empty( $value ) ) {
		return $value;

	// Check the license key by attempting to download the Geolocation database.
	$tmp_database_path = $this->database_service->download_database( $value );
	if ( is_wp_error( $tmp_database_path ) ) {
		WC_Admin_Settings::add_error( $tmp_database_path->get_error_message() );

		// Throw an exception to keep from changing this value. This will prevent
		// users from accidentally losing their license key, which cannot
		// be viewed again after generating.
		throw new Exception( $tmp_database_path->get_error_message() );

	// We may as well put this archive to good use, now that we've downloaded one.
	self::update_database( $tmp_database_path );

	// Remove missing license key notice.

	return $value;