PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.4
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.4
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / woocommerce-pos.php

woocommerce-pos.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.4, at woocommerce-pos.php

206 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WCPOS – Point of Sale for WooCommerce
4 * Plugin URI: https://wordpress.org/plugins/woocommerce-pos/
5 * Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires <a href="http://wordpress.org/plugins/woocommerce/">WooCommerce</a>.
6 * Version: 1.10.4
7 * Author: kilbot
8 * Author URI: http://wcpos.com
9 * Text Domain: woocommerce-pos
10 * License: GPL-3.0+
11 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
12 * Domain Path: /languages
13 * Requires at least: 5.6
14 * Tested up to: 7.1
15 * Requires PHP: 7.4
16 * Requires Plugins: woocommerce
17 * WC tested up to: 11.0.1
18 * WC requires at least: 5.3
19 *
20 * @see http://wcpos.com
21 * @package WCPOS\WooCommercePOS
22 */
23
24 namespace WCPOS\WooCommercePOS;
25
26 // Define plugin constants (use define() with checks to avoid conflicts when Pro plugin is active).
27 if ( ! \defined( __NAMESPACE__ . '\VERSION' ) ) {
28 \define( __NAMESPACE__ . '\VERSION', '1.10.4' );
29 }
30 require_once __DIR__ . '/includes/API/V2/Ping.php';
31 API\V2\Ping::maybe_serve();
32
33 if ( ! \defined( __NAMESPACE__ . '\TRANSLATION_VERSION' ) ) {
34 \define( __NAMESPACE__ . '\TRANSLATION_VERSION', '2026.8.14' );
35 }
36 if ( ! \defined( __NAMESPACE__ . '\PLUGIN_NAME' ) ) {
37 \define( __NAMESPACE__ . '\PLUGIN_NAME', 'woocommerce-pos' );
38 }
39 if ( ! \defined( __NAMESPACE__ . '\SHORT_NAME' ) ) {
40 \define( __NAMESPACE__ . '\SHORT_NAME', 'wcpos' );
41 }
42 if ( ! \defined( __NAMESPACE__ . '\PLUGIN_FILE' ) ) {
43 \define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'
44 }
45 if ( ! \defined( __NAMESPACE__ . '\PLUGIN_PATH' ) ) {
46 \define( __NAMESPACE__ . '\PLUGIN_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
47 }
48 if ( ! \defined( __NAMESPACE__ . '\PLUGIN_URL' ) ) {
49 \define( __NAMESPACE__ . '\PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
50 }
51
52 // Minimum requirements.
53 if ( ! \defined( __NAMESPACE__ . '\WC_MIN_VERSION' ) ) {
54 \define( __NAMESPACE__ . '\WC_MIN_VERSION', '5.3' );
55 }
56 if ( ! \defined( __NAMESPACE__ . '\PHP_MIN_VERSION' ) ) {
57 \define( __NAMESPACE__ . '\PHP_MIN_VERSION', '7.4' );
58 }
59 if ( ! \defined( __NAMESPACE__ . '\MIN_PRO_VERSION' ) ) {
60 \define( __NAMESPACE__ . '\MIN_PRO_VERSION', '1.8.7' );
61 }
62
63 // If Pro plugin is active, bail out early to avoid conflicts.
64 // Pro includes all free plugin functionality, so there's no need to initialize both.
65 // We check the option directly since Pro may not have loaded yet (alphabetical order).
66 $wcpos_pro_plugin_file = 'woocommerce-pos-pro/woocommerce-pos-pro.php'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- namespaced file scope.
67 $wcpos_active_plugins = get_option( 'active_plugins', array() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- namespaced file scope.
68 $wcpos_pro_is_active = \in_array( $wcpos_pro_plugin_file, $wcpos_active_plugins, true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- namespaced file scope.
69
70 // Also check network-activated plugins on multisite.
71 if ( ! $wcpos_pro_is_active && is_multisite() ) {
72 $wcpos_network_plugins = get_site_option( 'active_sitewide_plugins', array() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- namespaced file scope.
73 $wcpos_pro_is_active = isset( $wcpos_network_plugins[ $wcpos_pro_plugin_file ] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- namespaced file scope.
74 }
75
76 if ( $wcpos_pro_is_active ) {
77 return;
78 }
79
80 /**
81 * Load .env flags for development.
82 *
83 * @param string $file The path to the .env file.
84 */
85 function wcpos_load_env( $file ): void { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- namespaced.
86 if ( ! file_exists( $file ) ) {
87 return;
88 }
89
90 $lines = file( $file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
91 foreach ( $lines as $line ) {
92 if ( 0 === strpos( trim( $line ), '#' ) ) {
93 continue;
94 }
95
96 list($name, $value) = explode( '=', $line, 2 );
97 $name = trim( $name );
98 $value = trim( $value );
99
100 if ( ! \array_key_exists( $name, $_SERVER ) && ! \array_key_exists( $name, $_ENV ) ) {
101 putenv( \sprintf( '%s=%s', $name, $value ) );
102 $_ENV[ $name ] = $value;
103 }
104 }
105 }
106
107 /**
108 * Autoload vendor and prefixed libraries.
109 */
110 function wcpos_load_autoloaders(): void { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- namespaced.
111 $vendor_autoload = __DIR__ . '/vendor/autoload.php';
112 $vendor_prefixed_autoload = __DIR__ . '/vendor_prefixed/autoload.php';
113
114 if ( file_exists( $vendor_autoload ) ) {
115 require_once $vendor_autoload;
116 }
117 if ( file_exists( $vendor_prefixed_autoload ) ) {
118 require_once $vendor_prefixed_autoload;
119 require_once __DIR__ . '/includes/Vendor_Prefixed_Polyfills.php';
120 }
121 }
122
123 wcpos_load_autoloaders();
124 require_once __DIR__ . '/includes/API/class-aliases.php';
125
126 if ( \defined( 'WP_CLI' ) && WP_CLI ) {
127 if ( ! class_exists( \WCPOS\WooCommercePOS\Services\Anon_ID::class ) ) {
128 require_once __DIR__ . '/includes/Services/Anon_ID.php';
129 }
130 if ( ! class_exists( \WCPOS\WooCommercePOS\CLI\Anon_ID_Command::class ) ) {
131 require_once __DIR__ . '/includes/CLI/Anon_ID_Command.php';
132 }
133
134 \WP_CLI::add_command( 'wcpos anon-id', \WCPOS\WooCommercePOS\CLI\Anon_ID_Command::class );
135 }
136
137 // Environment variables.
138 wcpos_load_env( __DIR__ . '/.env' );
139
140 // Error handling for autoload failure.
141 if ( ! class_exists( Activator::class ) || ! class_exists( Deactivator::class ) ) {
142 add_action(
143 'admin_notices',
144 function (): void {
145 ?>
146 <div class="notice notice-error">
147 <p><?php esc_html_e( 'The WCPOS plugin failed to load correctly.', 'woocommerce-pos' ); ?></p>
148 </div>
149 <?php
150 }
151 );
152
153 return; // Exit early if classes are not found.
154 }
155
156 // Activate plugin.
157 new Activator();
158
159 // Deactivate plugin.
160 new Deactivator();
161
162 // Declare WooCommerce feature compatibility.
163 add_action(
164 'before_woocommerce_init',
165 function (): void {
166 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
167 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
168 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'product_instance_caching', __FILE__, true );
169 }
170 }
171 );
172
173 // Caching can cause all sorts of issues with the POS, so we attempt to disable caching for POS templates.
174 add_action(
175 'plugins_loaded',
176 function (): void {
177 // Check request URI as early as possible.
178 if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
179 return;
180 }
181
182 if ( preg_match( '#^/(wcpos-login|wcpos-checkout)(/|$)#i', sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ) {
183 // 1) Hard kill all LSCache features (cache + optimisation).
184 if ( ! \defined( 'LITESPEED_DISABLE_ALL' ) ) {
185 \define( 'LITESPEED_DISABLE_ALL', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- third-party constant.
186 }
187
188 // 2) Belt-and-braces: mark the response non-cacheable for older LSCache versions.
189 if ( ! \defined( 'LSCACHE_NO_CACHE' ) ) {
190 \define( 'LSCACHE_NO_CACHE', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- third-party constant.
191 }
192
193 // 3) Disable W3 Total Cache minify
194 if ( ! \defined( 'DONOTMINIFY' ) ) {
195 \define( 'DONOTMINIFY', 'true' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- third-party constant.
196 }
197
198 // 4) Disable WP Super Cache
199 if ( ! \defined( 'DONOTCACHEPAGE' ) ) {
200 \define( 'DONOTCACHEPAGE', 'true' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- third-party constant.
201 }
202 }
203 },
204 0
205 );
206