WC_Integration_MaxMind_Geolocation
extends WC_Integration
in package
WC Integration MaxMind Geolocation
Tags
Table of Contents
- $enabled : string
- Yes or no based on whether the integration is enabled.
- $errors : array<string|int, mixed>
- Validation errors.
- $form_fields : array<string|int, mixed>
- Form option fields.
- $id : string
- ID of the class extending the settings API. Used in option names.
- $method_description : string
- Integration description.
- $method_title : string
- Integration title.
- $plugin_id : string
- The plugin ID. Used for option names.
- $settings : array<string|int, mixed>
- Setting values.
- $data : array<string|int, mixed>
- The posted settings data. When empty, $_POST data will be used.
- $database_service : WC_Integration_MaxMind_Database_Service
- The service responsible for interacting with the MaxMind database.
- __construct() : mixed
- Initialize the integration.
- add_error() : mixed
- Add an error message for display in admin on save.
- admin_options() : mixed
- Override the normal options so we can print the database file path to the admin,
- display_errors() : mixed
- Display admin error messages.
- display_missing_license_key_notice() : mixed
- Display notice if license key is missing.
- format_settings() : array<string|int, mixed>
- Format settings if needed.
- generate_checkbox_html() : string
- Generate Checkbox HTML.
- generate_color_html() : string
- Generate Color Picker Input HTML.
- generate_decimal_html() : string
- Generate Decimal Input HTML.
- generate_multiselect_html() : string
- Generate Multiselect HTML.
- generate_password_html() : string
- Generate Password Input HTML.
- generate_price_html() : string
- Generate Price Input HTML.
- generate_safe_text_html() : string
- Generates HTML for the 'safe_text' input type (mostly used for gateway-related settings).
- generate_select_html() : string
- Generate Select HTML.
- generate_settings_html() : string
- Generate Settings HTML.
- generate_text_html() : string
- Generate Text Input HTML.
- generate_textarea_html() : string
- Generate Textarea HTML.
- generate_title_html() : string
- Generate Title HTML.
- get_custom_attribute_html() : string
- Get custom attributes.
- get_database_service() : WC_Integration_MaxMind_Database_Service|null
- Get database service.
- get_description_html() : string
- Get HTML for descriptions.
- get_errors() : mixed
- Get admin error messages.
- get_field_default() : string
- Get a fields default value. Defaults to "" if not set.
- get_field_key() : string
- Prefix key for settings.
- get_field_type() : string
- Get a fields type. Defaults to "text" if not set.
- get_field_value() : string
- Get a field's posted and validated value.
- get_form_fields() : array<string|int, mixed>
- Get the form fields after they are initialized.
- get_geolocation() : array<string|int, mixed>
- Performs a geolocation lookup against the MaxMind database for the given IP address.
- get_method_description() : string
- Return the description for admin screens.
- get_method_title() : string
- Return the title for admin screens.
- get_option() : string
- Get option from DB.
- get_option_key() : string
- Return the name of the option in the WP DB.
- get_post_data() : array<string|int, mixed>
- Returns the POSTed data, to be used to save the settings.
- get_tooltip_html() : string
- Get HTML for tooltips.
- init_form_fields() : mixed
- Initializes the settings fields.
- init_settings() : mixed
- Initialise Settings.
- process_admin_options() : bool
- Processes and saves options.
- set_post_data() : mixed
- Sets the POSTed data. This method can be used to set specific data, instead of taking it from the $_POST array.
- update_database() : mixed
- Updates the database used for geolocation queries.
- update_option() : bool
- Update a single option.
- validate_checkbox_field() : string
- Validate Checkbox Field.
- validate_decimal_field() : string
- Validate Decimal Field.
- validate_license_key_field() : mixed
- Checks to make sure that the license key is valid.
- validate_multiselect_field() : string|array<string|int, mixed>
- Validate Multiselect Field.
- validate_password_field() : string
- Validate Password Field. No input sanitization is used to avoid corrupting passwords.
- validate_price_field() : string
- Validate Price Field.
- validate_safe_text_field() : string
- Sanitize 'Safe Text' fields.
- validate_select_field() : string
- Validate Select Field.
- validate_settings_fields() : mixed
- Validate the data on the "Settings" form.
- validate_text_field() : string
- Validate Text Field.
- validate_textarea_field() : string
- Validate Textarea Field.
- set_defaults() : array<string|int, mixed>
- Set default required properties for each field.
- add_missing_license_key_notice() : mixed
- Add missing license key notice.
- get_database_prefix() : string
- Fetches the prefix for the MaxMind database file.
- remove_missing_license_key_notice() : mixed
- Remove missing license key notice.
Properties
$enabled
Yes or no based on whether the integration is enabled.
public
string
$enabled
= 'yes'
$errors
Validation errors.
public
array<string|int, mixed>
$errors
= array()
$form_fields
Form option fields.
public
array<string|int, mixed>
$form_fields
= array()
$id
ID of the class extending the settings API. Used in option names.
public
string
$id
= ''
$method_description
Integration description.
public
string
$method_description
= ''
$method_title
Integration title.
public
string
$method_title
= ''
$plugin_id
The plugin ID. Used for option names.
public
string
$plugin_id
= 'woocommerce_'
$settings
Setting values.
public
array<string|int, mixed>
$settings
= array()
$data
The posted settings data. When empty, $_POST data will be used.
protected
array<string|int, mixed>
$data
= array()
$database_service
The service responsible for interacting with the MaxMind database.
private
WC_Integration_MaxMind_Database_Service
$database_service
Methods
__construct()
Initialize the integration.
public
__construct() : mixed
Return values
mixed —add_error()
Add an error message for display in admin on save.
public
add_error(string $error) : mixed
Parameters
- $error : string
-
Error message.
Return values
mixed —admin_options()
Override the normal options so we can print the database file path to the admin,
public
admin_options() : mixed
Return values
mixed —display_errors()
Display admin error messages.
public
display_errors() : mixed
Return values
mixed —display_missing_license_key_notice()
Display notice if license key is missing.
public
display_missing_license_key_notice(mixed $old_value, mixed $new_value) : mixed
Parameters
- $old_value : mixed
-
Option old value.
- $new_value : mixed
-
Current value.
Return values
mixed —format_settings()
Format settings if needed.
public
format_settings(array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
- $value : array<string|int, mixed>
-
Value to format.
Tags
Return values
array<string|int, mixed> —generate_checkbox_html()
Generate Checkbox HTML.
public
generate_checkbox_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_color_html()
Generate Color Picker Input HTML.
public
generate_color_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_decimal_html()
Generate Decimal Input HTML.
public
generate_decimal_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_multiselect_html()
Generate Multiselect HTML.
public
generate_multiselect_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_password_html()
Generate Password Input HTML.
public
generate_password_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_price_html()
Generate Price Input HTML.
public
generate_price_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_safe_text_html()
Generates HTML for the 'safe_text' input type (mostly used for gateway-related settings).
public
generate_safe_text_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_select_html()
Generate Select HTML.
public
generate_select_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_settings_html()
Generate Settings HTML.
public
generate_settings_html([array<string|int, mixed> $form_fields = array() ][, bool $echo = true ]) : string
Generate the HTML for the fields on the "settings" screen.
Parameters
- $form_fields : array<string|int, mixed> = array()
-
(default: array()) Array of form fields.
- $echo : bool = true
-
Echo or return.
Tags
Return values
string — the html for the settingsgenerate_text_html()
Generate Text Input HTML.
public
generate_text_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_textarea_html()
Generate Textarea HTML.
public
generate_textarea_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —generate_title_html()
Generate Title HTML.
public
generate_title_html(string $key, array<string|int, mixed> $data) : string
Parameters
- $key : string
-
Field key.
- $data : array<string|int, mixed>
-
Field data.
Tags
Return values
string —get_custom_attribute_html()
Get custom attributes.
public
get_custom_attribute_html(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
-
Field data.
Return values
string —get_database_service()
Get database service.
public
get_database_service() : WC_Integration_MaxMind_Database_Service|null
Return values
WC_Integration_MaxMind_Database_Service|null —get_description_html()
Get HTML for descriptions.
public
get_description_html(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
-
Data for the description.
Return values
string —get_errors()
Get admin error messages.
public
get_errors() : mixed
Return values
mixed —get_field_default()
Get a fields default value. Defaults to "" if not set.
public
get_field_default(array<string|int, mixed> $field) : string
Parameters
- $field : array<string|int, mixed>
-
Field key.
Return values
string —get_field_key()
Prefix key for settings.
public
get_field_key(string $key) : string
Parameters
- $key : string
-
Field key.
Return values
string —get_field_type()
Get a fields type. Defaults to "text" if not set.
public
get_field_type(array<string|int, mixed> $field) : string
Parameters
- $field : array<string|int, mixed>
-
Field key.
Return values
string —get_field_value()
Get a field's posted and validated value.
public
get_field_value(string $key, array<string|int, mixed> $field[, array<string|int, mixed> $post_data = array() ]) : string
Parameters
- $key : string
-
Field key.
- $field : array<string|int, mixed>
-
Field array.
- $post_data : array<string|int, mixed> = array()
-
Posted data.
Return values
string —get_form_fields()
Get the form fields after they are initialized.
public
get_form_fields() : array<string|int, mixed>
Return values
array<string|int, mixed> — of optionsget_geolocation()
Performs a geolocation lookup against the MaxMind database for the given IP address.
public
get_geolocation(array<string|int, mixed> $data, string $ip_address) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>
-
Geolocation data.
- $ip_address : string
-
The IP address to geolocate.
Return values
array<string|int, mixed> — Geolocation including country code, state, city and postcode based on an IP address.get_method_description()
Return the description for admin screens.
public
get_method_description() : string
Return values
string —get_method_title()
Return the title for admin screens.
public
get_method_title() : string
Return values
string —get_option()
Get option from DB.
public
get_option(string $key[, mixed $empty_value = null ]) : string
Gets an option from the settings API, using defaults if necessary to prevent undefined notices.
Parameters
- $key : string
-
Option key.
- $empty_value : mixed = null
-
Value when empty.
Return values
string — The value specified for the option or a default value for the option.get_option_key()
Return the name of the option in the WP DB.
public
get_option_key() : string
Tags
Return values
string —get_post_data()
Returns the POSTed data, to be used to save the settings.
public
get_post_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_tooltip_html()
Get HTML for tooltips.
public
get_tooltip_html(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
-
Data for the tooltip.
Return values
string —init_form_fields()
Initializes the settings fields.
public
init_form_fields() : mixed
Return values
mixed —init_settings()
Initialise Settings.
public
init_settings() : mixed
Store all settings in a single database entry and make sure the $settings array is either the default or the settings stored in the database.
Tags
Return values
mixed —process_admin_options()
Processes and saves options.
public
process_admin_options() : bool
If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.
Return values
bool — was anything saved?set_post_data()
Sets the POSTed data. This method can be used to set specific data, instead of taking it from the $_POST array.
public
set_post_data([array<string|int, mixed> $data = array() ]) : mixed
Parameters
- $data : array<string|int, mixed> = array()
-
Posted data.
Return values
mixed —update_database()
Updates the database used for geolocation queries.
public
update_database([string|null $new_database_path = null ]) : mixed
Parameters
- $new_database_path : string|null = null
-
The path to the new database file. Null will fetch a new archive.
Return values
mixed —update_option()
Update a single option.
public
update_option(string $key[, mixed $value = '' ]) : bool
Parameters
- $key : string
-
Option key.
- $value : mixed = ''
-
Value to set.
Tags
Return values
bool — was anything saved?validate_checkbox_field()
Validate Checkbox Field.
public
validate_checkbox_field(string $key, string $value) : string
If not set, return "no", otherwise return "yes".
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string —validate_decimal_field()
Validate Decimal Field.
public
validate_decimal_field(string $key, string $value) : string
Make sure the data is escaped correctly, etc.
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string —validate_license_key_field()
Checks to make sure that the license key is valid.
public
validate_license_key_field(string $key, mixed $value) : mixed
Parameters
- $key : string
-
The key of the field.
- $value : mixed
-
The value of the field.
Tags
Return values
mixed —validate_multiselect_field()
Validate Multiselect Field.
public
validate_multiselect_field(string $key, string $value) : string|array<string|int, mixed>
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string|array<string|int, mixed> —validate_password_field()
Validate Password Field. No input sanitization is used to avoid corrupting passwords.
public
validate_password_field(string $key, string $value) : string
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string —validate_price_field()
Validate Price Field.
public
validate_price_field(string $key, string $value) : string
Make sure the data is escaped correctly, etc.
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string —validate_safe_text_field()
Sanitize 'Safe Text' fields.
public
validate_safe_text_field(string $key, string $value) : string
These fields are similar to regular text fields, but a much smaller set of HTML tags are allowed. By default,
this means <br>
, <img>
, <p>
and <span>
tags.
Note: this is a sanitization method, rather than a validation method (the name is due to some historic naming choices).
Parameters
- $key : string
-
Field key (currently unused).
- $value : string
-
Posted Value.
Return values
string —validate_select_field()
Validate Select Field.
public
validate_select_field(string $key, string $value) : string
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string —validate_settings_fields()
Validate the data on the "Settings" form.
public
validate_settings_fields([array<string|int, mixed> $form_fields = array() ]) : mixed
Parameters
- $form_fields : array<string|int, mixed> = array()
-
Array of fields.
Tags
Return values
mixed —validate_text_field()
Validate Text Field.
public
validate_text_field(string $key, string $value) : string
Make sure the data is escaped correctly, etc.
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Return values
string —validate_textarea_field()
Validate Textarea Field.
public
validate_textarea_field(string $key, string $value) : string
Parameters
- $key : string
-
Field key.
- $value : string
-
Posted Value.
Tags
Return values
string —set_defaults()
Set default required properties for each field.
protected
set_defaults(array<string|int, mixed> $field) : array<string|int, mixed>
Parameters
- $field : array<string|int, mixed>
-
Setting field array.
Return values
array<string|int, mixed> —add_missing_license_key_notice()
Add missing license key notice.
private
add_missing_license_key_notice() : mixed
Return values
mixed —get_database_prefix()
Fetches the prefix for the MaxMind database file.
private
get_database_prefix() : string
Return values
string —remove_missing_license_key_notice()
Remove missing license key notice.
private
remove_missing_license_key_notice() : mixed