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