| 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.8 |
| 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: 8.9.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.8'; |
| 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 |
$this->includes(); |
| 80 |
|
| 81 |
register_activation_hook( __FILE__, [ $this, 'activate' ] ); |
| 82 |
register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] ); |
| 83 |
|
| 84 |
add_action( 'init', [ $this, 'add_rewrite_rules' ] ); |
| 85 |
add_filter( 'query_vars', [ $this, 'register_query_var' ] ); |
| 86 |
|
| 87 |
add_action( 'plugins_loaded', [ $this, 'woocommerce_not_loaded' ], 11 ); |
| 88 |
|
| 89 |
// Admin notice for WooCommerce dependency |
| 90 |
add_action( 'admin_notices', [ $this, 'render_woocommerce_dependency_notice' ] ); |
| 91 |
|
| 92 |
add_action( 'woocommerce_loaded', [ $this, 'init_plugin' ] ); |
| 93 |
add_action( 'woocommerce_init', [ $this, 'on_wc_init' ] ); |
| 94 |
|
| 95 |
|
| 96 |
// Handle Appsero tracker |
| 97 |
$this->appsero_init_tracker_wepos(); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Missing WooCommerce notice |
| 102 |
* |
| 103 |
* @since 1.1.9 |
| 104 |
* |
| 105 |
* @return void |
| 106 |
*/ |
| 107 |
public function render_woocommerce_dependency_notice() { |
| 108 |
// Check wooCommerce is available and active |
| 109 |
$has_woocommerce = $this->has_woocommerce(); |
| 110 |
|
| 111 |
if ( $has_woocommerce ) { |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
// Check if woocommerce installed |
| 116 |
$woocommerce_installed = $this->is_woocommerce_installed(); |
| 117 |
|
| 118 |
if ( current_user_can( 'activate_plugins' ) ) { |
| 119 |
require_once WEPOS_PATH . '/templates/woocommerce-dependency-notice.php'; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Handles scenarios when WooCommerce is not active |
| 125 |
* |
| 126 |
* @since 1.1.9 |
| 127 |
* |
| 128 |
* @return void |
| 129 |
*/ |
| 130 |
public function woocommerce_not_loaded() { |
| 131 |
if ( did_action( 'woocommerce_loaded' ) || ! is_admin() ) { |
| 132 |
return; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Check whether woocommerce is installed and active |
| 138 |
* |
| 139 |
* @since 1.1.9 |
| 140 |
* |
| 141 |
* @return bool |
| 142 |
*/ |
| 143 |
public function has_woocommerce() { |
| 144 |
return class_exists( 'WooCommerce' ); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Check whether woocommerce is installed |
| 149 |
* |
| 150 |
* @since 1.1.9 |
| 151 |
* |
| 152 |
* @return bool |
| 153 |
*/ |
| 154 |
public function is_woocommerce_installed() { |
| 155 |
return in_array( 'woocommerce/woocommerce.php', array_keys( get_plugins() ), true ); |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Get the template path. |
| 160 |
* |
| 161 |
* @since 1.1.9 |
| 162 |
* |
| 163 |
* @return string |
| 164 |
*/ |
| 165 |
public function template_path() { |
| 166 |
return apply_filters( 'wepos_template_path', 'wepos/' ); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Add the required rewrite rules |
| 171 |
* |
| 172 |
* @return void |
| 173 |
*/ |
| 174 |
public function add_rewrite_rules() { |
| 175 |
add_rewrite_rule( '^wepos/?$', 'index.php?wepos=true', 'top' ); |
| 176 |
|
| 177 |
if ( get_transient( 'wepos-flush-rewrites' ) ) { |
| 178 |
flush_rewrite_rules( true ); |
| 179 |
delete_transient( 'wepos-flush-rewrites' ); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Register our query vars |
| 185 |
* |
| 186 |
* @param array $vars |
| 187 |
* |
| 188 |
* @return array |
| 189 |
*/ |
| 190 |
public function register_query_var( $vars ) { |
| 191 |
$vars[] = 'wepos'; |
| 192 |
|
| 193 |
return $vars; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Initializes the WePOS() class |
| 198 |
* |
| 199 |
* Checks for an existing WePOS() instance |
| 200 |
* and if it doesn't find one, creates it. |
| 201 |
* |
| 202 |
* @return \WePOS |
| 203 |
*/ |
| 204 |
public static function init() { |
| 205 |
static $instance = false; |
| 206 |
|
| 207 |
if ( ! $instance ) { |
| 208 |
$instance = new WePOS(); |
| 209 |
} |
| 210 |
|
| 211 |
return $instance; |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Magic getter to bypass referencing plugin. |
| 216 |
* |
| 217 |
* @param $prop |
| 218 |
* |
| 219 |
* @return mixed |
| 220 |
*/ |
| 221 |
public function __get( $prop ) { |
| 222 |
if ( array_key_exists( $prop, $this->container ) ) { |
| 223 |
return $this->container[ $prop ]; |
| 224 |
} |
| 225 |
|
| 226 |
return $this->{$prop}; |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Magic isset to bypass referencing plugin. |
| 231 |
* |
| 232 |
* @param $prop |
| 233 |
* |
| 234 |
* @return mixed |
| 235 |
*/ |
| 236 |
public function __isset( $prop ) { |
| 237 |
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Define the constants |
| 242 |
* |
| 243 |
* @return void |
| 244 |
*/ |
| 245 |
public function define_constants() { |
| 246 |
define( 'WEPOS_VERSION', $this->version ); |
| 247 |
define( 'WEPOS_FILE', __FILE__ ); |
| 248 |
define( 'WEPOS_PATH', dirname( WEPOS_FILE ) ); |
| 249 |
define( 'WEPOS_INCLUDES', WEPOS_PATH . '/includes' ); |
| 250 |
define( 'WEPOS_URL', plugins_url( '', WEPOS_FILE ) ); |
| 251 |
define( 'WEPOS_ASSETS', WEPOS_URL . '/assets' ); |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* Load the plugin after all plugins are loaded |
| 256 |
* |
| 257 |
* @return void |
| 258 |
*/ |
| 259 |
public function init_plugin() { |
| 260 |
$this->init_hooks(); |
| 261 |
|
| 262 |
do_action( 'wepos_loaded' ); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* Placeholder for activation function |
| 267 |
* |
| 268 |
* Nothing being called here yet. |
| 269 |
* |
| 270 |
* @return void |
| 271 |
*/ |
| 272 |
public function activate() { |
| 273 |
$installer = new WeDevs\WePOS\Installer(); |
| 274 |
|
| 275 |
$installer->run(); |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Placeholder for deactivation function |
| 280 |
* |
| 281 |
* Nothing being called here yet. |
| 282 |
* |
| 283 |
* @return void |
| 284 |
*/ |
| 285 |
public function deactivate() { |
| 286 |
$users_query = new WP_User_Query( [ |
| 287 |
'role__in' => [ 'seller', 'vendor_staff' ] |
| 288 |
] ); |
| 289 |
$users = $users_query->get_results(); |
| 290 |
|
| 291 |
if ( count( $users ) > 0 ) { |
| 292 |
foreach ( $users as $user ) { |
| 293 |
$user->remove_cap( 'publish_shop_orders' ); |
| 294 |
$user->remove_cap( 'list_users' ); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
/** |
| 300 |
* Include the required files |
| 301 |
* |
| 302 |
* @return void |
| 303 |
*/ |
| 304 |
public function includes() { |
| 305 |
require_once WEPOS_INCLUDES . '/functions.php'; |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Initialize the hooks |
| 310 |
* |
| 311 |
* @return void |
| 312 |
*/ |
| 313 |
public function init_hooks() { |
| 314 |
add_action( 'init', [ $this, 'init_classes' ] ); |
| 315 |
add_action( 'init', [ $this, 'localization_setup' ] ); |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Instantiate the required classes |
| 320 |
* |
| 321 |
* @return void |
| 322 |
*/ |
| 323 |
public function init_classes() { |
| 324 |
if ( is_admin() ) { |
| 325 |
$this->container['admin'] = new WeDevs\WePOS\Admin\Admin(); |
| 326 |
$this->container['settings'] = new WeDevs\WePOS\Admin\Settings(); |
| 327 |
|
| 328 |
new WeDevs\WePOS\Admin\Products(); |
| 329 |
new WeDevs\WePOS\Admin\Updates(); |
| 330 |
new WeDevs\WePOS\Admin\LimitedTimePromotion(); |
| 331 |
new WeDevs\WePOS\Admin\Discounts(); |
| 332 |
} else { |
| 333 |
$this->container['frontend'] = new WeDevs\WePOS\Frontend(); |
| 334 |
} |
| 335 |
|
| 336 |
if ( class_exists( 'WeDevs_Dokan' ) ) { |
| 337 |
$this->container['dokan'] = new WeDevs\WePOS\Dokan(); |
| 338 |
} |
| 339 |
|
| 340 |
$this->container['common'] = new WeDevs\WePOS\Common(); |
| 341 |
$this->container['rest'] = new WeDevs\WePOS\REST\Manager(); |
| 342 |
$this->container['assets'] = new WeDevs\WePOS\Assets(); |
| 343 |
|
| 344 |
// Payment gateway manager |
| 345 |
$this->container['gateways'] = new \WeDevs\WePOS\Gateways\Manager(); |
| 346 |
} |
| 347 |
|
| 348 |
/** |
| 349 |
* Initialize plugin for localization |
| 350 |
* |
| 351 |
* @uses load_plugin_textdomain() |
| 352 |
*/ |
| 353 |
public function localization_setup() { |
| 354 |
load_plugin_textdomain( 'wepos', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* On WC init, include cart required files in REST request |
| 359 |
* |
| 360 |
* @since 1.0.5 |
| 361 |
* |
| 362 |
* @return void |
| 363 |
*/ |
| 364 |
public function on_wc_init() { |
| 365 |
if ( wc()->is_rest_api_request() ) { |
| 366 |
$namespace = '/wepos/v1/'; |
| 367 |
|
| 368 |
$rest_bases = [ |
| 369 |
'products', |
| 370 |
]; |
| 371 |
|
| 372 |
foreach ( $rest_bases as $rest_base ) { |
| 373 |
$endpoint = $namespace . $rest_base; |
| 374 |
|
| 375 |
if ( strpos( $_SERVER['REQUEST_URI'], $endpoint ) ) { |
| 376 |
$this->include_wc_files(); |
| 377 |
break; |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Initialize the plugin tracker |
| 385 |
* |
| 386 |
* @return void |
| 387 |
*/ |
| 388 |
public function appsero_init_tracker_wepos() { |
| 389 |
$client = new Appsero\Client( '48fa1273-3e91-4cd6-9c07-d18ad6bc2f54', 'wePos', __FILE__ ); |
| 390 |
|
| 391 |
// Active insights |
| 392 |
$client->insights() |
| 393 |
->add_extra( function () { |
| 394 |
$products = wc_get_products( [ 'fields' => 'ids', 'paginate' => true ] ); |
| 395 |
$orders = wc_get_orders( [ 'fields' => 'ids', 'paginate' => true ] ); |
| 396 |
|
| 397 |
return [ |
| 398 |
'products' => $products->total, |
| 399 |
'orders' => $orders->total |
| 400 |
]; |
| 401 |
} ) |
| 402 |
->init(); |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* Include cart required files in REST request |
| 407 |
* |
| 408 |
* @since 1.0.5 |
| 409 |
* |
| 410 |
* @return void |
| 411 |
*/ |
| 412 |
public function include_wc_files() { |
| 413 |
if ( ! wc()->cart ) { |
| 414 |
include_once WC_ABSPATH . 'includes/wc-cart-functions.php'; |
| 415 |
include_once WC_ABSPATH . 'includes/wc-notice-functions.php'; |
| 416 |
include_once WC_ABSPATH . 'includes/class-wc-cart.php'; |
| 417 |
include_once WC_ABSPATH . 'includes/class-wc-tax.php'; |
| 418 |
include_once WC_ABSPATH . 'includes/class-wc-shipping-zones.php'; |
| 419 |
include_once WC_ABSPATH . 'includes/class-wc-customer.php'; |
| 420 |
include_once WC_ABSPATH . 'includes/class-wc-session-handler.php'; |
| 421 |
|
| 422 |
// Session class, handles session data for users - can be overwritten if custom handler is needed. |
| 423 |
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); |
| 424 |
wc()->session = new $session_class(); |
| 425 |
wc()->session->init(); |
| 426 |
|
| 427 |
wc()->customer = new WC_Customer( get_current_user_id(), true ); |
| 428 |
// Cart needs the customer info. |
| 429 |
wc()->cart = new WC_Cart(); |
| 430 |
|
| 431 |
// Customer should be saved during shutdown. |
| 432 |
add_action( 'shutdown', [ wc()->customer, 'save' ], 10 ); |
| 433 |
} |
| 434 |
} |
| 435 |
} // WePOS |
| 436 |
|
| 437 |
function wepos() { |
| 438 |
return WePOS::init(); |
| 439 |
} |
| 440 |
|
| 441 |
// Kick off plugin |
| 442 |
wepos(); |
| 443 |
|