Bitcoin Forum
December 08, 2016, 08:09:42 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Bitcoin Wordpress Widget  (Read 1661 times)
fanquake
Donator
Sr. Member
*
Offline Offline

Activity: 266


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

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.




Code:
<?php

/*
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('https://mtgox.com/api/0/data/ticker.php');
curl_setopt($chCURLOPT_REFERER'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($chCURLOPT_USERAGENT"CakeScript/0.1");
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
$mtgoxjson curl_exec($ch);
curl_close($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']);

?>

<ul>
<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>
</ul>
<?php
}
 
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 //
?>


<?php 

if ($show_price){
getBitcoinPrice();
 }
if ($donate) { ?>

<p style="font-size:12px;">
Send me some Bitcoins! <?php echo $donation_address?>
</p>
<?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 ); ?>


<p>
<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']; ?>" />
</p>
<p>
<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'); ?>" />
</p>
<p>
<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'); ?>" />
</p>
<p>
<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']; ?>" />
</p>
        <?php }
 
}

// End class bitcoin_widget
add_action('widgets_init'create_function('''return register_widget("bitcoin_widget");'));
?>
1481184582
Hero Member
*
Offline Offline

Posts: 1481184582

View Profile Personal Message (Offline)

Ignore
1481184582
Reply with quote  #2

1481184582
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481184582
Hero Member
*
Offline Offline

Posts: 1481184582

View Profile Personal Message (Offline)

Ignore
1481184582
Reply with quote  #2

1481184582
Report to moderator
1481184582
Hero Member
*
Offline Offline

Posts: 1481184582

View Profile Personal Message (Offline)

Ignore
1481184582
Reply with quote  #2

1481184582
Report to moderator
CryptoGolfer
Newbie
*
Offline Offline

Activity: 12



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

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 periodically...like hourly of 4x daily, or just daily etc. Using wordpress flexishop theme with ecommerce plugin..SQL version 5

(And know verrrry little about coding)
iformas
Newbie
*
Offline Offline

Activity: 19


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

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

http://www.bitcoinschile.cl
http://forums.bitcoinschile.cl/
Pages: [1]
  Print  
 
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!