$key ) { if ( ! is_string( $key ) || // provider that does not need api key ! empty( $options['providers'][ $provider ] ) ) { // provider that has api key $list += array( $provider => $provider ); } } // get selected item $provider = array(); $providers = array_keys( $providers ); $cookie = $context->get_cookie(); if ( isset( $cookie[ $tab ] ) ) { foreach ( array_slice( (array)$cookie[ $tab ], 3 ) as $key => $val ) { if ( 'o' === $val ) { $provider[] = $providers[ $key ]; } } } add_settings_field( $option_name.'_service', __( 'Geolocation API', 'ip-geo-block' ), array( $context, 'callback_field' ), $option_slug, $section, array( 'type' => 'select', 'attr' => 'multiple="multiple"', 'option' => $option_name, 'field' => 'service', 'value' => ! empty( $provider ) ? $provider : $providers[0], 'list' => $list, ) ); // preset IP address if ( isset( $_GET['s'] ) ) { $list = preg_replace( array( '/\.\*+$/', '/:\w*\*+$/', '/(::.*)::$/' ), array( '.0', '::', '$1' ), trim( $_GET['s'] ) ); // de-anonymize if `***` exists $list = filter_var( $list, FILTER_VALIDATE_IP ) ? $list : ''; } else { $list = ''; } add_settings_field( $option_name.'_ip_address', __( 'IP address', 'ip-geo-block' ), array( $context, 'callback_field' ), $option_slug, $section, array( 'type' => 'text', 'option' => $option_name, 'field' => 'ip_address', 'value' => $list, ) ); // Anonymize IP address add_settings_field( $option_name.'_anonymize', __( 'Anonymize IP address', 'ip-geo-block' ), array( $context, 'callback_field' ), $option_slug, $section, array( 'type' => 'checkbox', 'option' => $option_name, 'field' => 'anonymize', 'value' => ( ! empty( $options['anonymize'] ) || ! empty( $options['restrict_api'] ) ) ? TRUE : FALSE, ) ); // Search geolocation add_settings_field( $option_name.'_get_location', __( 'Search geolocation', 'ip-geo-block' ), array( $context, 'callback_field' ), $option_slug, $section, array( 'type' => 'button', 'option' => $option_name, 'field' => 'get_location', 'value' => __( 'Search now', 'ip-geo-block' ), 'after' => '
', ) ); } }