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

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