Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- en<?php
- private static $instance;
- public static function instance() {
- if ( ! self::$instance ) {
- self::$instance = new Woocommerce_Gateway_Green_Money();
- if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
- self::$instance->setup_constants();
- self::$instance->hooks();
- self::$instance->includes();
- self::$instance->load_textdomain();
- add_filter( 'woocommerce_payment_gateways', array( self::$instance, 'add_wc_gateway' ) );
- }
- }
- return self::$instance;
- }
- private function setup_constants() {
- // Plugin path
- define( 'WOO_GM_DIR', plugin_dir_path( __FILE__ ) );
- // Plugin URL
- define( 'WOO_GM_URL', plugin_dir_url( __FILE__ ) );
- }
- private function hooks() {
- register_activation_hook( __FILE__, array( 'Woocommerce_Gateway_Green_Money', 'activate' ) );
- register_deactivation_hook( __FILE__, array( 'Woocommerce_Gateway_Green_Money', 'deactivate' ) );
- }
- private function includes() {
- require_once WOO_GM_DIR . 'includes/gateway.php';
- }
- /**
- * Add the gateway to WooCommerce.
- *
- * @access public
- * @param array $methods
- * @return array
- */
- function add_wc_gateway( $methods ) {
- $methods[] = 'WC_Gateway_Green_Money';
- return $methods;
- }
- public function load_textdomain() {
- // Set filter for language directory
- $lang_dir = WOO_GM_DIR . '/languages/';
- $lang_dir = apply_filters( 'woo_gateway_green_money_lang_dir', $lang_dir );
- // Traditional WordPress plugin locale filter
- $locale = apply_filters( 'plugin_locale', get_locale(), '' );
- $mofile = sprintf( '%1$s-%2$s.mo', 'woocommerce-gateway-green-money', $locale );
- // Setup paths to current locale file
- $mofile_local = $lang_dir . $mofile;
- $mofile_global = WP_LANG_DIR . '/woocommerce-gateway-green-money/' . $mofile;
- if ( file_exists( $mofile_global ) ) {
- // Look in global /wp-content/languages/woocommerce-gateway-green-money/ folder
- load_textdomain( 'woocommerce-gateway-green-money', $mofile_global );
- } elseif ( file_exists( $mofile_local ) ) {
- // Look in local /wp-content/plugins/woocommerce-gateway-green-money/languages/ folder
- load_textdomain( 'woocommerce-gateway-green-money', $mofile_local );
- } else {
- // Load the default language files
- load_plugin_textdomain( 'woocommerce-gateway-green-money', false, $lang_dir );
- }
- }// END public function __construct()
- public static function activate() {
- flush_rewrite_rules();
- }
- public static function deactivate() {
- flush_rewrite_rules();
- }
- }// END class Woocommerce_Gateway_Green_Money
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
- $plugins = get_plugins();
- foreach ( $plugins as $plugin_path => $plugin ) {
- if ( 'WooCommerce' === $plugin['Name'] ) {
- define( 'HAS_WOO', true );
- break;
- }
- }
- add_action( 'admin_notices', 'woocommerce_gateway_green_money_notice' );
- } else { //else WooCommerce class exists
- return Woocommerce_Gateway_Green_Money::instance();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement