PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.10.5
Subscriptions for WooCommerce with Stripe Recurring Payments v1.10.5
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.5, at subscription.php

338 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: Subscription & Recurring Payment for WooCommerce
4 * Plugin URI: https://wpsubscription.co/
5 * Description: WPSubscription allow WooCommerce to enables recurring payments, subscriptions, and auto-renewals for digital and physical products. Supports Stripe, PayPal, Paddle, and more.
6 *
7 * Version: 1.10.5
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.5';
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
178 if ( $this->is_request( 'admin' ) ) {
179 $this->container['admin'] = new SpringDevs\Subscription\Admin();
180 }
181
182 if ( $this->is_request( 'frontend' ) ) {
183 $this->container['frontend'] = new SpringDevs\Subscription\Frontend();
184 }
185
186 $this->container['illuminate'] = new SpringDevs\Subscription\Illuminate();
187 }
188
189 /**
190 * Initialize the hooks
191 *
192 * @return void
193 */
194 public function init_hooks() {
195 add_action( 'init', array( $this, 'init_classes' ) );
196 add_action( 'init', array( $this, 'localization_setup' ) );
197 add_action( 'init', array( $this, 'run_update' ) );
198
199 // HPOS Compatibility: Declare support for custom order tables
200 add_action(
201 'before_woocommerce_init',
202 function () {
203 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
204 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
205 }
206 }
207 );
208
209 // HPOS Compatibility: Register subscription post type with HPOS support
210 add_action(
211 'init',
212 function () {
213 register_post_type(
214 'subscrpt_order',
215 array(
216 'hpos' => true,
217 'public' => false,
218 'show_ui' => true,
219 'show_in_menu' => false,
220 'supports' => array( 'title' ),
221 'capability_type' => 'post',
222 'capabilities' => array(
223 'create_posts' => false,
224 ),
225 'map_meta_cap' => true,
226 )
227 );
228 },
229 0
230 );
231 }
232
233 /**
234 * Need to do some actions after update plugin
235 *
236 * @return void
237 */
238 public function run_update() {
239 $upgrade = new \SpringDevs\Subscription\Upgrade();
240 $upgrade->run();
241 }
242
243 /**
244 * Instantiate the required classes
245 *
246 * @return void
247 */
248 public function init_classes() {
249 if ( $this->is_request( 'ajax' ) ) {
250 $this->container['ajax'] = new SpringDevs\Subscription\Ajax();
251 $this->container['onboarding_ajax'] = new SpringDevs\Subscription\Admin\OnboardingAjax();
252 }
253
254 $this->container['api'] = new SpringDevs\Subscription\API();
255 $this->container['assets'] = new SpringDevs\Subscription\Assets();
256 }
257
258 /**
259 * Initialize plugin for localization
260 *
261 * Note: WordPress automatically loads translations for plugins hosted on WordPress.org
262 * since version 4.6, so manual loading is not required.
263 */
264 public function localization_setup() {
265 // WordPress auto-loads translations for plugins hosted on WordPress.org since v4.6.
266 }
267
268 /**
269 * What type of request is this?
270 *
271 * @param string $type admin, ajax, cron or frontend.
272 *
273 * @return bool
274 */
275 private function is_request( $type ) {
276 switch ( $type ) {
277 case 'admin':
278 return is_admin();
279
280 case 'ajax':
281 return defined( 'DOING_AJAX' );
282
283 case 'rest':
284 return defined( 'REST_REQUEST' );
285
286 case 'cron':
287 return defined( 'DOING_CRON' );
288
289 case 'frontend':
290 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
291 }
292 }
293 } // Sdevs_Wc_Subscription
294
295 // Add Paypal Gateway Blocks.
296 if ( ! function_exists( 'subscrpt_register_paypal_block' ) ) {
297 /**
298 * Register the PayPal block for WooCommerce Blocks.
299 */
300 function subscrpt_register_paypal_block() {
301 // Check if the required class exists.
302 if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
303 return;
304 }
305
306 // Hook the registration function to the 'woocommerce_blocks_payment_method_type_registration' action.
307 add_action(
308 'woocommerce_blocks_payment_method_type_registration',
309 function ( PaymentMethodRegistry $payment_method_registry ) {
310 $payment_method_registry->register( new Paypal_Blocks_Integration() );
311 }
312 );
313 }
314
315 // Register PayPal integration only if WordPress functions are available
316 if ( function_exists( 'get_option' ) ) {
317 // Is PayPal integration enabled?
318 $is_paypal_integration_enabled = 'on' === get_option( 'wp_subs_paypal_integration_enabled', 'off' );
319 if ( $is_paypal_integration_enabled ) {
320 add_action( 'woocommerce_blocks_loaded', 'subscrpt_register_paypal_block' );
321 }
322 }
323 }
324
325 /**
326 * Initialize the main plugin
327 *
328 * @return Sdevs_Subscription|bool
329 */
330 function sdevs_subscription() {
331 return Sdevs_Subscription::init();
332 }
333
334 /**
335 * Kick-off the plugin
336 */
337 sdevs_subscription();
338