forked from JeroenSormani/woocommerce-coupon-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-coupon-generator.php
169 lines (127 loc) · 3.35 KB
/
woocommerce-coupon-generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* Plugin Name: WooCommerce Coupon Generator
* Plugin URI:
* Description:
* Version: 1.0.0
* Author: Jeroen Sormani
* Author URI: http://www.jeroensormani.com/
* Text Domain: woocommerce-coupon-generator
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Class WooCommerce_Coupon_Generator.
*
* Main WooCommerce_Coupon_Generator class initializes the plugin.
*
* @class WooCommerce_Coupon_Generator
* @version 1.0.0
* @author Jeroen Sormani
*/
class WooCommerce_Coupon_Generator {
/**
* Plugin version.
*
* @since 1.0.0
* @var string $version Plugin version number.
*/
public $version = '1.0.0';
/**
* Plugin file.
*
* @since 1.0.0
* @var string $file Plugin file path.
*/
public $file = __FILE__;
/**
* Instance of WooCommerce_Coupon_Generator.
*
* @since 1.0.0
* @access private
* @var object $instance The instance of WooCommerce_Coupon_Generator.
*/
private static $instance;
/**
* Construct.
*
* Initialize the class and plugin.
*
* @since 1.0.0
*/
public function __construct() {
// Initialize plugin parts
$this->init();
}
/**
* Instance.
*
* An global instance of the class. Used to retrieve the instance
* to use on other files/plugins/themes.
*
* @since 1.0.0
* @return object Instance of the class.
*/
public static function instance() {
if( is_null ( self::$instance ) ) :
self::$instance = new self();
endif;
return self::$instance;
}
/**
* Init.
*
* Initialize plugin parts.
*
* @since 1.0.0
*/
public function init() {
// Check if WooCommerce is active
if ( ! function_exists ( 'is_plugin_active_for_network' ) ) :
require_once ( ABSPATH . '/wp-admin/includes/plugin.php' );
endif;
if ( ! in_array ( 'woocommerce/woocommerce.php', apply_filters ( 'active_plugins', get_option ( 'active_plugins' ) ) ) ) :
if ( ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) :
return;
endif;
endif;
if ( is_admin() ) :
// Functions
require_once plugin_dir_path( __FILE__ ) . 'includes/admin/wccg-core-functions.php';
// Classes
require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-wccg-admin.php';
$this->admin = new WCCG_Admin();
endif;
// Load textdomain
$this->load_textdomain();
}
/**
* Textdomain.
*
* Load the textdomain based on WP language.
*
* @since 1.0.0
*/
public function load_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-coupon-generator' );
// Load textdomain
load_textdomain( 'woocommerce-coupon-generator', WP_LANG_DIR . '/woocommerce-coupon-generator/woocommerce-coupon-generator-' . $locale . '.mo' );
load_plugin_textdomain( 'woocommerce-coupon-generator', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
}
/**
* The main function responsible for returning the WooCommerce_Coupon_Generator object.
*
* Use this function like you would a global variable, except without needing to declare the global.
*
* Example: <?php WooCommerce_Coupon_Generator()->method_name(); ?>
*
* @since 1.0.0
*
* @return object WooCommerce_Coupon_Generator class object.
*/
if ( ! function_exists( 'WooCommerce_Coupon_Generator' ) ) :
function WooCommerce_Coupon_Generator() {
return WooCommerce_Coupon_Generator::instance();
}
endif;
WooCommerce_Coupon_Generator();