| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Subscription for WooCommerce |
| 4 |
Plugin URI: https://wordpress.org/plugins/subscription |
| 5 |
Description: Allow your customers to order once and get their products and services every month/week. |
| 6 |
Version: 1.3.0 |
| 7 |
Author: SpringDevs |
| 8 |
Author URI: https://springdevs.com/ |
| 9 |
Requires Plugins: woocommerce |
| 10 |
License: GPLv2 |
| 11 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
Text Domain: sdevs_subscrpt |
| 13 |
Domain Path: /languages |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* Copyright (c) 2021 SpringDevs (email: contact@springdevs.com). All rights reserved. |
| 18 |
* |
| 19 |
* Released under the GPL license |
| 20 |
* http://www.opensource.org/licenses/gpl-license.php |
| 21 |
* |
| 22 |
* This is an add-on for WordPress |
| 23 |
* http://wordpress.org/ |
| 24 |
* |
| 25 |
* ********************************************************************** |
| 26 |
* This program is free software; you can redistribute it and/or modify |
| 27 |
* it under the terms of the GNU General Public License as published by |
| 28 |
* the Free Software Foundation; either version 2 of the License, or |
| 29 |
* (at your option) any later version. |
| 30 |
* |
| 31 |
* This program is distributed in the hope that it will be useful, |
| 32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 34 |
* GNU General Public License for more details. |
| 35 |
* |
| 36 |
* You should have received a copy of the GNU General Public License |
| 37 |
* along with this program; if not, write to the Free Software |
| 38 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 39 |
* ********************************************************************** |
| 40 |
*/ |
| 41 |
|
| 42 |
// don't call the file directly. |
| 43 |
if ( ! defined( 'ABSPATH' ) ) { |
| 44 |
exit; |
| 45 |
} |
| 46 |
|
| 47 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 48 |
|
| 49 |
/** |
| 50 |
* Sdevs_Subscription class |
| 51 |
* |
| 52 |
* @class Sdevs_Subscription The class that holds the entire plugin |
| 53 |
*/ |
| 54 |
final class Sdevs_Subscription { |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* Plugin version |
| 59 |
* |
| 60 |
* @var string |
| 61 |
*/ |
| 62 |
const version = '1.3.0'; |
| 63 |
|
| 64 |
/** |
| 65 |
* Holds various class instances |
| 66 |
* |
| 67 |
* @var array |
| 68 |
*/ |
| 69 |
private array $container = array(); |
| 70 |
|
| 71 |
/** |
| 72 |
* Constructor for the Sdevs_Wc_Subscription class |
| 73 |
* |
| 74 |
* Sets up all the appropriate hooks and actions |
| 75 |
* within our plugin. |
| 76 |
*/ |
| 77 |
private function __construct() { |
| 78 |
$this->define_constants(); |
| 79 |
|
| 80 |
register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
| 81 |
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); |
| 82 |
|
| 83 |
add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Initializes the Sdevs_Wc_Subscription() class |
| 88 |
* |
| 89 |
* Checks for an existing Sdevs_Wc_Subscription() instance |
| 90 |
* and if it doesn't find one, creates it. |
| 91 |
* |
| 92 |
* @return Sdevs_Subscription|bool |
| 93 |
*/ |
| 94 |
public static function init() { |
| 95 |
static $instance = false; |
| 96 |
|
| 97 |
if ( ! $instance ) { |
| 98 |
$instance = new Sdevs_Subscription(); |
| 99 |
} |
| 100 |
|
| 101 |
return $instance; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Magic getter to bypass referencing plugin. |
| 106 |
* |
| 107 |
* @param mixed $prop Prop. |
| 108 |
* |
| 109 |
* @return mixed |
| 110 |
*/ |
| 111 |
public function __get( $prop ) { |
| 112 |
if ( array_key_exists( $prop, $this->container ) ) { |
| 113 |
return $this->container[ $prop ]; |
| 114 |
} |
| 115 |
|
| 116 |
return $this->{$prop}; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Magic isset to bypass referencing plugin. |
| 121 |
* |
| 122 |
* @param mixed $prop Prop. |
| 123 |
* |
| 124 |
* @return bool |
| 125 |
*/ |
| 126 |
public function __isset( $prop ) { |
| 127 |
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Define the constants |
| 132 |
* |
| 133 |
* @return void |
| 134 |
*/ |
| 135 |
public function define_constants() { |
| 136 |
define( 'SUBSCRPT_VERSION', self::version ); |
| 137 |
define( 'SUBSCRPT_FILE', __FILE__ ); |
| 138 |
define( 'SUBSCRPT_PATH', dirname( SUBSCRPT_FILE ) ); |
| 139 |
define( 'SUBSCRPT_INCLUDES', SUBSCRPT_PATH . '/includes' ); |
| 140 |
define( 'SUBSCRPT_TEMPLATES', SUBSCRPT_PATH . '/templates/' ); |
| 141 |
define( 'SUBSCRPT_URL', plugins_url( '', SUBSCRPT_FILE ) ); |
| 142 |
define( 'SUBSCRPT_ASSETS', SUBSCRPT_URL . '/assets' ); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Load the plugin after all plugins are loaded |
| 147 |
* |
| 148 |
* @return void |
| 149 |
*/ |
| 150 |
public function init_plugin() { |
| 151 |
$this->includes(); |
| 152 |
$this->init_hooks(); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Placeholder for activation function |
| 157 |
* |
| 158 |
* Nothing being called here yet. |
| 159 |
*/ |
| 160 |
public function activate() { |
| 161 |
$installer = new SpringDevs\Subscription\Installer(); |
| 162 |
$installer->run(); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Placeholder for deactivation function |
| 167 |
* |
| 168 |
* Nothing being called here yet. |
| 169 |
*/ |
| 170 |
public function deactivate() { |
| 171 |
wp_clear_scheduled_hook( 'subscrpt_daily_cron' ); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Include the required files |
| 176 |
* |
| 177 |
* @return void |
| 178 |
*/ |
| 179 |
public function includes() { |
| 180 |
if ( $this->is_request( 'admin' ) ) { |
| 181 |
$this->container['admin'] = new SpringDevs\Subscription\Admin(); |
| 182 |
} |
| 183 |
|
| 184 |
if ( $this->is_request( 'frontend' ) ) { |
| 185 |
$this->container['frontend'] = new SpringDevs\Subscription\Frontend(); |
| 186 |
} |
| 187 |
|
| 188 |
$this->container['illuminate'] = new SpringDevs\Subscription\Illuminate(); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Initialize the hooks |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
public function init_hooks() { |
| 197 |
add_action( 'init', array( $this, 'init_classes' ) ); |
| 198 |
add_action( 'init', array( $this, 'localization_setup' ) ); |
| 199 |
add_action( 'init', array( $this, 'run_update' ) ); |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Need to do some actions after update plugin |
| 204 |
* |
| 205 |
* @return void |
| 206 |
*/ |
| 207 |
public function run_update() { |
| 208 |
$upgrade = new \SpringDevs\Subscription\Upgrade(); |
| 209 |
$upgrade->run(); |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Instantiate the required classes |
| 214 |
* |
| 215 |
* @return void |
| 216 |
*/ |
| 217 |
public function init_classes() { |
| 218 |
if ( $this->is_request( 'ajax' ) ) { |
| 219 |
$this->container['ajax'] = new SpringDevs\Subscription\Ajax(); |
| 220 |
} |
| 221 |
|
| 222 |
$this->container['api'] = new SpringDevs\Subscription\Api(); |
| 223 |
$this->container['assets'] = new SpringDevs\Subscription\Assets(); |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* Initialize plugin for localization |
| 228 |
* |
| 229 |
* @uses load_plugin_textdomain() |
| 230 |
*/ |
| 231 |
public function localization_setup() { |
| 232 |
load_plugin_textdomain( 'sdevs_subscrpt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* What type of request is this? |
| 237 |
* |
| 238 |
* @param string $type admin, ajax, cron or frontend. |
| 239 |
* |
| 240 |
* @return bool |
| 241 |
*/ |
| 242 |
private function is_request( $type ) { |
| 243 |
switch ( $type ) { |
| 244 |
case 'admin': |
| 245 |
return is_admin(); |
| 246 |
|
| 247 |
case 'ajax': |
| 248 |
return defined( 'DOING_AJAX' ); |
| 249 |
|
| 250 |
case 'rest': |
| 251 |
return defined( 'REST_REQUEST' ); |
| 252 |
|
| 253 |
case 'cron': |
| 254 |
return defined( 'DOING_CRON' ); |
| 255 |
|
| 256 |
case 'frontend': |
| 257 |
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); |
| 258 |
} |
| 259 |
} |
| 260 |
} // Sdevs_Wc_Subscription |
| 261 |
|
| 262 |
/** |
| 263 |
* Initialize the main plugin |
| 264 |
* |
| 265 |
* @return Sdevs_Subscription|bool |
| 266 |
*/ |
| 267 |
function sdevs_subscription() { |
| 268 |
return Sdevs_Subscription::init(); |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* Kick-off the plugin |
| 273 |
*/ |
| 274 |
sdevs_subscription(); |
| 275 |
|