Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. en<?php
  2.  
  3. private static $instance;
  4.  
  5. public static function instance() {
  6. if ( ! self::$instance ) {
  7. self::$instance = new Woocommerce_Gateway_Green_Money();
  8. if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
  9. self::$instance->setup_constants();
  10. self::$instance->hooks();
  11. self::$instance->includes();
  12. self::$instance->load_textdomain();
  13.  
  14. add_filter( 'woocommerce_payment_gateways', array( self::$instance, 'add_wc_gateway' ) );
  15. }
  16. }
  17. return self::$instance;
  18. }
  19.  
  20. private function setup_constants() {
  21. // Plugin path
  22. define( 'WOO_GM_DIR', plugin_dir_path( __FILE__ ) );
  23.  
  24. // Plugin URL
  25. define( 'WOO_GM_URL', plugin_dir_url( __FILE__ ) );
  26. }
  27.  
  28. private function hooks() {
  29. register_activation_hook( __FILE__, array( 'Woocommerce_Gateway_Green_Money', 'activate' ) );
  30. register_deactivation_hook( __FILE__, array( 'Woocommerce_Gateway_Green_Money', 'deactivate' ) );
  31. }
  32.  
  33. private function includes() {
  34. require_once WOO_GM_DIR . 'includes/gateway.php';
  35. }
  36.  
  37. /**
  38. * Add the gateway to WooCommerce.
  39. *
  40. * @access public
  41. * @param array $methods
  42. * @return array
  43. */
  44. function add_wc_gateway( $methods ) {
  45.  
  46. $methods[] = 'WC_Gateway_Green_Money';
  47. return $methods;
  48. }
  49.  
  50. public function load_textdomain() {
  51. // Set filter for language directory
  52. $lang_dir = WOO_GM_DIR . '/languages/';
  53. $lang_dir = apply_filters( 'woo_gateway_green_money_lang_dir', $lang_dir );
  54.  
  55. // Traditional WordPress plugin locale filter
  56. $locale = apply_filters( 'plugin_locale', get_locale(), '' );
  57. $mofile = sprintf( '%1$s-%2$s.mo', 'woocommerce-gateway-green-money', $locale );
  58.  
  59. // Setup paths to current locale file
  60. $mofile_local = $lang_dir . $mofile;
  61. $mofile_global = WP_LANG_DIR . '/woocommerce-gateway-green-money/' . $mofile;
  62.  
  63. if ( file_exists( $mofile_global ) ) {
  64. // Look in global /wp-content/languages/woocommerce-gateway-green-money/ folder
  65. load_textdomain( 'woocommerce-gateway-green-money', $mofile_global );
  66. } elseif ( file_exists( $mofile_local ) ) {
  67. // Look in local /wp-content/plugins/woocommerce-gateway-green-money/languages/ folder
  68. load_textdomain( 'woocommerce-gateway-green-money', $mofile_local );
  69. } else {
  70. // Load the default language files
  71. load_plugin_textdomain( 'woocommerce-gateway-green-money', false, $lang_dir );
  72. }
  73. }// END public function __construct()
  74.  
  75. public static function activate() {
  76. flush_rewrite_rules();
  77. }
  78.  
  79. public static function deactivate() {
  80. flush_rewrite_rules();
  81. }
  82.  
  83. }// END class Woocommerce_Gateway_Green_Money
  84.  
  85. require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  86.  
  87. $plugins = get_plugins();
  88.  
  89. foreach ( $plugins as $plugin_path => $plugin ) {
  90. if ( 'WooCommerce' === $plugin['Name'] ) {
  91. define( 'HAS_WOO', true );
  92. break;
  93. }
  94. }
  95. add_action( 'admin_notices', 'woocommerce_gateway_green_money_notice' );
  96. } else { //else WooCommerce class exists
  97. return Woocommerce_Gateway_Green_Money::instance();
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement