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

263 lines 7.3 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.14.0
7 * Author: Orderable
8 * Text Domain: orderable
9 * WC requires at least: 5.4.0
10 * WC tested up to: 8.9
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.14.0';
23
24 /**
25 * @var string Required pro version.
26 */
27 public static $required_pro_version = '1.14.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 }
167
168 /**
169 * Define constant if not already set.
170 *
171 * @param string $name
172 * @param string|bool $value
173 */
174 private function define( $name, $value ) {
175 if ( ! defined( $name ) ) {
176 define( $name, $value );
177 }
178 }
179
180 /**
181 * Load classes.
182 */
183 private function load_classes() {
184 require_once ORDERABLE_INC_PATH . 'database/class-database.php';
185 require_once ORDERABLE_INC_PATH . 'class-helpers.php';
186 require_once ORDERABLE_INC_PATH . 'class-settings.php';
187 require_once ORDERABLE_INC_PATH . 'class-modules.php';
188 require_once ORDERABLE_INC_PATH . 'class-assets.php';
189 require_once ORDERABLE_INC_PATH . 'class-products.php';
190 require_once ORDERABLE_INC_PATH . 'class-ajax.php';
191 require_once ORDERABLE_INC_PATH . 'class-orders.php';
192 require_once ORDERABLE_INC_PATH . 'class-admin-notices.php';
193 require_once ORDERABLE_INC_PATH . 'class-webhooks.php';
194 require_once ORDERABLE_INC_PATH . 'class-shortcodes.php';
195 require_once ORDERABLE_INC_PATH . 'class-ask-review.php';
196 require_once ORDERABLE_INC_PATH . 'class-integrations.php';
197
198 Orderable_Settings::run();
199 Orderable_Assets::run();
200 Orderable_Modules::run();
201 Orderable_Products::run();
202 Orderable_Ajax::run();
203 Orderable_Shortcodes::run();
204 Orderable_Ask_Review::run();
205 Orderable_Integrations::run();
206 }
207
208 /**
209 * Validate the Orderable core version number.
210 *
211 * @return bool
212 */
213 private static function validate_pro_version() {
214 if ( ! defined( 'ORDERABLE_PRO_VERSION' ) ) {
215 // Pro version is valid because it doesn't exist.
216 return true;
217 }
218
219 $pro_version = explode( '-', ORDERABLE_PRO_VERSION );
220
221 return version_compare( $pro_version[0], self::$required_pro_version, '>=' );
222 }
223
224 /**
225 * Is Woo active.
226 *
227 * @return bool
228 */
229 public static function is_woo_active() {
230 return in_array( 'woocommerce/woocommerce.php', (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ||
231 in_array( 'woocommerce/woocommerce.php', array_keys( (array) get_site_option( 'active_sitewide_plugins' ), true ) );
232 }
233
234 /**
235 * Load WooCommerce blocks.
236 *
237 * @return void
238 */
239 public function load_woocommerce_blocks() {
240 require_once ORDERABLE_MODULES_PATH . 'checkout/blocks/order-date/class-checkout-order-date-blocks-integration.php';
241 require_once ORDERABLE_MODULES_PATH . 'checkout/blocks/order-date/class-checkout-order-date-extend-store-api.php';
242
243 add_action(
244 'woocommerce_blocks_checkout_block_registration',
245 function( $integration_registry ) {
246 $integration_registry->register( new Checkout_Order_Date_Blocks_Integration() );
247 }
248 );
249
250 woocommerce_store_api_register_endpoint_data( Checkout_Order_Date_Extend_Store_API::extend_cart_schema() );
251 woocommerce_store_api_register_endpoint_data( Checkout_Order_Date_Extend_Store_API::extend_checkout_schema() );
252
253 add_action(
254 'woocommerce_store_api_checkout_update_order_from_request',
255 array( 'Checkout_Order_Date_Blocks_Integration', 'save_order_service_date_fields' ),
256 10,
257 2
258 );
259 }
260 }
261
262 $orderable = new Orderable();
263