* @copyright Copyright 2014 vendocrat. All Rights Reserved. * @link http://vendocr.at/ */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! class_exists( 'vendocrat_WC_Payment_Methods' ) ) : class vendocrat_WC_Payment_Methods { /* File var */ private $file; /* Basic vars */ public $version; public $plugin_url; public $plugin_dir; /* Payment methods */ public $available_methods; /** * Constructor * * @since 2014-08-15 * @version 2014-09-22 **************************************************/ function __construct( $file ) { // setup dir/uri $this->file = $file; $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); $this->plugin_dir = trailingslashit( dirname( $file ) ); // definitions $this->defines(); // load functions and classes $this->load_functions(); $this->load_classes(); // load text domain $this->load_plugin_textdomain(); $this->available_methods = array( 'amazon' => 'Amazon', 'american-express' => 'American Express', 'atm' => 'ATM', 'bank-transfer' => __( 'Bank Transfer', 'woocommerce-payment-methods' ), 'bankomat' => 'Bankomat', 'bitcoin' => 'Bitcoin', 'braintree' => 'Braintree', 'carta-si' => 'Carta Si', 'cash' => __( 'Cash', 'woocommerce-payment-methods' ), 'cash-on-delivery' => __( 'Cash on Delivery', 'woocommerce-payment-methods' ), 'cb' => 'CB', 'cirrus' => 'Cirrus', // 'cheque' => __( 'Pay with Cheque', 'woocommerce-payment-methods' ), 'clickandbuy' => 'ClickAndBuy', 'credit-card' => __( 'Credit Card', 'woocommerce-payment-methods' ), 'diners' => 'Diners Club', 'discover' => 'Discover', 'ec' => 'EC (Electronic Cash)', 'eps' => 'Eps', 'fattura' => __( 'Invoice', 'woocommerce-payment-methods' ), 'facture' => __( 'Invoice', 'woocommerce-payment-methods' ), 'flattr' => 'Flattr', 'giropay' => 'Giropay', 'gittip' => 'Gittip', 'google-wallet' => 'Google Wallet', 'ideal' => 'Ideal', 'invoice' => __( 'Invoice', 'woocommerce-payment-methods' ), 'jcb' => 'JCB', 'maestro' => 'Maestro', 'mastercard' => 'MasterCard', 'mastercard-securecode' => 'MasterCard Securecode', 'ogone' => 'Ogone', 'paybox' => 'Paybox', 'paylife' => 'Paylife', 'paymill' => 'Paymill', 'paypal' => 'PayPal', 'paysafecard' => 'paysafecard', 'postepay' => 'postepay', 'quick' => 'Quick', 'invoice' => __( 'Invoice', 'woocommerce-payment-methods' ), 'ripple' => 'Ripple', 'skrill' => 'Skrill', 'sofort' => 'SofortÜberweisung', 'square' => 'Square', 'stripe' => 'Stripe', 'truste' => 'Truste', 'unionpay' => 'Unionpay', 'verified-by-visa' => 'Verified By Visa', 'verisign' => 'Verisign', 'visa' => 'Visa', 'visa-electron' => 'Visa Electron', 'western-union' => 'Western Union', 'wirecard' => 'Wirecard', ); // scripts and styles if ( ! is_admin() ) : add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_styles' ) ); add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); endif; // register widgets add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); // add shortcode add_shortcode( 'v_woo_payment_methods', array( &$this, 'get_payment_methods' ) ); add_shortcode( 'wc_payment_methods', array( &$this, 'get_payment_methods' ) ); } /** * Definitions * * @return void * * @since 2014-09-22 * @version 2014-09-22 **************************************************/ function defines() { // Plugin define( 'WC_PAYMENT_METHODS_DIR', $this->plugin_dir ); define( 'WC_PAYMENT_METHODS_URI', $this->plugin_url ); // Assets define( 'WC_PAYMENT_METHODS_CSS_URI', trailingslashit( WC_PAYMENT_METHODS_URI . 'assets/css' ) ); define( 'WC_PAYMENT_METHODS_IMG_URI', trailingslashit( WC_PAYMENT_METHODS_URI . 'assets/img' ) ); } /** * Load functions * * @return void * * @since 2014-09-07 * @version 2014-09-07 **************************************************/ function load_functions() {} /** * Load classes * * @return void * * @since 2014-09-07 * @version 2014-09-07 **************************************************/ function load_classes() {} /** * Load theme textdomain * * @return void * * @since 2014-09-08 * @version 2014-10-23 **************************************************/ public function load_plugin_textdomain() { $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-payment-methods' ); $dir = trailingslashit( WP_LANG_DIR ); /** * Frontend/global Locale. Looks in: * - WP_LANG_DIR/woocommerce-payment-methods/woocommerce-payment-methods-LOCALE.mo * - woocommerce-payment-methods/languages/woocommerce-payment-methods-LOCALE.mo (which if not found falls back to:) * - WP_LANG_DIR/plugins/woocommerce-payment-methods-LOCALE.mo */ load_textdomain( 'woocommerce-payment-methods', $dir .'woocommerce-payment-methods/woocommerce-payment-methods-'. $locale .'.mo' ); load_plugin_textdomain( 'woocommerce-payment-methods', false, plugin_basename( $this->plugin_dir ) .'/languages/' ); } /** * Enqueue Styles * * @return void * * @since 2014-09-07 * @version 2014-09-21 **************************************************/ function enqueue_styles() { if ( ! wp_style_is( 'vendocrat-paymentfont', 'registered' ) ) { wp_register_style( 'vendocrat-paymentfont', WC_PAYMENT_METHODS_CSS_URI .'paymentfont.min.css', array(), false, 'all' ); } wp_enqueue_style( 'vendocrat-paymentfont' ); wp_register_style( 'payment-methods', WC_PAYMENT_METHODS_CSS_URI .'payment-methods.min.css', array(), false, 'all' ); wp_enqueue_style( 'payment-methods' ); } /** * Enqueue Scripts * * @return void * * @since 2014-09-07 * @version 2014-09-07 **************************************************/ function enqueue_scripts() {} /** * Register Widgets * * @return void * * @since 2014-09-07 * @version 2014-09-08 **************************************************/ function register_widgets() { require_once WC_PAYMENT_METHODS_DIR .'classes/class-widget-wc-payment-methods.php'; register_widget( 'vendocrat_Widget_WC_Payment_Methods' ); } /** * Woo Accepted Payment Methods * * @since 2014-09-07 * @version 2014-09-21 **************************************************/ function get_payment_methods( $atts = array(), $content = null ) { extract( shortcode_atts( array( 'methods' => false, // comma separated list of payment methods icon slugs to be displayed, see http://paymentfont.io for available icons (new since 0.2.0) 'style' => 'default', // default, inverse, o/outline 'tooltip' => false, // adds data attributes to icon to be used for diplaying tooltips (made for Bootstrap) 'placement' => 'bottom', // set tooltip placement (new since 0.1.2) 'xclass' => false, // add any extra classes, seperated by a space ), $atts ) ); $class = 'payment-methods'; $class.= ($style) ? ' payment-methods-'. $style : ''; $class.= ($xclass) ? ' '. $xclass : ''; // use the passed methods array if it's not empty, otherwhise use available gateways/methods if ( ! $methods ) { $gateways = $this->get_available_gateways(); $methods = $gateways['methods']; } if ( $methods ) { $methods = explode( ',', $methods ); foreach ( $methods as $key => $slug ) { if ( $slug ) $methods[$slug] = $slug; } $methods = array_flip( $methods ); } if ( count($methods) > 0 ) { // remove duplicate methods $methods = array_unique($methods); // sort array ksort($methods); // let the magic happen $icons = ''; foreach ( $methods as $slug ) { $icon = ''; // continue if we have no corresponding icon if ( ! array_key_exists ( $slug, $this->available_methods ) ) continue; // retrieve title $title = $this->available_methods[$slug]; // build icon class $iclass = 'pf pf-'. $slug .' '. $slug; // icon markup $icon = ''; // wrap in list item tags and append to $icons $icons.= '