Skip to content

Instantly share code, notes, and snippets.

@mch0lic
Created May 30, 2019 07:52
Show Gist options
  • Save mch0lic/10a519f764be0527fe74a2f789b072db to your computer and use it in GitHub Desktop.
Save mch0lic/10a519f764be0527fe74a2f789b072db to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce Payment Gateway - TF Bank
* Description: TF Bank Credit Line integration.
* Version: 1.0.1
* Author: Mindaugas Budreika
* Author URI: mailto:mindaugas.budreika@thecoffeemate.group
* Text Domain: woocommerce-gateway-tf-bank
* WC requires at least: 3.5.3
* WC tested up to: 3.5.3
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_TF_Bank' ) ) :
class WC_TF_Bank {
private static $instance;
public static $dir;
public static $url;
/**
* Returns the singleton instance of this class.
*
* @since 1.0.0
* @return Singleton The singleton instance.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
self::$dir = plugin_dir_path( __FILE__ );
self::$url = plugin_dir_url( __FILE__ );
}
return self::$instance;
}
/**
* Private clone method in place to prevent instance cloning.
*
* @since 1.0.0
* @return void
*/
private function __clone() {
}
/**
* Private unserialize method to prevent unserialization of instance.
*
* @since 1.0.0
* @return void
*/
private function __wakeup() {
}
/**
* Private method prevents creation of instances of this class outside
* the scope of this class.
*
* @since 1.0.0
*/
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'init' ) );
}
/**
* Init the plugin once action plugins_loaded is executed.
*
* @since 1.0.0
*/
public function init() {
if ( class_exists( 'WC_Payment_Gateway' ) ) {
require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-tf-bank.php';
// Register payment gateway with WooCommerce
add_filter( 'woocommerce_payment_gateways', array( $this, 'register_payment_gateway' ) );
}
// Add documentation link
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_action_links' ) );
// Load plugin textdomain.
load_plugin_textdomain( 'woocommerce-gateway-tf-bank', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Register new payment gateway.
*
* @since 1.0.0
*/
public function register_payment_gateway( $methods ) {
$methods[] = 'WC_Gateway_TF_Bank';
return $methods;
}
/**
* Adds action link to plugin documentation.
*
* @since 1.0.0
* @param $links
*/
public function add_action_links( $links ) {
$custom_links = array(
sprintf( '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout&section=tf_bank' ) ) . '">%s</a>', __( 'Settings', 'woocommerce-gateway-tf-bank' ) ),
sprintf( '<a href="' . esc_url( self::$url . 'docs/documentation.pdf' ) .'" target="_blank">%s</a>', __( 'Documentation', 'woocommerce-gateway-tf-bank' ) )
);
return array_merge( $custom_links, $links );
}
}
WC_TF_Bank::get_instance();
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment