-
Notifications
You must be signed in to change notification settings - Fork 0
/
give-addon-sms.php
315 lines (260 loc) · 6.56 KB
/
give-addon-sms.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/**
* Plugin Name: Give - Addon SMS
* Plugin URI: https://github.com/impress-org/give-addon-sms
* Description: .
* Version: 1.0
* Author: WordImpress, LLC
* Author URI: https://wordimpress.com
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: give-addon-sms
*/
/**
* Our Globals for easy Reference.
* You'll want to make sure you replace "GIVE_ADDON_SMS"
* with your own prefix throughout this whole plugin.
*
* Functions are prefixed with "give_boilerplate" and should be replaced as well.
*
* The text domain is give-addon-sms and should be replaced as well.
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Give_Addon_SMS
*/
final class Give_Addon_SMS {
/**
* Instance.
*
* @since
* @access private
* @var Give_Addon_SMS
*/
private static $instance;
/**
* Singleton pattern.
*
* @since
* @access private
*/
private function __construct() {
}
/**
* Get instance.
*
* @return Give_Addon_SMS
* @since
* @access public
*
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Give_Addon_SMS ) ) {
self::$instance = new Give_Addon_SMS();
self::$instance->setup();
}
return self::$instance;
}
/**
* Setup
*
* @since
* @access private
*/
private function setup() {
self::$instance->setup_constants();
register_activation_hook( GIVE_ADDON_SMS_FILE, array( $this, 'install' ) );
add_action( 'give_init', array( $this, 'init' ), 10, 1 );
add_action( 'plugins_loaded', array( $this, 'check_environment' ), 999 );
add_filter( 'give-settings_get_settings_pages', array( $this, 'register_setting_page' ) );
}
/**
* Setup constants
*
* Defines useful constants to use throughout the add-on.
*
* @since
* @access private
*/
private function setup_constants() {
// Defines addon version number for easy reference.
if ( ! defined( 'GIVE_ADDON_SMS_VERSION' ) ) {
define( 'GIVE_ADDON_SMS_VERSION', '1.0' );
}
// Set it to latest.
if ( ! defined( 'GIVE_ADDON_SMS_MIN_GIVE_VERSION' ) ) {
define( 'GIVE_ADDON_SMS_MIN_GIVE_VERSION', '2.3.0' );
}
if ( ! defined( 'GIVE_ADDON_SMS_FILE' ) ) {
define( 'GIVE_ADDON_SMS_FILE', __FILE__ );
}
if ( ! defined( 'GIVE_ADDON_SMS_DIR' ) ) {
define( 'GIVE_ADDON_SMS_DIR', plugin_dir_path( GIVE_ADDON_SMS_FILE ) );
}
if ( ! defined( 'GIVE_ADDON_SMS_URL' ) ) {
define( 'GIVE_ADDON_SMS_URL', plugin_dir_url( GIVE_ADDON_SMS_FILE ) );
}
if ( ! defined( 'GIVE_ADDON_SMS_BASENAME' ) ) {
define( 'GIVE_ADDON_SMS_BASENAME', plugin_basename( GIVE_ADDON_SMS_FILE ) );
}
}
/**
* Plugin installation
*
* @since
* @access public
*/
public function install() {
// Bailout.
if ( ! self::$instance->check_environment() ) {
return;
}
}
/**
* Plugin installation
*
* @param Give $give
*
* @return void
* @since
* @access public
*
*/
public function init( $give ) {
if ( ! self::$instance->check_environment() ) {
return;
}
require_once __DIR__ . '/vendor/autoload.php';
self::$instance->load_files();
self::$instance->setup_hooks();
self::$instance->load_license();
}
/**
* Check plugin environment
*
* @return bool|null
* @since
* @access public
*
*/
public function check_environment() {
// Bailout.
if ( ! is_admin() || ! current_user_can( 'activate_plugins' ) ) {
return null;
}
// Load plugin helper functions.
if ( ! function_exists( 'deactivate_plugins' ) || ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
// Load helper functions.
require_once GIVE_ADDON_SMS_DIR . 'includes/misc-functions.php';
// Flag to check whether deactivate plugin or not.
$is_deactivate_plugin = false;
// Verify dependency cases.
switch ( true ) {
case doing_action( 'give_init' ):
if (
defined( 'GIVE_VERSION' ) &&
version_compare( GIVE_VERSION, GIVE_ADDON_SMS_MIN_GIVE_VERSION, '<' )
) {
/* Min. Give. plugin version. */
// Show admin notice.
add_action( 'admin_notices', '__give_addon_sms_dependency_notice' );
$is_deactivate_plugin = true;
}
break;
case doing_action( 'activate_' . GIVE_ADDON_SMS_BASENAME ):
case doing_action( 'plugins_loaded' ) && ! did_action( 'give_init' ):
/* Check to see if Give is activated, if it isn't deactivate and show a banner. */
// Check for if give plugin activate or not.
$is_give_active = defined( 'GIVE_PLUGIN_BASENAME' ) ? is_plugin_active( GIVE_PLUGIN_BASENAME ) : false;
if ( ! $is_give_active ) {
add_action( 'admin_notices', '__give_addon_sms_inactive_notice' );
$is_deactivate_plugin = true;
}
break;
}
// Don't let this plugin activate.
if ( $is_deactivate_plugin ) {
// Deactivate plugin.
deactivate_plugins( GIVE_ADDON_SMS_BASENAME );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
return false;
}
return true;
}
/**
* Register setting page.
*
* @param $settings
*
* @return array
*/
function register_setting_page( $settings ) {
require_once GIVE_ADDON_SMS_DIR . 'includes/admin/settings.php';
$settings[] = new Give_SMS_Admin_Settings();
return $settings;
}
/**
* Load plugin files.
*
* @since
* @access private
*/
private function load_files() {
require_once GIVE_ADDON_SMS_DIR . 'includes/misc-functions.php';
require_once GIVE_ADDON_SMS_DIR . 'includes/sms.php';
if ( is_admin() ) {
require_once GIVE_ADDON_SMS_DIR . 'includes/admin/setting-examples.php';
}
}
/**
* Setup hooks
*
* @since
* @access private
*/
private function setup_hooks() {
// Filters
add_filter( 'plugin_action_links_' . GIVE_ADDON_SMS_BASENAME, '__give_addon_sms_plugin_row_meta', 10, 2 );
// Actions
add_action( 'admin_init', '__give_addon_sms_activation_banner' );
}
/**
* Load license
*
* @since
* @access private
*/
private function load_license() {
new Give_License(
GIVE_ADDON_SMS_FILE,
'Give Addon Boilerplate',
GIVE_ADDON_SMS_VERSION,
'WordImpress',
'give_addon_sms_license_key'
);
}
}
/**
* The main function responsible for returning the one true Give_Addon_SMS instance
* to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $recurring = Give_Addon_SMS(); ?>
*
* @return Give_Addon_SMS|bool
* @since 1.0
*
*/
function Give_Addon_SMS() {
return Give_Addon_SMS::get_instance();
}
Give_Addon_SMS();