self::mask($options['adscout_api_token']), 'partner_domain_hex' => self::mask($options['adscout_partner_domain_hex']), ); (new AdScout_Frontend())::include_partial('integration-settings', 'admin', $data); return; } /** * The AdScout locations (name + API base URL) published by AdScout. * Also the allowlist for the API endpoint option - see AdScout_Ajax::adscout_save_base_url(). * * @return array * @since 2.5.2 */ public static function locations(): array { $location_data = null; $response = wp_remote_get(ADSCOUT_LOCATIONS_URL); if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) { $location_data = json_decode(wp_remote_retrieve_body($response), true); } $location_data = is_array($location_data) ? $location_data : [ ['name' => 'AdScout', 'url' => 'https://scoutefy.com/'], ]; $filtered_location_data = array_filter($location_data, function($item) { return is_array($item) && isset($item['name']) && isset($item['url']) && wp_parse_url($item['url'], PHP_URL_SCHEME) === 'https'; }); return array_map(function($item) { return ['name' => $item['name'], 'url' => $item['url']]; }, $filtered_location_data); } public static function api_base_url_settings(): void { $adjusted_location_data = self::locations(); $options = (new AdScout_Options()); $base_url = 'https://scoutefy.com/'; if($options::get_option('adscout_api_endpoint') and $options::get_option('adscout_api_endpoint') !== '') { $base_url = $options::get_option('adscout_api_endpoint'); } $locations_data = [ 'endpoints' => array_map(function ($item) { return [$item['name'] => $item['url']]; }, $adjusted_location_data), 'selected' => $base_url, ]; (new AdScout_Frontend())::include_partial('api-base-url', 'admin', $locations_data); } public static function feed_settings(): void { $options = (new AdScout_Options())::all_options(); $feed_data = array( 'as_feed_last_updated' => $options['as_feed_last_updated'] ?? false, 'as_feed_url' => $options['as_feed_url'] ?? false, ); (new AdScout_Frontend())::include_partial('feed-generator', 'admin', $feed_data); } public static function sync_user_data(): void { $options = (new AdScout_Options())::all_options(); (new AdScout_Frontend())::include_partial('share-order-personal-data', 'admin', [ 'applied' => (new AdScout_Options())::get_option('sync_user_data'), ]); } public static function coupon_settings(): void { (new AdScout_Frontend())::include_partial('coupon-settings', 'admin', [ 'url' => esc_url( get_rest_url() ) . ADSCOUT_API_ENDPOINT_PREFIX . ADSCOUT_API_ENDPOINT_NAME, ]); } public static function order_status_settings(): void { $options = (new AdScout_Options())::all_options(); if (!is_array($options['adscout_order_statuses_to_sync'])) { $statuses = explode(',', $options['adscout_order_statuses_to_sync']); } else { $statuses = $options['adscout_order_statuses_to_sync']; } $data = array( 'adscout_order_statuses_to_sync' => $statuses, ); (new AdScout_Frontend())::include_partial('order-sync-status-settings', 'admin', $data); } /** * Returns a masked token to show in frontend * @param $token * @return string */ public static function mask($token): string { if ($token and strlen($token) > 10) { return str_repeat('•', strlen(substr($token, -20)) - 10) . substr(substr($token, -20), -10); } return '••••••'; } }