PluginProbe
wePOS – Point Of Sale (POS) for WooCommerce & Dokan / 1.2.6
wePOS – Point Of Sale (POS) for WooCommerce & Dokan v1.2.6
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.2.6, at wepos.php

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