PluginProbe
Orderable – Restaurant & Food Ordering System / 1.20.1
Orderable – Restaurant & Food Ordering System v1.20.1
0.1.4 0.1.5 0.2.0 1.0.0 1.1.0 1.1.1 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.19.1 1.19.2 1.2.0 1.20.0 1.20.1 All 44 releases
orderable / orderable.php

orderable.php in Orderable – Restaurant & Food Ordering System 1.20.1, at orderable.php

267 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Orderable - Local Ordering System
4 * Author URI: https://orderable.com
5 * Description: Take local online ordering to a whole new level with Orderable.
6 * Version: 1.20.1
7 * Author: Orderable
8 * Text Domain: orderable
9 * WC requires at least: 5.4.0
10 * WC tested up to: 10.5.2
11 * Requires PHP: 7.4
12 */
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Orderable main class.
18 */
19 class Orderable {
20 /**
21 * @var string Plugin version.
22 */
23 public static $version = '1.20.1';
24
25 /**
26 * @var string Required pro version.
27 */
28 public static $required_pro_version = '1.17.0';
29
30 /**
31 * Construct the plugin.
32 */
33 public function __construct() {
34 $this->define_constants();
35
36 add_action( 'init', array( $this, 'load_textdomain' ), 0 );
37 add_action( 'plugins_loaded', array( $this, 'run' ), 20 );
38
39 // Redirect to settings page on activate.
40 add_action( 'activated_plugin', array( $this, 'activate' ), 20 );
41
42 // Declare compatibility with High-Performance Order Storage (HPOS).
43 add_action(
44 'before_woocommerce_init',
45 function() {
46 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
47 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
48 }
49 }
50 );
51
52 add_action( 'woocommerce_blocks_loaded', array( $this, 'load_woocommerce_blocks' ) );
53 }
54
55 /**
56 * Load Textdomain.
57 */
58 public function load_textdomain() {
59 load_plugin_textdomain( 'orderable', false, ORDERABLE_LANGUAGES_PATH );
60 }
61
62 /**
63 * Run.
64 */
65 public function run() {
66 if ( ! self::is_woo_active() ) {
67 add_action( 'admin_notices', array( __CLASS__, 'orderable_notice_woocommerce' ) );
68
69 // If Woo is not active, don't run Orderable.
70 return;
71 }
72
73 $this->load_classes();
74 $this->update_check();
75 Orderable_Database::run();
76
77 if ( ! $this->validate_pro_version() ) {
78 add_action( 'admin_notices', array( __CLASS__, 'orderable_notice_pro_version' ) );
79
80 $this->define( 'ORDERABLE_PRO_INVALID', true );
81 }
82
83 do_action( 'orderable_init' );
84 }
85
86 /**
87 * Run when plugin activated.
88 *
89 * @param $plugin
90 *
91 * @return void
92 */
93 public function activate( $plugin ) {
94 if ( ! self::is_woo_active() ) {
95 return;
96 }
97
98 $checked = isset( $_REQUEST['checked'] ) ? $_REQUEST['checked'] : array();
99
100 // Ensure we are not doing a bulk activation.
101 if ( is_array( $checked ) && count( $checked ) > 1 ) {
102 return;
103 }
104
105 if ( ORDERABLE_BASENAME !== $plugin ) {
106 return;
107 }
108
109 wp_redirect( admin_url( 'admin.php?page=orderable-settings' ) );
110 exit;
111 }
112
113 /**
114 * Run script sif plugin version has changed.
115 */
116 private function update_check() {
117 if ( ORDERABLE_VERSION === get_site_option( 'orderable_version' ) ) {
118 return;
119 }
120
121 Orderable_Helpers::delete_orderable_transients();
122 update_option( 'orderable_version', ORDERABLE_VERSION );
123 }
124
125 /**
126 * Activate WooCommerce notice.
127 */
128 public static function orderable_notice_woocommerce() {
129 ?>
130 <div class="notice notice-error">
131 <p>
132 <?php _e( 'Orderable requires WooCommerce to be installed and activated.', 'orderable' ); ?>
133 </p>
134 </div>
135 <?php
136 }
137
138 /**
139 * Get Orderable pro version notice.
140 */
141 public static function orderable_notice_pro_version() {
142 ?>
143 <div class="notice notice-error">
144 <p>
145 <?php printf( __( 'Orderable Pro needs to be at least v%s for compatibility. Please update the Orderable Pro plugin.', 'orderable' ), self::$required_pro_version ); ?>
146 <a href="<?php echo esc_url( admin_url( 'update-core.php' ) ); ?>"><?php _e( 'Update now', 'orderable' ); ?></a>.
147 </p>
148 </div>
149 <?php
150 }
151
152 /**
153 * Define Constants.
154 */
155 private function define_constants() {
156 $this->define( 'ORDERABLE_PATH', plugin_dir_path( __FILE__ ) );
157 $this->define( 'ORDERABLE_URL', plugin_dir_url( __FILE__ ) );
158 $this->define( 'ORDERABLE_ASSETS_URL', ORDERABLE_URL . 'assets/' );
159 $this->define( 'ORDERABLE_INC_PATH', ORDERABLE_PATH . 'inc/' );
160 $this->define( 'ORDERABLE_MODULES_PATH', ORDERABLE_INC_PATH . 'modules/' );
161 $this->define( 'ORDERABLE_VENDOR_PATH', ORDERABLE_INC_PATH . 'vendor/' );
162 $this->define( 'ORDERABLE_TEMPLATES_PATH', ORDERABLE_PATH . 'templates/' );
163 $this->define( 'ORDERABLE_TPL_PATH', ORDERABLE_PATH . 'templates/' );
164 $this->define( 'ORDERABLE_BASENAME', plugin_basename( __FILE__ ) );
165 $this->define( 'ORDERABLE_LANGUAGES_PATH', dirname( ORDERABLE_BASENAME ) . '/languages/' );
166 $this->define( 'ORDERABLE_VERSION', self::$version );
167 $this->define( 'ORDERABLE_CACHE_EXPIRATION_TIME', 5 * MINUTE_IN_SECONDS );
168 }
169
170 /**
171 * Define constant if not already set.
172 *
173 * @param string $name
174 * @param string|bool $value
175 */
176 private function define( $name, $value ) {
177 if ( ! defined( $name ) ) {
178 define( $name, $value );
179 }
180 }
181
182 /**
183 * Load classes.
184 */
185 private function load_classes() {
186 require_once ORDERABLE_INC_PATH . 'database/class-database.php';
187 require_once ORDERABLE_INC_PATH . 'class-helpers.php';
188 require_once ORDERABLE_INC_PATH . 'class-settings.php';
189 require_once ORDERABLE_INC_PATH . 'class-modules.php';
190 require_once ORDERABLE_INC_PATH . 'class-assets.php';
191 require_once ORDERABLE_INC_PATH . 'class-products.php';
192 require_once ORDERABLE_INC_PATH . 'class-ajax.php';
193 require_once ORDERABLE_INC_PATH . 'class-orders.php';
194 require_once ORDERABLE_INC_PATH . 'class-admin-notices.php';
195 require_once ORDERABLE_INC_PATH . 'class-webhooks.php';
196 require_once ORDERABLE_INC_PATH . 'class-shortcodes.php';
197 require_once ORDERABLE_INC_PATH . 'class-ask-review.php';
198 require_once ORDERABLE_INC_PATH . 'class-integrations.php';
199 require_once ORDERABLE_INC_PATH . 'class-compat-flux-checkout.php';
200
201 Orderable_Settings::run();
202 Orderable_Assets::run();
203 Orderable_Modules::run();
204 Orderable_Products::run();
205 Orderable_Ajax::run();
206 Orderable_Shortcodes::run();
207 Orderable_Ask_Review::run();
208 Orderable_Integrations::run();
209 Orderable_Compat_Flux_Checkout::run();
210 }
211
212 /**
213 * Validate the Orderable core version number.
214 *
215 * @return bool
216 */
217 private static function validate_pro_version() {
218 if ( ! defined( 'ORDERABLE_PRO_VERSION' ) ) {
219 // Pro version is valid because it doesn't exist.
220 return true;
221 }
222
223 $pro_version = explode( '-', ORDERABLE_PRO_VERSION );
224
225 return version_compare( $pro_version[0], self::$required_pro_version, '>=' );
226 }
227
228 /**
229 * Is Woo active.
230 *
231 * @return bool
232 */
233 public static function is_woo_active() {
234 return in_array( 'woocommerce/woocommerce.php', (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ||
235 in_array( 'woocommerce/woocommerce.php', array_keys( (array) get_site_option( 'active_sitewide_plugins' ), true ) );
236 }
237
238 /**
239 * Load WooCommerce blocks.
240 *
241 * @return void
242 */
243 public function load_woocommerce_blocks() {
244 require_once ORDERABLE_MODULES_PATH . 'checkout/blocks/order-date/class-checkout-order-date-blocks-integration.php';
245 require_once ORDERABLE_MODULES_PATH . 'checkout/blocks/order-date/class-checkout-order-date-extend-store-api.php';
246
247 add_action(
248 'woocommerce_blocks_checkout_block_registration',
249 function( $integration_registry ) {
250 $integration_registry->register( new Checkout_Order_Date_Blocks_Integration() );
251 }
252 );
253
254 woocommerce_store_api_register_endpoint_data( Checkout_Order_Date_Extend_Store_API::extend_cart_schema() );
255 woocommerce_store_api_register_endpoint_data( Checkout_Order_Date_Extend_Store_API::extend_checkout_schema() );
256
257 add_action(
258 'woocommerce_store_api_checkout_update_order_from_request',
259 array( 'Checkout_Order_Date_Blocks_Integration', 'save_order_service_date_fields' ),
260 10,
261 2
262 );
263 }
264 }
265
266 $orderable = new Orderable();
267