· 6 years ago · Feb 13, 2020, 02:16 AM
1<?php
2/**
3* Plugin Name: WooCommerce Product Bundles
4* Plugin URI: https://woocommerce.com/products/product-bundles/
5* Description: Offer product bundles and assembled products in your WooCommerce store.
6* Version: 5.12.0
7* Author: SomewhereWarm
8* Author URI: https://somewherewarm.gr/
9*
10* Woo: 18716:fbca839929aaddc78797a5b511c14da9
11*
12* Text Domain: woocommerce-product-bundles
13* Domain Path: /languages/
14*
15* Requires PHP: 5.6
16*
17* Requires at least: 4.4
18* Tested up to: 5.2
19*
20* WC requires at least: 3.1
21* WC tested up to: 3.7
22*
23* Copyright: © 2017-2019 SomewhereWarm SMPC.
24* License: GNU General Public License v3.0
25* License URI: http://www.gnu.org/licenses/gpl-3.0.html
26*/
27
28// Exit if accessed directly.
29if ( ! defined( 'ABSPATH' ) ) {
30 exit;
31}
32
33/**
34 * Main plugin class.
35 *
36 * @class WC_Bundles
37 * @version 5.12.0
38 */
39class WC_Bundles {
40
41 public $version = '5.12.0';
42 public $required = '3.1.0';
43
44 /**
45 * The single instance of the class.
46 * @var WC_Bundles
47 *
48 * @since 4.11.4
49 */
50 protected static $_instance = null;
51
52 /**
53 * Main WC_Bundles instance. Ensures only one instance of WC_Bundles is loaded or can be loaded - @see 'WC_PB()'.
54 *
55 * @static
56 * @return WC_Bundles
57 * @since 4.11.4
58 */
59 public static function instance() {
60 if ( is_null( self::$_instance ) ) {
61 self::$_instance = new self();
62 }
63 return self::$_instance;
64 }
65
66 /**
67 * Cloning is forbidden.
68 *
69 * @since 4.11.4
70 */
71 public function __clone() {
72 _doing_it_wrong( __FUNCTION__, __( 'Foul!', 'woocommerce-product-bundles' ), '4.11.4' );
73 }
74
75 /**
76 * Unserializing instances of this class is forbidden.
77 *
78 * @since 4.11.4
79 */
80 public function __wakeup() {
81 _doing_it_wrong( __FUNCTION__, __( 'Foul!', 'woocommerce-product-bundles' ), '4.11.4' );
82 }
83
84 /**
85 * Make stuff.
86 */
87 protected function __construct() {
88 // Entry point.
89 add_action( 'plugins_loaded', array( $this, 'initialize_plugin' ), 9 );
90 }
91
92 /**
93 * Auto-load in-accessible properties.
94 *
95 * @param mixed $key
96 * @return mixed
97 */
98 public function __get( $key ) {
99 if ( in_array( $key, array( 'compatibility', 'modules', 'cart', 'order', 'display' ) ) ) {
100 $classname = 'WC_PB_' . ucfirst( $key );
101 return call_user_func( array( $classname, 'instance' ) );
102 }
103 }
104
105 /**
106 * Plugin URL getter.
107 *
108 * @return string
109 */
110 public function plugin_url() {
111 return untrailingslashit( plugins_url( '/', __FILE__ ) );
112 }
113
114 /**
115 * Plugin path getter.
116 *
117 * @return string
118 */
119 public function plugin_path() {
120 return untrailingslashit( plugin_dir_path( __FILE__ ) );
121 }
122
123 /**
124 * Plugin base path name getter.
125 *
126 * @return string
127 */
128 public function plugin_basename() {
129 return plugin_basename( __FILE__ );
130 }
131
132 /**
133 * Plugin version getter.
134 *
135 * @since 5.8.0
136 *
137 * @param boolean $base
138 * @param string $version
139 * @return string
140 */
141 public function plugin_version( $base = false, $version = '' ) {
142
143 $version = $version ? $version : $this->version;
144
145 if ( $base ) {
146 $version_parts = explode( '-', $version );
147 $version = sizeof( $version_parts ) === 2 ? $version_parts[ 0 ] : $version;
148 }
149
150 return $version;
151 }
152
153 /**
154 * Fire in the hole!
155 */
156 public function initialize_plugin() {
157
158 // WC version sanity check.
159 if ( ! function_exists( 'WC' ) || version_compare( WC()->version, $this->required ) < 0 ) {
160 $notice = sprintf( __( 'WooCommerce Product Bundles requires at least WooCommerce <strong>%s</strong>.', 'woocommerce-product-bundles' ), $this->required );
161 require_once( 'includes/admin/class-wc-pb-admin-notices.php' );
162 WC_PB_Admin_Notices::add_notice( $notice, 'error' );
163 return false;
164 }
165
166 // PHP version check.
167 if ( ! function_exists( 'phpversion' ) || version_compare( phpversion(), '5.6.20', '<' ) ) {
168 $notice = sprintf( __( 'WooCommerce Product Bundles requires at least PHP <strong>%1$s</strong>. Learn <a href="%2$s">how to update PHP</a>.', 'woocommerce-product-bundles' ), '5.6.20', 'https://docs.woocommerce.com/document/how-to-update-your-php-version/' );
169 require_once( 'includes/admin/class-wc-pb-admin-notices.php' );
170 WC_PB_Admin_Notices::add_notice( $notice, 'error' );
171 return false;
172 }
173
174 $this->define_constants();
175 $this->includes();
176
177 WC_PB_Compatibility::instance();
178 WC_PB_Modules::instance();
179
180 WC_PB_Cart::instance();
181 $this->modules->load_components( 'cart' );
182
183 WC_PB_Order::instance();
184 $this->modules->load_components( 'order' );
185
186 WC_PB_Display::instance();
187 $this->modules->load_components( 'display' );
188
189 // Load translations hook.
190 add_action( 'init', array( $this, 'load_translation' ) );
191 }
192
193 /**
194 * Constants.
195 */
196 public function define_constants() {
197
198 wc_maybe_define_constant( 'WC_PB_SUPPORT_URL', 'https://woocommerce.com/my-account/marketplace-ticket-form/' );
199 wc_maybe_define_constant( 'WC_PB_ABSPATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
200
201 if ( 'yes' === get_option( 'woocommerce_product_bundles_debug_stock_sync', null ) || 'yes' === get_option( 'woocommerce_product_bundles_debug_stock_cache', null ) || defined( 'WC_PB_DEBUG_STOCK_CACHE' ) ) {
202 /**
203 * 'WC_PB_DEBUG_STOCK_SYNC' constant.
204 *
205 * Used to disable bundled product stock meta syncing for bundled items.
206 */
207 wc_maybe_define_constant( 'WC_PB_DEBUG_STOCK_SYNC', true );
208 }
209
210 if ( 'yes' === get_option( 'woocommerce_product_bundles_debug_stock_parent_sync', null ) || defined( 'WC_PB_DEBUG_STOCK_SYNC' ) ) {
211 /**
212 * 'WC_PB_DEBUG_STOCK_PARENT_SYNC' constant.
213 *
214 * Used to disable stock status and visibility syncing for bundles.
215 */
216 wc_maybe_define_constant( 'WC_PB_DEBUG_STOCK_PARENT_SYNC', true );
217 }
218
219 if ( 'yes' === get_option( 'woocommerce_product_bundles_debug_transients', null ) ) {
220 /**
221 * 'WC_PB_DEBUG_TRANSIENTS' constant.
222 *
223 * Used to disable transients caching at plugin level.
224 */
225 wc_maybe_define_constant( 'WC_PB_DEBUG_TRANSIENTS', true );
226 }
227
228 if ( 'yes' === get_option( 'woocommerce_product_bundles_debug_object_cache', null ) ) {
229 /**
230 * 'WC_PB_DEBUG_OBJECT_CACHE' constant.
231 *
232 * Used to disable object caching at plugin level.
233 */
234 wc_maybe_define_constant( 'WC_PB_DEBUG_OBJECT_CACHE', true );
235 }
236
237 if ( 'yes' === get_option( 'woocommerce_product_bundles_debug_runtime_cache', null ) ) {
238 /**
239 * 'WC_PB_DEBUG_RUNTIME_CACHE' constant.
240 *
241 * Used to disable runtime object caching at plugin level.
242 */
243 wc_maybe_define_constant( 'WC_PB_DEBUG_RUNTIME_CACHE', true );
244 }
245 }
246
247 /**
248 * Includes.
249 */
250 public function includes() {
251
252 // Extensions compatibility functions and hooks.
253 require_once( 'includes/compatibility/class-wc-pb-compatibility.php' );
254
255 // Modules.
256 require_once( 'includes/modules/class-wc-pb-modules.php' );
257
258 // Data classes.
259 require_once( 'includes/data/class-wc-pb-data.php' );
260
261 // Install.
262 require_once( 'includes/class-wc-pb-install.php' );
263
264 // Functions (incl deprecated).
265 require_once( 'includes/wc-pb-functions.php' );
266 require_once( 'includes/wc-pb-deprecated-functions.php' );
267
268 // Helper functions and hooks.
269 require_once( 'includes/class-wc-pb-helpers.php' );
270
271 // Data syncing between products and bundled items.
272 require_once( 'includes/class-wc-pb-db-sync.php' );
273
274 // Product price filters and price-related functions.
275 require_once( 'includes/class-wc-pb-product-prices.php' );
276
277 // Bundled Item class.
278 require_once( 'includes/class-wc-bundled-item.php' );
279
280 // Product Bundle class.
281 require_once( 'includes/class-wc-product-bundle.php' );
282
283 // Stock mgr class.
284 require_once( 'includes/class-wc-pb-stock-manager.php' );
285
286 // Cart-related functions and hooks.
287 require_once( 'includes/class-wc-pb-cart.php' );
288
289 // Order-related functions and hooks.
290 require_once( 'includes/class-wc-pb-order.php' );
291
292 // Order-again functions and hooks.
293 require_once( 'includes/class-wc-pb-order-again.php' );
294
295 // Coupon-related functions and hooks.
296 require_once( 'includes/class-wc-pb-coupon.php' );
297
298 // Front-end filters and templates.
299 require_once( 'includes/class-wc-pb-display.php' );
300
301 // Front-end AJAX handlers.
302 require_once( 'includes/class-wc-pb-ajax.php' );
303
304 // REST API hooks.
305 require_once( 'includes/class-wc-pb-rest-api.php' );
306
307 // Admin includes.
308 if ( is_admin() ) {
309 $this->admin_includes();
310 }
311
312 // WP-CLI includes.
313 if ( defined( 'WP_CLI' ) && WP_CLI ) {
314 require_once( 'includes/class-wc-pb-cli.php' );
315 }
316 }
317
318 /**
319 * Admin & AJAX functions and hooks.
320 */
321 public function admin_includes() {
322
323 // Admin notices handling.
324 require_once( 'includes/admin/class-wc-pb-admin-notices.php' );
325
326 // Admin functions and hooks.
327 require_once( 'includes/admin/class-wc-pb-admin.php' );
328 }
329
330 /**
331 * Load textdomain.
332 */
333 public function load_translation() {
334 load_plugin_textdomain( 'woocommerce-product-bundles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
335 }
336
337 /*
338 |--------------------------------------------------------------------------
339 | Deprecated methods.
340 |--------------------------------------------------------------------------
341 */
342
343 public function woo_bundles_plugin_url() {
344 _deprecated_function( __METHOD__ . '()', '5.0.0', __CLASS__ . '::plugin_url()' );
345 return $this->plugin_url();
346 }
347 public function woo_bundles_plugin_path() {
348 _deprecated_function( __METHOD__ . '()', '5.0.0', __CLASS__ . '::plugin_path()' );
349 return $this->plugin_path();
350 }
351}
352
353/**
354 * Returns the main instance of WC_Bundles to prevent the need to use globals.
355 *
356 * @since 4.11.4
357 * @return WC_Bundles
358 */
359function WC_PB() {
360 return WC_Bundles::instance();
361}
362
363$GLOBALS[ 'woocommerce_bundles' ] = WC_PB();