Bitcoin Forum
May 26, 2017, 09:34:37 AM *
News: If the forum does not load normally for you, please send me a traceroute.
   Home   Help Search Donate Login Register  
Pages: [1]
Author Topic: Bitcoin Wordpress Widget  (Read 1711 times)
Sr. Member
Offline Offline

Activity: 266

View Profile
February 18, 2012, 08:35:03 AM

At the moment this is only a simple widget, which displays the current bitcoin price (high, low, avg and vol), as well as the option to display a sig for donations.

Although it can be made into much more if people think there would be a use for it, so let me know if of any suggestions/ideas.

For anybody who is unsure how to use the code below

1 - Create a file called bitcoin_widget.php ( it can really be any filename you like, as long as its .php), and copy the code below into it.
2 - Create a folder called bitcoin_widget in your wordpress content dir
3 - Drop the widget into the folder and activate it in the plugins menu.
4 - Hit up the widgets page under the Appearence menu, and drag the one called "Bitcoin!" into you desired location.


Plugin Name: Bitcoin WordPress
Description: Add bitcoin stuff to your WordPress blog
Author: fanquake
Version: 1.0
Revision Date: February 18, 2012
Requires at least: WP 3.2
Tested up to: WP 3.4

function getBitcoinPrice() {
 // Fetch the current rate from MtGox
$ch curl_init('');
curl_setopt($chCURLOPT_REFERER'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
$mtgoxjson curl_exec($ch);
// Decode from an object to array
$output_mtgox json_decode($mtgoxjson);
$output_mtgox_1 get_object_vars($output_mtgox);
$mtgox_array get_object_vars($output_mtgox_1['ticker']);


<li><strong>Last:</strong>&nbsp;&nbsp;<?php echo $mtgox_array['last'];   ?></li>
<li><strong>High:</strong>&nbsp;<?php echo $mtgox_array['high'];   ?></li>
<li><strong>Low:</strong>&nbsp;&nbsp;<?php echo $mtgox_array['low'];   ?></li>
<li><strong>Avg:</strong>&nbsp;&nbsp;&nbsp;<?php echo $mtgox_array['avg'];   ?></li>
<li><strong>Vol:</strong>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $mtgox_array['vol'];   ?></li>
class bitcoin_widget extends WP_Widget {
// Constructor //
function bitcoin_widget() {
$widget_ops = array( 'classname' => 'bitcoin_widget''description' => 'Show some bitcoin stuff' ); // Widget Settings
$control_ops = array( 'id_base' => 'bitcoin_widget' ); // Widget Control Settings
$this->WP_Widget'bitcoin_widget''Bitcoins!'$widget_ops$control_ops ); // Create the widget

// Extract Args //

function widget($args$instance) {
extract$args );

$title  apply_filters('widget_title'$instance['title']); // The widget title
$show_price = isset($instance['show_price']) ? $instance['show_price'] : false// Show the Bitcoin price
$donate = isset($instance['donate_bitcoins']) ? $instance['donate_bitcoins'] : false// Get some bitcoins for your blog
$donation_address = isset($instance['donation_address']) ? $instance['donation_address'] : false// Donation address

// Before widget //

echo $before_widget;

// Title of widget //

if ( $title ) { echo $before_title $title $after_title; }

// Widget output //


if ($show_price){
if ($donate) { ?>

<p style="font-size:12px;">
Send me some Bitcoins! <?php echo $donation_address?>
<?php }

// After widget //

echo $after_widget;

// Update Settings //
function update($new_instance$old_instance) {
$instance['title']     = strip_tags($new_instance['title']);
$instance['show_price']     = $new_instance['show_price'];
$instance['donate_bitcoins']     = $new_instance['donate_bitcoins'];
$instance['donation_address']     = $new_instance['donation_address'];
return $instance;
// Widget Control Panel //

function form($instance) {

$defaults = array( 'title' => 'Bitcoins!''show_price' => 'on''donate_bitcoins' => 'on''donation_address' => 'xxx'  );
$instance wp_parse_args( (array) $instance$defaults ); ?>

<label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>'" type="text" value="<?php echo $instance['title']; ?>" />
<label for="<?php echo $this->get_field_id('show_price'); ?>"><?php _e('Show the Bitcoin price?'); ?></label>
<input type="checkbox" class="checkbox" <?php checked$instance['show_price'], 'on' ); ?> id="<?php echo $this->get_field_id('show_price'); ?>" name="<?php echo $this->get_field_name('show_price'); ?>" />
<label for="<?php echo $this->get_field_id('donate_bitcoins'); ?>"><?php _e('Add a bitcoin donation address?'); ?></label>
<input type="checkbox" class="checkbox" <?php checked$instance['donate_bitcoins'], 'on' ); ?> id="<?php echo $this->get_field_id('donate_bitcoins'); ?>" name="<?php echo $this->get_field_name('donate_bitcoins'); ?>" />
<label for="<?php echo $this->get_field_id('donation_address'); ?>"><?php _e('Donation Address:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('donation_address'); ?>" name="<?php echo $this->get_field_name('donation_address'); ?>" type="text" value="<?php echo $instance['donation_address']; ?>" />
        <?php }

// End class bitcoin_widget
add_action('widgets_init'create_function('''return register_widget("bitcoin_widget");'));
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Offline Offline

Activity: 12

View Profile WWW
April 30, 2012, 12:11:03 AM

Hi there...looking for a WP plugin that enables me to set a price in USD for my items..the item's bitcoin prices automatically updates with the inflation/deflation in the MtGox price. For instance, if I sell a golf club for $100, divide current gox price of $5 and it's price is obv 20 BTC. But if the MtGox rate goes to $2.50 (god forbid) then I want my prices to automatically change to $100/2.50 = 40 BTC.. I want them to update hourly of 4x daily, or just daily etc. Using wordpress flexishop theme with ecommerce plugin..SQL version 5

(And know verrrry little about coding)
Offline Offline

Activity: 19

View Profile
September 08, 2012, 01:37:25 AM

you need add some lines for ping mtgox and output a error text if is offline. mtgox is not always online . when is offline the widget may cause lag in the page. plz find a way without use exec
Pages: [1]
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!