PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.10.8
Subscriptions for WooCommerce with Stripe Recurring Payments v1.10.8
1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 All 60 releases
subscription / subscription.php

subscription.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.10.8, at subscription.php

339 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Subscriptions for WooCommerce with Stripe Recurring Payments
4 * Plugin URI: https://wpsubscription.co/
5 * Description: WPSubscription allows WooCommerce to enable recurring payments, subscriptions, and auto-renewals for digital and physical products. Supports Stripe, PayPal, Paddle, and more.
6 *
7 * Version: 1.10.8
8 *
9 * Author: ConversWP
10 * Author URI: https://wpsubscription.co/
11 *
12 * Text Domain: subscription
13 * Domain Path: /languages
14 *
15 * Requires PHP: 7.4
16 *
17 * Requires at least: 6.0
18 * Tested up to: 7.0
19 *
20 * WC requires at least: 6.0
21 * WC tested up to: 10.3
22 *
23 * Requires Plugins: woocommerce
24 *
25 * License: GPLv2 or later
26 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
27 *
28 * @package Subscription
29 */
30
31 // don't call the file directly.
32 if ( ! defined( 'ABSPATH' ) ) {
33 exit;
34 }
35
36 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
37 use SpringDevs\Subscription\Illuminate\Gateways\Paypal\Paypal_Blocks_Integration;
38
39 require_once __DIR__ . '/vendor/autoload.php';
40
41 /**
42 * Sdevs_Subscription class
43 *
44 * @class Sdevs_Subscription The class that holds the entire plugin
45 */
46 final class Sdevs_Subscription {
47
48
49 /**
50 * Plugin version
51 *
52 * @var string
53 */
54 const VERSION = '1.10.8';
55
56 /**
57 * Holds various class instances
58 *
59 * @var array
60 */
61 private $container = array();
62
63 /**
64 * Constructor for the Sdevs_Wc_Subscription class
65 *
66 * Sets up all the appropriate hooks and actions
67 * within our plugin.
68 */
69 private function __construct() {
70 $this->define_constants();
71
72 register_activation_hook( __FILE__, array( $this, 'activate' ) );
73 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
74
75 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
76 }
77
78 /**
79 * Initializes the Sdevs_Wc_Subscription() class
80 *
81 * Checks for an existing Sdevs_Wc_Subscription() instance
82 * and if it doesn't find one, creates it.
83 *
84 * @return Sdevs_Subscription|bool
85 */
86 public static function init() {
87 static $instance = false;
88
89 if ( ! $instance ) {
90 $instance = new Sdevs_Subscription();
91 }
92
93 return $instance;
94 }
95
96 /**
97 * Magic getter to bypass referencing plugin.
98 *
99 * @param mixed $prop Prop.
100 *
101 * @return mixed
102 */
103 public function __get( $prop ) {
104 if ( array_key_exists( $prop, $this->container ) ) {
105 return $this->container[ $prop ];
106 }
107
108 return $this->{$prop};
109 }
110
111 /**
112 * Magic isset to bypass referencing plugin.
113 *
114 * @param mixed $prop Prop.
115 *
116 * @return bool
117 */
118 public function __isset( $prop ) {
119 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
120 }
121
122 /**
123 * Define the constants
124 *
125 * @return void
126 */
127 public function define_constants() {
128 define( 'SUBSCRPT_VERSION', self::VERSION );
129 define( 'SUBSCRPT_FILE', __FILE__ );
130 define( 'SUBSCRPT_PATH', dirname( SUBSCRPT_FILE ) );
131 define( 'SUBSCRPT_INCLUDES', SUBSCRPT_PATH . '/includes' );
132 define( 'SUBSCRPT_TEMPLATES', SUBSCRPT_PATH . '/templates/' );
133 define( 'SUBSCRPT_URL', plugins_url( '', SUBSCRPT_FILE ) );
134 define( 'SUBSCRPT_ASSETS', SUBSCRPT_URL . '/assets' );
135
136 // Load legacy constant aliases (WP_SUBSCRIPTION_* → SUBSCRPT_*) for
137 // backwards compatibility with subscription-pro and third-party code.
138 require_once SUBSCRPT_INCLUDES . '/LegacyCompat.php';
139 }
140
141 /**
142 * Load the plugin after all plugins are loaded
143 *
144 * @return void
145 */
146 public function init_plugin() {
147 $this->includes();
148 $this->init_hooks();
149 }
150
151 /**
152 * Placeholder for activation function
153 */
154 public function activate() {
155 $installer = new SpringDevs\Subscription\Installer();
156 $installer->run();
157 }
158
159 /**
160 * Placeholder for deactivation function
161 *
162 * Nothing being called here yet.
163 */
164 public function deactivate() {
165 wp_clear_scheduled_hook( 'subscrpt_hourly_cron' );
166 wp_clear_scheduled_hook( 'subscrpt_daily_cron' ); // legacy cleanup for sites migrating from old hook name
167 }
168
169 /**
170 * Include the required files
171 *
172 * @return void
173 */
174 public function includes() {
175 // Include functions file first to ensure global functions are available
176 require_once SUBSCRPT_INCLUDES . '/functions.php';
177 require_once SUBSCRPT_INCLUDES . '/Admin/AdminComponents.php';
178
179 if ( $this->is_request( 'admin' ) ) {
180 $this->container['admin'] = new SpringDevs\Subscription\Admin();
181 }
182
183 if ( $this->is_request( 'frontend' ) ) {
184 $this->container['frontend'] = new SpringDevs\Subscription\Frontend();
185 }
186
187 $this->container['illuminate'] = new SpringDevs\Subscription\Illuminate();
188 }
189
190 /**
191 * Initialize the hooks
192 *
193 * @return void
194 */
195 public function init_hooks() {
196 add_action( 'init', array( $this, 'init_classes' ) );
197 add_action( 'init', array( $this, 'localization_setup' ) );
198 add_action( 'init', array( $this, 'run_update' ) );
199
200 // HPOS Compatibility: Declare support for custom order tables
201 add_action(
202 'before_woocommerce_init',
203 function () {
204 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
205 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
206 }
207 }
208 );
209
210 // HPOS Compatibility: Register subscription post type with HPOS support
211 add_action(
212 'init',
213 function () {
214 register_post_type(
215 'subscrpt_order',
216 array(
217 'hpos' => true,
218 'public' => false,
219 'show_ui' => true,
220 'show_in_menu' => false,
221 'supports' => array( 'title' ),
222 'capability_type' => 'post',
223 'capabilities' => array(
224 'create_posts' => false,
225 ),
226 'map_meta_cap' => true,
227 )
228 );
229 },
230 0
231 );
232 }
233
234 /**
235 * Need to do some actions after update plugin
236 *
237 * @return void
238 */
239 public function run_update() {
240 $upgrade = new \SpringDevs\Subscription\Upgrade();
241 $upgrade->run();
242 }
243
244 /**
245 * Instantiate the required classes
246 *
247 * @return void
248 */
249 public function init_classes() {
250 if ( $this->is_request( 'ajax' ) ) {
251 $this->container['ajax'] = new SpringDevs\Subscription\Ajax();
252 $this->container['onboarding_ajax'] = new SpringDevs\Subscription\Admin\OnboardingAjax();
253 }
254
255 $this->container['api'] = new SpringDevs\Subscription\API();
256 $this->container['assets'] = new SpringDevs\Subscription\Assets();
257 }
258
259 /**
260 * Initialize plugin for localization
261 *
262 * Note: WordPress automatically loads translations for plugins hosted on WordPress.org
263 * since version 4.6, so manual loading is not required.
264 */
265 public function localization_setup() {
266 // WordPress auto-loads translations for plugins hosted on WordPress.org since v4.6.
267 }
268
269 /**
270 * What type of request is this?
271 *
272 * @param string $type admin, ajax, cron or frontend.
273 *
274 * @return bool
275 */
276 private function is_request( $type ) {
277 switch ( $type ) {
278 case 'admin':
279 return is_admin();
280
281 case 'ajax':
282 return defined( 'DOING_AJAX' );
283
284 case 'rest':
285 return defined( 'REST_REQUEST' );
286
287 case 'cron':
288 return defined( 'DOING_CRON' );
289
290 case 'frontend':
291 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
292 }
293 }
294 } // Sdevs_Wc_Subscription
295
296 // Add Paypal Gateway Blocks.
297 if ( ! function_exists( 'subscrpt_register_paypal_block' ) ) {
298 /**
299 * Register the PayPal block for WooCommerce Blocks.
300 */
301 function subscrpt_register_paypal_block() {
302 // Check if the required class exists.
303 if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
304 return;
305 }
306
307 // Hook the registration function to the 'woocommerce_blocks_payment_method_type_registration' action.
308 add_action(
309 'woocommerce_blocks_payment_method_type_registration',
310 function ( PaymentMethodRegistry $payment_method_registry ) {
311 $payment_method_registry->register( new Paypal_Blocks_Integration() );
312 }
313 );
314 }
315
316 // Register PayPal integration only if WordPress functions are available
317 if ( function_exists( 'get_option' ) ) {
318 // Is PayPal integration enabled?
319 $is_paypal_integration_enabled = 'on' === get_option( 'wp_subs_paypal_integration_enabled', 'off' );
320 if ( $is_paypal_integration_enabled ) {
321 add_action( 'woocommerce_blocks_loaded', 'subscrpt_register_paypal_block' );
322 }
323 }
324 }
325
326 /**
327 * Initialize the main plugin
328 *
329 * @return Sdevs_Subscription|bool
330 */
331 function sdevs_subscription() {
332 return Sdevs_Subscription::init();
333 }
334
335 /**
336 * Kick-off the plugin
337 */
338 sdevs_subscription();
339