PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.0.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.0.0
2.0.0 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 All 61 releases
subscription / subscription.php

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

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