function currency_conversion_shortcode($atts) { $atts = shortcode_atts( array( 'amount' => '1', 'from' => 'USD', 'to' => 'EUR', ), $atts, 'currency_conversion' ); if (!is_numeric($atts['amount'])) { return "Invalid amount passed. Please pass a valid numeric value."; } $api_key = 'xxxxx-xxxx-xxxx'; $url = "https://api.fastforex.io/convert?from=" . $atts['from'] . "&to=" . $atts['to'] . "&amount=" . $atts['amount'] . "&api_key=" . $api_key; $result = file_get_contents($url); if ($result === false) { return "Error: Failed to fetch data from API."; } $result = json_decode($result, true); if (!isset($result['result']['rate'])) { return "Error: Invalid response from API."; } return $atts['amount'] . " " . $atts['from'] . " = " . $result['result']['rate'] . " " . $atts['to']; } add_shortcode('currency_conversion', 'currency_conversion_shortcode');
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)