How to add its own custom currency aggregator
From WPCS version 2.1.5/1.1.5 it is possible with 2 next hooks: wpcs_announce_aggregator and wpcs_add_aggregator_processor in file functions.php of the current wordpress theme.
Example:
add_action('wpcs_announce_aggregator', function($aggregators) {
$aggregators['hello_world'] = 'My own aggregator';
return $aggregators;
});
add_action('wpcs_add_aggregator_processor', function($aggregator_key, $currency_name) {
global $WPCS;
$request = [];
//ratesapi.io as an example
if ($aggregator_key === 'hello_world') {
$query_url = 'https://api.ratesapi.io/api/latest?base=' . $WPCS->default_currency . '&symbols=' . $currency_name;
if (function_exists('curl_init')) {
$res = $WPCS->file_get_contents_curl($query_url);
} else {
$res = file_get_contents($query_url);
}
$data = json_decode($res, true);
$request = isset($data['rates'][$currency_name]) ? $data['rates'][$currency_name] : 0;
if (!$request) {
$request = sprintf("no data for %s", $currency_name);
}
}
return $request;
}, 10, 2);