PluginProbe
Orderable – Restaurant & Food Ordering System / 1.17.1
Orderable – Restaurant & Food Ordering System v1.17.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.17.1, at orderable.php

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