forked from pronamic/woocommerce-subscriptions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwoocommerce-subscriptions.php
More file actions
204 lines (175 loc) · 6.11 KB
/
woocommerce-subscriptions.php
File metadata and controls
204 lines (175 loc) · 6.11 KB
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
<?php
/**
* Plugin Name: WooCommerce Subscriptions
* Plugin URI: https://www.woocommerce.com/products/woocommerce-subscriptions/
* Description: Sell products and services with recurring payments in your WooCommerce Store.
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Version: 8.6.0
* Requires Plugins: woocommerce
*
* Requires at least: 6.8
* Tested up to: 6.9
* Requires PHP: 7.4
*
* WC requires at least: 10.5
* WC tested up to: 10.6
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Copyright: © 2025 WooCommerce
*
* Woo: 27147:6115e6d7e297b623a169fdcf5728b224
*
* @package WooCommerce Subscriptions
* @author WooCommerce.
* @since 1.0
*/
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/includes/class-wc-subscriptions-dependency-manager.php';
$dependency_manager = new WC_Subscriptions_Dependency_Manager( WC_Subscriptions::$wc_minimum_supported_version );
// Check the dependencies before loading the plugin. If the dependencies are not met, display an admin notice and exit
if ( ! $dependency_manager->has_valid_dependencies() ) {
add_action( 'admin_notices', [ $dependency_manager, 'display_dependency_admin_notice' ] );
return;
}
/**
* Declare plugin compatibility with WooCommerce HPOS.
*
* @since 4.9.0
*/
add_action(
'before_woocommerce_init',
function() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);
add_action(
'woocommerce_init',
function () {
// Overrides the WooCommerce version to the WC()->version.
// This prevents the wrong version being stored in the transient during a WooCommerce core downgrade.
set_transient( 'wcs_woocommerce_active_version', WC()->version, HOUR_IN_SECONDS );
}
);
// Subscribe to automated translations.
add_filter( 'woocommerce_translations_updates_for_woocommerce-subscriptions', '__return_true' );
// Load and set up the Autoloader
$wcs_autoloader = wcs_init_autoloader();
/**
* The main subscriptions class.
*
* @since 1.0
*/
class WC_Subscriptions {
/**
* Name of the option field used to store the active plugin version. This is principally
* used in support of plugin update logic.
*/
public const PLUGIN_VERSION_OPTION_NAME = 'wcs_plugin_version';
/** @var string */
public static $name = 'subscription';
/** @var string */
public static $activation_transient = 'woocommerce_subscriptions_activated';
/** @var string */
public static $plugin_file = __FILE__;
/** @var string */
public static $version = '8.6.0'; // WRCS: DEFINED_VERSION.
/** @var string */
public static $wc_minimum_supported_version = '7.7';
/** @var WCS_Cache_Manager */
public static $cache;
/** @var WCS_Autoloader */
protected static $autoloader;
/**
* Set up the class, including it's hooks & filters, when the file is loaded.
*
* @since 1.0
*
* @param WCS_Autoloader $autoloader Autoloader instance.
*/
public static function init( $autoloader = null ) {
$plugin = new WC_Subscriptions_Plugin( $autoloader );
self::$cache = $plugin->cache;
self::$autoloader = $plugin->get_autoloader();
}
/*
* Plugin House Keeping
*/
/**
* Called when WooCommerce is inactive or running and out-of-date version to display an inactive notice.
*
* @deprecated 5.0.0
*
* @since 1.2
*/
public static function woocommerce_inactive_notice() {
_deprecated_function( __METHOD__, '5.0.0', 'WC_Subscriptions_Dependency_Manager::display_dependency_admin_notice' );
$dependency_manager = new WC_Subscriptions_Dependency_Manager( WC_Subscriptions::$wc_minimum_supported_version );
$dependency_manager->display_dependency_admin_notice();
}
/* Deprecated Functions */
/**
* Handle deprecation function calls.
*
* @since 4.0.0
*
* @param string $method The name of the method being called.
* @param array $arguments An array containing the parameters passed to the method.
*
* @return void|mixed The value returned from a deprecated function replacement or null.
*/
public static function __callStatic( $method, $arguments ) {
static $deprecation_handler = null;
// Initialise the handler if we dont have one already.
if ( ! $deprecation_handler ) {
$deprecation_handler = new WC_Subscriptions_Deprecation_Handler();
}
if ( $deprecation_handler->is_deprecated( $method ) ) {
$deprecation_handler->trigger_notice( $method );
return $deprecation_handler->call_replacement( $method, $arguments );
} else {
// Trigger an error consistant with PHP if the function called doesn't exist.
$class = __CLASS__;
$trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 );
$file = $trace[0]['file'];
$line = $trace[0]['line'];
throw new Error( "Call to undefined method $class::$method() in $file on line $line" ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
/**
* Add woocommerce_inbox_variant for the Remote Inbox Notification.
*
* P2 post can be found at https://wp.me/paJDYF-1uJ.
*/
if ( ! function_exists( 'add_woocommerce_inbox_variant' ) ) {
function add_woocommerce_inbox_variant() {
$config_name = 'woocommerce_inbox_variant_assignment';
if ( false === get_option( $config_name, false ) ) {
update_option( $config_name, wp_rand( 1, 12 ) );
}
}
}
add_action( 'woocommerce_subscriptions_upgraded', 'add_woocommerce_inbox_variant', 10 );
register_activation_hook( __FILE__, 'add_woocommerce_inbox_variant' );
/**
* Load and set up the Autoloader
*
* If the `woocommerce-subscriptions-core` plugin is active, setup the autoloader using this plugin directory
* as the base file path for loading subscription core classes.
*
* @since 4.0.0
* @return WCS_Autoloader
*/
function wcs_init_autoloader() {
$wcs_core_path = __DIR__ . '/includes/core/';
require_once $wcs_core_path . '/class-wcs-core-autoloader.php';
require_once dirname( __FILE__ ) . '/includes/class-wcs-autoloader.php';
$wcs_autoloader = new WCS_Autoloader( $wcs_core_path );
$wcs_autoloader->register();
return $wcs_autoloader;
}
WC_Subscriptions::init( $wcs_autoloader );