PluginProbe
Orderable – Restaurant & Food Ordering System / 1.21.1
Orderable – Restaurant & Food Ordering System v1.21.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.21.1, at orderable.php

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