Skip to content

Commit 26923c1

Browse files
author
=
committed
Added checks for settings not being initialised
1 parent 5c778ac commit 26923c1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

swiftcomplete.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function swiftcomplete_add_plugin_page_settings_link( $actions ) {
5353
return $actions;
5454
}
5555

56-
if ($settings['w3w_enabled'] == true) {
56+
if ($settings !== false && array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] == true) {
5757
add_action('woocommerce_after_order_notes', 'display_w3w_field');
5858
}
5959

@@ -108,18 +108,18 @@ function override_default_address_fields($address_fields)
108108
{
109109
$settings = get_option('swiftcomplete_settings');
110110

111-
if (array_key_exists('billing_placeholder', $settings) && strlen($settings['billing_placeholder']) > 0)
111+
if ($settings !== false && array_key_exists('billing_placeholder', $settings) && strlen($settings['billing_placeholder']) > 0)
112112
$billing_placeholder = esc_attr($settings['billing_placeholder']);
113113
else
114-
$billing_placeholder = array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'Type your address, postcode or what3words...' : 'Type your address or postcode...';
114+
$billing_placeholder = $settings !== false && array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'Type your address, postcode or what3words...' : 'Type your address or postcode...';
115115

116-
if (array_key_exists('shipping_placeholder', $settings) && strlen($settings['shipping_placeholder']) > 0)
116+
if ($settings !== false && array_key_exists('shipping_placeholder', $settings) && strlen($settings['shipping_placeholder']) > 0)
117117
$shipping_placeholder = esc_attr($settings['shipping_placeholder']);
118118
else
119-
$shipping_placeholder = array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'Type your address, postcode or what3words...' : 'Type your address or postcode...';
119+
$shipping_placeholder = $settings !== false && array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'Type your address, postcode or what3words...' : 'Type your address or postcode...';
120120

121-
$billing_label = array_key_exists('billing_label', $settings) && strlen($settings['billing_label']) > 0 ? esc_attr($settings['billing_label']) : 'Address Finder';
122-
$shipping_label = array_key_exists('shipping_label', $settings) && strlen($settings['shipping_label']) > 0 ? esc_attr($settings['shipping_label']) : 'Address Finder';
121+
$billing_label = $settings !== false && array_key_exists('billing_label', $settings) && strlen($settings['billing_label']) > 0 ? esc_attr($settings['billing_label']) : 'Address Finder';
122+
$shipping_label = $settings !== false && array_key_exists('shipping_label', $settings) && strlen($settings['shipping_label']) > 0 ? esc_attr($settings['shipping_label']) : 'Address Finder';
123123

124124
$address_fields['billing']['billing_address_autocomplete'] = array(
125125
'label' => __($billing_label, 'woocommerce'),
@@ -413,25 +413,25 @@ function add_swiftcomplete_billing()
413413
$settings = get_option('swiftcomplete_settings');
414414
$api_key = '';
415415

416-
if (array_key_exists('api_key', $settings) && strlen($settings['api_key']) > 0)
416+
if ($settings !== false && array_key_exists('api_key', $settings) && strlen($settings['api_key']) > 0)
417417
$api_key = $settings['api_key'];
418418

419419
wp_enqueue_script('swiftcomplete_script', 'https://script.swiftcomplete.com/js/swiftcomplete.js');
420420
wp_enqueue_script('swiftcomplete_launch', plugin_dir_url(__FILE__) . 'addressfinder.js', array('jquery'));
421-
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("billing", "' . esc_attr($api_key) . '", "' . (array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . (array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . (array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . (array_key_exists('billing_placeholder', $settings) ? esc_attr($settings['billing_placeholder']) : '') . '")'));
421+
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("billing", "' . esc_attr($api_key) . '", "' . ($settings !== false && array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . ($settings !== false && array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . ($settings !== false && array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . ($settings !== false && array_key_exists('billing_placeholder', $settings) ? esc_attr($settings['billing_placeholder']) : '') . '")'));
422422
}
423423

424424
function add_swiftcomplete_shipping()
425425
{
426426
$settings = get_option('swiftcomplete_settings');
427427
$api_key = '';
428428

429-
if (array_key_exists('api_key', $settings) && strlen($settings['api_key']) > 0)
429+
if ($settings !== false && array_key_exists('api_key', $settings) && strlen($settings['api_key']) > 0)
430430
$api_key = $settings['api_key'];
431431

432432
wp_enqueue_script('swiftcomplete_script', 'https://script.swiftcomplete.com/js/swiftcomplete.js');
433433
wp_enqueue_script('swiftcomplete_launch', plugin_dir_url(__FILE__) . 'addressfinder.js', array('jquery'));
434-
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("shipping", "' . esc_attr($api_key) . '", "' . (array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . (array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . (array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . (array_key_exists('shipping_placeholder', $settings) ? esc_attr($settings['shipping_placeholder']) : '') . '")'));
434+
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("shipping", "' . esc_attr($api_key) . '", "' . ($settings !== false && array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . ($settings !== false && array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . ($settings !== false && array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . ($settings !== false && array_key_exists('shipping_placeholder', $settings) ? esc_attr($settings['shipping_placeholder']) : '') . '")'));
435435
}
436436

437437
add_action('woocommerce_checkout_billing', 'add_swiftcomplete_billing');

0 commit comments

Comments
 (0)