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

272 lines 6.0 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
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.4.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 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 require_once __DIR__ . '/vendor/autoload.php';
24
25 /**
26 * Sdevs_Subscription class
27 *
28 * @class Sdevs_Subscription The class that holds the entire plugin
29 */
30 final class Sdevs_Subscription {
31
32
33 /**
34 * Plugin version
35 *
36 * @var string
37 */
38 const version = '1.3.2';
39
40 /**
41 * Holds various class instances
42 *
43 * @var array
44 */
45 private $container = array();
46
47 /**
48 * Constructor for the Sdevs_Wc_Subscription class
49 *
50 * Sets up all the appropriate hooks and actions
51 * within our plugin.
52 */
53 private function __construct() {
54 $this->define_constants();
55
56 register_activation_hook( __FILE__, array( $this, 'activate' ) );
57 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
58
59 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
60 }
61
62 /**
63 * Initializes the Sdevs_Wc_Subscription() class
64 *
65 * Checks for an existing Sdevs_Wc_Subscription() instance
66 * and if it doesn't find one, creates it.
67 *
68 * @return Sdevs_Subscription|bool
69 */
70 public static function init() {
71 static $instance = false;
72
73 if ( ! $instance ) {
74 $instance = new Sdevs_Subscription();
75 }
76
77 return $instance;
78 }
79
80 /**
81 * Magic getter to bypass referencing plugin.
82 *
83 * @param mixed $prop Prop.
84 *
85 * @return mixed
86 */
87 public function __get( $prop ) {
88 if ( array_key_exists( $prop, $this->container ) ) {
89 return $this->container[ $prop ];
90 }
91
92 return $this->{$prop};
93 }
94
95 /**
96 * Magic isset to bypass referencing plugin.
97 *
98 * @param mixed $prop Prop.
99 *
100 * @return bool
101 */
102 public function __isset( $prop ) {
103 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
104 }
105
106 /**
107 * Define the constants
108 *
109 * @return void
110 */
111 public function define_constants() {
112 define( 'WP_SUBSCRIPTION_VERSION', self::version );
113 define( 'WP_SUBSCRIPTION_FILE', __FILE__ );
114 define( 'WP_SUBSCRIPTION_PATH', dirname( WP_SUBSCRIPTION_FILE ) );
115 define( 'WP_SUBSCRIPTION_INCLUDES', WP_SUBSCRIPTION_PATH . '/includes' );
116 define( 'WP_SUBSCRIPTION_TEMPLATES', WP_SUBSCRIPTION_PATH . '/templates/' );
117 define( 'WP_SUBSCRIPTION_URL', plugins_url( '', WP_SUBSCRIPTION_FILE ) );
118 define( 'WP_SUBSCRIPTION_ASSETS', WP_SUBSCRIPTION_URL . '/assets' );
119 }
120
121 /**
122 * Load the plugin after all plugins are loaded
123 *
124 * @return void
125 */
126 public function init_plugin() {
127 $this->includes();
128 $this->init_hooks();
129 }
130
131 /**
132 * Placeholder for activation function
133 */
134 public function activate() {
135 $installer = new SpringDevs\Subscription\Installer();
136 $installer->run();
137 }
138
139 /**
140 * Placeholder for deactivation function
141 *
142 * Nothing being called here yet.
143 */
144 public function deactivate() {
145 wp_clear_scheduled_hook( 'subscrpt_daily_cron' );
146 }
147
148 /**
149 * Include the required files
150 *
151 * @return void
152 */
153 public function includes() {
154 if ( $this->is_request( 'admin' ) ) {
155 $this->container['admin'] = new SpringDevs\Subscription\Admin();
156 }
157
158 if ( $this->is_request( 'frontend' ) ) {
159 $this->container['frontend'] = new SpringDevs\Subscription\Frontend();
160 }
161
162 $this->container['illuminate'] = new SpringDevs\Subscription\Illuminate();
163 }
164
165 /**
166 * Initialize the hooks
167 *
168 * @return void
169 */
170 public function init_hooks() {
171 add_action( 'init', array( $this, 'init_classes' ) );
172 add_action( 'init', array( $this, 'localization_setup' ) );
173 add_action( 'init', array( $this, 'run_update' ) );
174
175 // HPOS Compatibility: Declare support for custom order tables
176 add_action('before_woocommerce_init', function() {
177 if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
178 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
179 }
180 });
181
182 // HPOS Compatibility: Register subscription post type with HPOS support
183 add_action('init', function() {
184 register_post_type('subscrpt_order', array(
185 'hpos' => true,
186 'public' => false,
187 'show_ui' => true,
188 'show_in_menu' => false,
189 'supports' => array('title'),
190 'capability_type' => 'post',
191 'capabilities' => array(
192 'create_posts' => false,
193 ),
194 'map_meta_cap' => true,
195 ));
196 }, 0);
197 }
198
199 /**
200 * Need to do some actions after update plugin
201 *
202 * @return void
203 */
204 public function run_update() {
205 $upgrade = new \SpringDevs\Subscription\Upgrade();
206 $upgrade->run();
207 }
208
209 /**
210 * Instantiate the required classes
211 *
212 * @return void
213 */
214 public function init_classes() {
215 if ( $this->is_request( 'ajax' ) ) {
216 $this->container['ajax'] = new SpringDevs\Subscription\Ajax();
217 }
218
219 $this->container['api'] = new SpringDevs\Subscription\Api();
220 $this->container['assets'] = new SpringDevs\Subscription\Assets();
221 }
222
223 /**
224 * Initialize plugin for localization
225 *
226 * @uses load_plugin_textdomain()
227 */
228 public function localization_setup() {
229 load_plugin_textdomain( 'wp_subscription', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
230 }
231
232 /**
233 * What type of request is this?
234 *
235 * @param string $type admin, ajax, cron or frontend.
236 *
237 * @return bool
238 */
239 private function is_request( $type ) {
240 switch ( $type ) {
241 case 'admin':
242 return is_admin();
243
244 case 'ajax':
245 return defined( 'DOING_AJAX' );
246
247 case 'rest':
248 return defined( 'REST_REQUEST' );
249
250 case 'cron':
251 return defined( 'DOING_CRON' );
252
253 case 'frontend':
254 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
255 }
256 }
257 } // Sdevs_Wc_Subscription
258
259 /**
260 * Initialize the main plugin
261 *
262 * @return Sdevs_Subscription|bool
263 */
264 function sdevs_subscription() {
265 return Sdevs_Subscription::init();
266 }
267
268 /**
269 * Kick-off the plugin
270 */
271 sdevs_subscription();
272