PluginProbe
wePOS – Point Of Sale (POS) for WooCommerce & Dokan / 1.3.3
wePOS – Point Of Sale (POS) for WooCommerce & Dokan v1.3.3
2.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.10 1.1.11 1.1.12 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 36 releases
wepos / wepos.php

wepos.php in wePOS – Point Of Sale (POS) for WooCommerce & Dokan 1.3.3, at wepos.php

475 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: wePOS - Point Of Sale (POS) for WooCommerce
4 Plugin URI: https://wedevs.com/wepos
5 Description: A beautiful and fast Point of Sale (POS) system for WooCommerce
6 Version: 1.3.3
7 Author: weDevs
8 Author URI: https://wedevs.com/
9 Text Domain: wepos
10 Requires Plugins: woocommerce
11 Domain Path: /languages
12 WC requires at least: 8.5.0
13 WC tested up to: 10.1.2
14 License: GPL2
15 License URI: https://www.gnu.org/licenses/gpl-2.0.html
16 */
17
18 /**
19 * Copyright (c) YEAR weDevs (email: info@wedevs.com). All rights reserved.
20 *
21 * Released under the GPL license
22 * http://www.opensource.org/licenses/gpl-license.php
23 *
24 * This is an add-on for WordPress
25 * http://wordpress.org/
26 *
27 * **********************************************************************
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version.
32 *
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41 * **********************************************************************
42 */
43
44 // don't call the file directly
45 if ( ! defined( 'ABSPATH' ) ) {
46 exit;
47 }
48
49 /**
50 * WePOS class
51 *
52 * @class WePOS The class that holds the entire WePOS plugin
53 */
54 final class WePOS {
55
56 /**
57 * Plugin version
58 *
59 * @var string
60 */
61 public $version = '1.3.3';
62
63 /**
64 * Holds various class instances
65 *
66 * @var array
67 */
68 private $container = [];
69
70 /**
71 * Constructor for the WePOS class
72 *
73 * Sets up all the appropriate hooks and actions
74 * within our plugin.
75 */
76 public function __construct() {
77 require_once __DIR__ . '/vendor/autoload.php';
78
79 $this->define_constants();
80 $this->includes();
81
82 register_activation_hook( __FILE__, [ $this, 'activate' ] );
83 register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] );
84
85 add_action( 'init', [ $this, 'add_rewrite_rules' ] );
86 add_filter( 'query_vars', [ $this, 'register_query_var' ] );
87
88 // Declaring High Performance Order Storage Support
89 add_action( 'before_woocommerce_init', [ $this, 'declare_woocommerce_feature_compatibility' ] );
90
91 add_action( 'plugins_loaded', [ $this, 'woocommerce_not_loaded' ], 11 );
92
93 // Admin notice for WooCommerce dependency
94 add_action( 'admin_notices', [ $this, 'render_woocommerce_dependency_notice' ] );
95
96 add_action( 'woocommerce_loaded', [ $this, 'init_plugin' ] );
97 add_action( 'woocommerce_init', [ $this, 'on_wc_init' ] );
98
99
100 // Handle Appsero tracker
101 $this->appsero_init_tracker_wepos();
102 }
103
104 /**
105 * Missing WooCommerce notice
106 *
107 * @since 1.1.9
108 *
109 * @return void
110 */
111 public function render_woocommerce_dependency_notice() {
112 // Check wooCommerce is available and active
113 $has_woocommerce = $this->has_woocommerce();
114
115 if ( $has_woocommerce ) {
116 return;
117 }
118
119 // Check if woocommerce installed
120 $woocommerce_installed = $this->is_woocommerce_installed();
121
122 if ( current_user_can( 'activate_plugins' ) ) {
123 require_once WEPOS_PATH . '/templates/woocommerce-dependency-notice.php';
124 }
125 }
126
127 /**
128 * Add High Performance Order Storage Support
129 *
130 * @since 1.3.1
131 * @see https://developer.woocommerce.com/docs/hpos-extension-recipe-book/
132 *
133 * @return void
134 */
135 public function declare_woocommerce_feature_compatibility() {
136 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
137 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', WEPOS_FILE, true );
138 }
139 }
140
141 /**
142 * Handles scenarios when WooCommerce is not active
143 *
144 * @since 1.1.9
145 *
146 * @return void
147 */
148 public function woocommerce_not_loaded() {
149 if ( did_action( 'woocommerce_loaded' ) || ! is_admin() ) {
150 return;
151 }
152 }
153
154 /**
155 * Check whether woocommerce is installed and active
156 *
157 * @since 1.1.9
158 *
159 * @return bool
160 */
161 public function has_woocommerce() {
162 return class_exists( 'WooCommerce' );
163 }
164
165 /**
166 * Check whether woocommerce is installed
167 *
168 * @since 1.1.9
169 *
170 * @return bool
171 */
172 public function is_woocommerce_installed() {
173 return in_array( 'woocommerce/woocommerce.php', array_keys( get_plugins() ), true );
174 }
175
176 /**
177 * Get the template path.
178 *
179 * @since 1.1.9
180 *
181 * @return string
182 */
183 public function template_path() {
184 return apply_filters( 'wepos_template_path', 'wepos/' );
185 }
186
187 /**
188 * Add the required rewrite rules
189 *
190 * @return void
191 */
192 public function add_rewrite_rules() {
193 add_rewrite_rule( '^wepos/?$', 'index.php?wepos=true', 'top' );
194
195 if ( get_transient( 'wepos-flush-rewrites' ) ) {
196 flush_rewrite_rules( true );
197 delete_transient( 'wepos-flush-rewrites' );
198 }
199 }
200
201 /**
202 * Register our query vars
203 *
204 * @param array $vars
205 *
206 * @return array
207 */
208 public function register_query_var( $vars ) {
209 $vars[] = 'wepos';
210
211 return $vars;
212 }
213
214 /**
215 * Initializes the WePOS() class
216 *
217 * Checks for an existing WePOS() instance
218 * and if it doesn't find one, creates it.
219 *
220 * @return \WePOS
221 */
222 public static function init() {
223 static $instance = false;
224
225 if ( ! $instance ) {
226 $instance = new WePOS();
227 }
228
229 return $instance;
230 }
231
232 /**
233 * Magic getter to bypass referencing plugin.
234 *
235 * @param $prop
236 *
237 * @return mixed
238 */
239 public function __get( $prop ) {
240 if ( array_key_exists( $prop, $this->container ) ) {
241 return $this->container[ $prop ];
242 }
243
244 return $this->{$prop};
245 }
246
247 /**
248 * Magic isset to bypass referencing plugin.
249 *
250 * @param $prop
251 *
252 * @return mixed
253 */
254 public function __isset( $prop ) {
255 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
256 }
257
258 /**
259 * Define the constants
260 *
261 * @return void
262 */
263 public function define_constants() {
264 define( 'WEPOS_VERSION', $this->version );
265 define( 'WEPOS_FILE', __FILE__ );
266 define( 'WEPOS_PATH', dirname( WEPOS_FILE ) );
267 define( 'WEPOS_INCLUDES', WEPOS_PATH . '/includes' );
268 define( 'WEPOS_URL', plugins_url( '', WEPOS_FILE ) );
269 define( 'WEPOS_ASSETS', WEPOS_URL . '/assets' );
270 }
271
272 /**
273 * Load the plugin after all plugins are loaded
274 *
275 * @return void
276 */
277 public function init_plugin() {
278 $this->init_hooks();
279
280 do_action( 'wepos_loaded' );
281 }
282
283 /**
284 * Placeholder for activation function
285 *
286 * Nothing being called here yet.
287 *
288 * @return void
289 */
290 public function activate() {
291 $installer = new WeDevs\WePOS\Installer();
292
293 $installer->run();
294 }
295
296 /**
297 * Placeholder for deactivation function
298 *
299 * Nothing being called here yet.
300 *
301 * @return void
302 */
303 public function deactivate() {
304 $users_query = new WP_User_Query( [
305 'role__in' => [ 'seller', 'vendor_staff' ]
306 ] );
307 $users = $users_query->get_results();
308
309 if ( count( $users ) > 0 ) {
310 foreach ( $users as $user ) {
311 $user->remove_cap( 'publish_shop_orders' );
312 $user->remove_cap( 'list_users' );
313 }
314 }
315 }
316
317 /**
318 * Include the required files
319 *
320 * @return void
321 */
322 public function includes() {
323 require_once WEPOS_INCLUDES . '/functions.php';
324 }
325
326 /**
327 * Initialize the hooks
328 *
329 * @return void
330 */
331 public function init_hooks() {
332 add_action( 'init', [ $this, 'init_classes' ] );
333 add_action( 'init', [ $this, 'localization_setup' ] );
334 add_action( 'wepos_loaded', [ $this, 'load_payment_gateways' ] );
335 }
336
337 /**
338 * Instantiate the required classes
339 *
340 * @return void
341 */
342 public function init_classes() {
343 if ( is_admin() ) {
344 $this->container['admin'] = new WeDevs\WePOS\Admin\Admin();
345 $this->container['settings'] = new WeDevs\WePOS\Admin\Settings();
346
347 new WeDevs\WePOS\Admin\Products();
348 new WeDevs\WePOS\Admin\Updates();
349 new WeDevs\WePOS\Admin\LimitedTimePromotion();
350 new WeDevs\WePOS\Admin\Discounts();
351 } else {
352 $this->container['frontend'] = new WeDevs\WePOS\Frontend();
353 }
354
355 if ( class_exists( 'WeDevs_Dokan' ) ) {
356 $this->container['dokan'] = new WeDevs\WePOS\Dokan();
357 }
358
359 $this->container['common'] = new WeDevs\WePOS\Common();
360 $this->container['rest'] = new WeDevs\WePOS\REST\Manager();
361 $this->container['assets'] = new WeDevs\WePOS\Assets();
362 }
363
364 /**
365 * Initialize plugin for localization
366 *
367 * @uses load_plugin_textdomain()
368 */
369 public function localization_setup() {
370 load_plugin_textdomain( 'wepos', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
371 }
372
373 /**
374 * Load the payment gateways.
375 *
376 * @since 1.3.1
377 *
378 * @return void
379 */
380 public function load_payment_gateways() {
381 // Payment gateway manager
382 $this->container['gateways'] = new \WeDevs\WePOS\Gateways\Manager();
383 }
384
385 /**
386 * On WC init, include cart required files in REST request
387 *
388 * @since 1.0.5
389 *
390 * @return void
391 */
392 public function on_wc_init() {
393 if ( wc()->is_rest_api_request() ) {
394 $namespace = '/wepos/v1/';
395
396 $rest_bases = [
397 'products',
398 ];
399
400 foreach ( $rest_bases as $rest_base ) {
401 $endpoint = $namespace . $rest_base;
402
403 if ( strpos( $_SERVER['REQUEST_URI'], $endpoint ) ) {
404 $this->include_wc_files();
405 break;
406 }
407 }
408 }
409 }
410
411 /**
412 * Initialize the plugin tracker
413 *
414 * @return void
415 */
416 public function appsero_init_tracker_wepos() {
417 if ( ! class_exists( 'WeDevs\WePOS\Dependencies\Appsero\Client' ) ) {
418 return;
419 }
420
421 $client = new WeDevs\WePOS\Dependencies\Appsero\Client( '48fa1273-3e91-4cd6-9c07-d18ad6bc2f54', 'wePos', __FILE__ );
422
423 // Active insights
424 $client->insights()
425 ->add_extra( function () {
426 $products = wc_get_products( [ 'fields' => 'ids', 'paginate' => true ] );
427 $orders = wc_get_orders( [ 'fields' => 'ids', 'paginate' => true ] );
428
429 return [
430 'products' => $products->total,
431 'orders' => $orders->total
432 ];
433 } )
434 ->init();
435 }
436
437 /**
438 * Include cart required files in REST request
439 *
440 * @since 1.0.5
441 *
442 * @return void
443 */
444 public function include_wc_files() {
445 if ( ! wc()->cart ) {
446 include_once WC_ABSPATH . 'includes/wc-cart-functions.php';
447 include_once WC_ABSPATH . 'includes/wc-notice-functions.php';
448 include_once WC_ABSPATH . 'includes/class-wc-cart.php';
449 include_once WC_ABSPATH . 'includes/class-wc-tax.php';
450 include_once WC_ABSPATH . 'includes/class-wc-shipping-zones.php';
451 include_once WC_ABSPATH . 'includes/class-wc-customer.php';
452 include_once WC_ABSPATH . 'includes/class-wc-session-handler.php';
453
454 // Session class, handles session data for users - can be overwritten if custom handler is needed.
455 $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
456 wc()->session = new $session_class();
457 wc()->session->init();
458
459 wc()->customer = new WC_Customer( get_current_user_id(), true );
460 // Cart needs the customer info.
461 wc()->cart = new WC_Cart();
462
463 // Customer should be saved during shutdown.
464 add_action( 'shutdown', [ wc()->customer, 'save' ], 10 );
465 }
466 }
467 } // WePOS
468
469 function wepos() {
470 return WePOS::init();
471 }
472
473 // Kick off plugin
474 wepos();
475