-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-subscribe-all-the-things.php
executable file
·242 lines (199 loc) · 5.96 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
<?php
/*
* Plugin Name: WooCommerce Subscribe All the Things
* Plugin URI: https://github.com/Prospress/woocommerce-subscribe-to-all-the-things
* Description: Experimental extension for linking WooCommerce Subscriptions with simple products, variable products and product types created by WooCommerce extensions, such as Composite Products and Product Bundles.
* Version: 1.1.2
* Author: Prospress Inc.
* Author URI: http://prospress.com/
*
* Text Domain: woocommerce-subscribe-all-the-things
* Domain Path: /languages/
*
* Requires at least: 4.1
* Tested up to: 4.6
*
* Copyright: © 2009-2015 Prospress, Inc.
* 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' ) ) :
class WCS_ATT {
/* Plugin version. */
const VERSION = '1.1.2';
/* Required WC version. */
const REQ_WC_VERSION = '2.3.0';
/* 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!' ), '1.0.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '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 );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
}
public function plugin_url() {
return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
}
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
public function plugins_loaded() {
global $woocommerce;
// Subs 2 check
if ( ! function_exists( 'wcs_is_subscription' ) ) {
add_action( 'admin_notices', array( $this, 'wcs_admin_notice' ) );
return false;
}
// WC 2 check
if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION ) < 0 ) {
add_action( 'admin_notices', array( $this, 'wc_admin_notice' ) );
return false;
}
require_once( 'includes/class-wcsatt-core-compatibility.php' );
require_once( 'includes/class-wcsatt-integrations.php' );
require_once( 'includes/class-wcsatt-schemes.php' );
require_once( 'includes/class-wcsatt-scheme-prices.php' );
require_once( 'includes/class-wcsatt-cart.php' );
require_once( 'includes/class-wcsatt-display.php' );
// Admin includes
if ( is_admin() ) {
$this->admin_includes();
}
}
/**
* Loads the Admin & AJAX filters / hooks.
*
* @return void
*/
public function admin_includes() {
require_once( 'includes/admin/class-wcsatt-admin.php' );
}
/**
* Display a warning message if Subs version check fails.
*
* @return void
*/
public function wc_admin_notice() {
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Subscribe All the Things requires at least WooCommerce %s in order to function. Please upgrade WooCommerce.', self::TEXT_DOMAIN ), self::REQ_WC_VERSION ) . '</p></div>';
}
/**
* Display a warning message if WC version check fails.
*
* @return void
*/
public function wcs_admin_notice() {
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Subscribe All the Things requires WooCommerce Subscriptions version 2.0+.', self::TEXT_DOMAIN ), self::REQ_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 );
}
}
/**
* Deactivate extension.
*
* @return void
*/
public function deactivate() {
delete_option( 'wcsatt_version' );
}
/**
* Product types supported by the plugin.
* You can dynamically attach subscriptions to these product types
*
* @return array
*/
public function get_supported_product_types() {
return apply_filters( 'wcsatt_supported_product_types', array( 'simple', 'variable', 'variation', 'mix-and-match', 'bundle', 'composite' ) );
}
/**
* 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.net/">SomewhereWarm</a>';
$links[ 1 ] = sprintf( __( 'By %s' ), sprintf( __( '%s and %s' ), $author1, $author2 ) );
}
return $links;
}
}
endif; // end class_exists check
/**
* 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();