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