Last active
April 21, 2017 07:25
-
-
Save devpilot/e4c7ebb9efcb6f2553a91f0298e31c40 to your computer and use it in GitHub Desktop.
Fetch btc exchange rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package bc_exchange | |
* @version 1.2 | |
*/ | |
/* | |
Plugin Name: BC Exchange | |
Plugin URI: https://github.com/devpilot/ | |
Description: Get BTC Exchange rate from <a href="https://blockchain.info/">Blockchain</a> | |
Author: DevPilot | |
Version: 1.2 | |
Author URI: https://github.com/devpilot/ | |
*/ | |
/* Usage: [bcex currency=USD] */ | |
/** | |
* Fetch exchange rate | |
* | |
* @author DevPilot | |
*/ | |
class Ex_Rate { | |
/** | |
* Exchange data. | |
* | |
* @since 1.0.0 | |
* @access private | |
* @var string $exData exchange data in json. | |
*/ | |
private $exData; | |
public function __construct() { | |
$this->exData = file_get_contents('https://blockchain.info/ticker'); | |
} | |
// Add Shortcode | |
public function bcex_shortcode( $atts ) { | |
// Attributes | |
$atts = shortcode_atts( | |
array( | |
'currency' => 'USD', | |
), | |
$atts | |
); | |
if ($this->exData) { | |
$values = json_decode($this->exData); | |
$symb = $atts['currency']; | |
return $values->$symb->last; | |
} | |
} | |
} | |
$ex = new Ex_Rate; | |
add_shortcode( 'bcex', array( $ex, 'bcex_shortcode' ) ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment