This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathwoocommerce-subscribe-all-the-things.php
executable file
·357 lines (294 loc) · 9.35 KB
/
woocommerce-subscribe-all-the-things.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
/*
* Plugin Name: WooCommerce Subscribe All The Things
* Plugin URI: https://github.com/Prospress/woocommerce-subscribe-to-all-the-things
* Description: Mini-extension for WooCommerce Subscriptions that allows you to add subscription plans to non-subscription product types.
* Version: 2.1.5
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
*
* Text Domain: woocommerce-subscribe-all-the-things
* Domain Path: /languages/
*
* Requires at least: 4.4
* Tested up to: 5.0
*
* WC requires at least: 3.0
* WC tested up to: 3.5
*
* Copyright: © 2017-2019 SomewhereWarm SMPC.
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WCS_ATT' ) ) :
// Abstract modules container class.
require_once( 'includes/modules/abstract/class-wcs-att-abstract-module.php' );
class WCS_ATT extends WCS_ATT_Abstract_Module {
/* Plugin version. */
const VERSION = '2.1.5';
/* Required WC version. */
const REQ_WC_VERSION = '3.0.0';
/* Required WC version. */
const REQ_WCS_VERSION = '2.1.0';
/* Mac WC version. */
const MAX_WC_VERSION = '3.5.100';
/* Max WC version. */
const MAX_WCS_VERSION = '2.5.100';
/* Text domain. */
const TEXT_DOMAIN = 'woocommerce-subscribe-all-the-things';
/**
* @var WCS_ATT - the single instance of the class.
*
* @since 1.0.0
*/
protected static $_instance = null;
/**
* Main WCS_ATT Instance.
*
* Ensures only one instance of WCS_ATT is loaded or can be loaded.
*
* @static
* @see WCS_ATT()
* @return WCS_ATT - Main instance
* @since 1.0.0
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Foul!', 'woocommerce-subscribe-all-the-things' ), '1.0.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Foul!', 'woocommerce-subscribe-all-the-things' ), '1.0.0' );
}
/**
* Do some work.
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
add_action( 'init', array( $this, 'init_textdomain' ) );
add_action( 'admin_init', array( $this, 'activate' ) );
add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
}
/**
* The plugin URL.
*
* @return string
*/
public function plugin_url() {
return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
}
/**
* The plugin path.
*
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Bootstrap.
*/
public function plugins_loaded() {
global $woocommerce;
// WCS 2.1+ check.
if ( ! class_exists( 'WC_Subscriptions' ) || version_compare( WC_Subscriptions::$version, self::REQ_WCS_VERSION ) < 0 ) {
add_action( 'admin_notices', array( $this, 'wcs_admin_notice' ) );
return false;
}
// WC 3.0+ check.
if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION ) < 0 ) {
add_action( 'admin_notices', array( $this, 'wc_admin_notice' ) );
return false;
}
// WCS < 2.6 check.
if ( version_compare( WC_Subscriptions::$version, self::MAX_WCS_VERSION ) >= 0 ) {
add_action( 'admin_notices', array( $this, 'wcs_apfs_admin_notice' ) );
}
// WC < 3.6 check.
if ( version_compare( $woocommerce->version, self::MAX_WC_VERSION ) >= 0 ) {
add_action( 'admin_notices', array( $this, 'wc_apfs_admin_notice' ) );
}
$this->includes();
}
/**
* Load plugin files.
*
* @return void
*/
public function includes() {
// Classes.
require_once( 'includes/class-wcs-att-core-compatibility.php' );
require_once( 'includes/class-wcs-att-integrations.php' );
require_once( 'includes/class-wcs-att-scheme.php' );
require_once( 'includes/class-wcs-att-product.php' );
require_once( 'includes/class-wcs-att-cart.php' );
require_once( 'includes/class-wcs-att-order.php' );
require_once( 'includes/class-wcs-att-sync.php' );
// Modules.
$this->register_modules();
$this->initialize_modules();
// Load display components.
require_once( 'includes/class-wcs-att-display.php' );
$this->register_component_hooks( 'display' );
// Load form handling components.
$this->register_component_hooks( 'form' );
// Legacy stuff.
require_once( 'includes/legacy/class-wcs-att-schemes.php' );
// Admin includes.
if ( is_admin() ) {
$this->admin_includes();
}
}
/**
* Include submodules.
*
* @since 2.1.0
*
* @return void
*/
protected function register_modules() {
require_once( 'includes/modules/class-wcs-att-management.php' );
$this->modules = apply_filters( 'wcsatt_modules', array(
'WCS_ATT_Management'
) );
}
/**
* Register all module hooks associated with a named SATT component.
*
* @since 2.1.0
*
* @param string $component
*/
protected function register_component_hooks( $component ) {
foreach ( $this->modules as $module ) {
$module->register_hooks( $component );
}
}
/**
* Loads the Admin & AJAX filters / hooks.
*
* @return void
*/
public function admin_includes() {
require_once( 'includes/admin/class-wcs-att-admin.php' );
}
/**
* Display a warning message if WCS min version check fails.
*
* @return void
*/
public function wc_admin_notice() {
echo '<div class="error"><p>' . sprintf( __( '<strong>Subscribe All The Things</strong> requires at least WooCommerce %s in order to function. Please upgrade WooCommerce.', 'woocommerce-subscribe-all-the-things' ), self::REQ_WC_VERSION ) . '</p></div>';
}
/**
* Display a warning message if WC min version check fails.
*
* @return void
*/
public function wcs_admin_notice() {
echo '<div class="error"><p>' . sprintf( __( '<strong>Subscribe All The Things</strong> requires WooCommerce Subscriptions version %s+.', 'woocommerce-subscribe-all-the-things' ), self::REQ_WCS_VERSION ) . '</p></div>';
}
/**
* Display a warning message if WCS max version check fails.
*
* @return void
*/
public function wcs_apfs_admin_notice() {
echo '<div class="notice notice-warning"><p>' . sprintf( __( '<strong>Subscribe All The Things</strong> has not been tested with the version of WooCommerce Subscriptions found on your system. Please consider upgrading to <a href="https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/">All Products For WooCommerce Subscriptions</a>, the WooCommerce.com successor of Subscribe All The Things.', 'woocommerce-subscribe-all-the-things' ), self::MAX_WCS_VERSION ) . '</p></div>';
}
/**
* Display a warning message if WC max version check fails.
*
* @return void
*/
public function wc_apfs_admin_notice() {
echo '<div class="notice notice-warning"><p>' . sprintf( __( '<strong>Subscribe All The Things</strong> has not been tested with the version of WooCommerce found on your system. Please consider upgrading to <a href="https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/">All Products For WooCommerce Subscriptions</a>, the WooCommerce.com successor of Subscribe All The Things.', 'woocommerce-subscribe-all-the-things' ), self::MAX_WC_VERSION ) . '</p></div>';
}
/**
* Load textdomain.
*
* @return void
*/
public function init_textdomain() {
load_plugin_textdomain( 'woocommerce-subscribe-all-the-things', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Store plugin version.
*
* @return void
*/
public function activate() {
global $wpdb;
$version = get_option( 'wcsatt_version', false );
if ( $version === false ) {
add_option( 'wcsatt_version', self::VERSION );
} elseif ( version_compare( $version, self::VERSION, '<' ) ) {
update_option( 'wcsatt_version', self::VERSION );
}
}
/**
* Product types supported by the plugin.
*
* @return array
*/
public function get_supported_product_types() {
return apply_filters( 'wcsatt_supported_product_types', array( 'simple', 'variable', 'variation', 'mix-and-match', 'bundle', 'composite' ) );
}
/**
* Log important stuff.
*
* @param string $message
* @param string $level
* @return void
*/
public function log( $message, $level ) {
$logger = wc_get_logger();
$logger->log( $level, $message, array( 'source' => 'wcs_att' ) );
}
/**
* Show row meta on the plugin screen.
*
* @param mixed $links Plugin Row Meta
* @param mixed $file Plugin Base file
* @return array
*/
public function plugin_meta_links( $links, $file, $data, $status ) {
if ( $file == plugin_basename( __FILE__ ) ) {
$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
$author2 = '<a href="http://somewherewarm.gr/">SomewhereWarm</a>';
$links[ 1 ] = sprintf( __( 'By %s', 'woocommerce-subscribe-all-the-things' ), sprintf( __( '%s and %s', 'woocommerce-subscribe-all-the-things' ), $author1, $author2 ) );
}
return $links;
}
}
// End class_exists check.
endif;
/**
* Returns the main instance of WCS_ATT to prevent the need to use globals.
*
* @since 1.0.0
* @return WooCommerce Subscribe All The Things
*/
function WCS_ATT() {
return WCS_ATT::instance();
}
// Launch the whole plugin.
$GLOBALS[ 'woocommerce_subscribe_all_the_things' ] = WCS_ATT();