Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Created December 9, 2012 04:51
Show Gist options
  • Save claudiosanches/4243377 to your computer and use it in GitHub Desktop.
Save claudiosanches/4243377 to your computer and use it in GitHub Desktop.
Easy Digital Downloads Bitcoin Currency
<?php
/**
* Plugin Name: Easy Digital Downloads BTC Currency
* Plugin URI: http://claudiosmweb.com/
* Description: Adds Bitcoin currency in Easy Digital Downloads
* Author: claudiosanches
* Author URI: http://claudiosmweb.com/
* Version: 1.0
* License: GPLv2 or later
* Text Domain: eddbitcc
* Domain Path: /languages/
*/
/**
* Add BTC Currency in Easy Digital Downloads.
*/
class EDD_BTC_Currency {
/**
* Class construct.
*/
public function __construct() {
// Actions.
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 0 );
// Filters.
add_filter( 'edd_currencies', array( $this, 'add_currency' ) );
add_filter( 'edd_btc_currency_filter_before', array( $this, 'currency_symbol' ) );
add_filter( 'edd_btc_currency_filter_after', array( $this, 'currency_symbol' ) );
add_filter( 'edd_format_amount_decimals', array( $this, 'currency_decimals' ) );
}
/**
* Load Plugin textdomain.
*
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( 'eddbitcc', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Add Bitcoin currency.
*
* @param array $currencies Default currencies.
*
* @return array News currencies with Bitcoin.
*/
public function add_currency( $currencies ) {
$currencies['BTC'] = __( 'Bitcoin (&#3647;)', 'eddbitcc' );
asort( $currencies );
return $currencies;
}
/**
* Fix Bitcoin currency symbol.
*
* @param string $formated Formated currency display.
*
* @return string Fixed Bitcoin currency display.
*/
public function currency_symbol( $formated ) {
$currency_symbol = apply_filters( 'bitcoin_currency_symbol', '&#3647;' );
$formated = str_replace( 'BTC', $currency_symbol, $formated );
return $formated;
}
/**
* Fix decimals to Bitcoin.
*
* @return int Bitcoin decimals.
*/
public function currency_decimals() {
return 8;
}
}
$edd_btc_currency = new EDD_BTC_Currency();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment