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

235 lines 6.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.12.2
7 * Author: Orderable
8 * Text Domain: orderable
9 * WC requires at least: 5.4.0
10 * WC tested up to: 8.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.12.2';
23
24 /**
25 * @var string Required pro version.
26 */
27 public static $required_pro_version = '1.11.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 }
52
53 /**
54 * Load Textdomain.
55 */
56 public function load_textdomain() {
57 load_plugin_textdomain( 'orderable', false, ORDERABLE_LANGUAGES_PATH );
58 }
59
60 /**
61 * Run.
62 */
63 public function run() {
64 if ( ! self::is_woo_active() ) {
65 add_action( 'admin_notices', array( __CLASS__, 'orderable_notice_woocommerce' ) );
66
67 // If Woo is not active, don't run Orderable.
68 return;
69 }
70
71 $this->load_classes();
72 $this->update_check();
73 Orderable_Database::run();
74
75 if ( ! $this->validate_pro_version() ) {
76 add_action( 'admin_notices', array( __CLASS__, 'orderable_notice_pro_version' ) );
77
78 $this->define( 'ORDERABLE_PRO_INVALID', true );
79 }
80
81 do_action( 'orderable_init' );
82 }
83
84 /**
85 * Run when plugin activated.
86 *
87 * @param $plugin
88 *
89 * @return void
90 */
91 public function activate( $plugin ) {
92 if ( ! self::is_woo_active() ) {
93 return;
94 }
95
96 $checked = isset( $_REQUEST['checked'] ) ? $_REQUEST['checked'] : [];
97
98 // Ensure we are not doing a bulk activation.
99 if ( is_array( $checked ) && count( $checked ) > 1 ) {
100 return;
101 }
102
103 if ( ORDERABLE_BASENAME !== $plugin ) {
104 return;
105 }
106
107 wp_redirect( admin_url( 'admin.php?page=orderable-settings' ) );
108 exit;
109 }
110
111 /**
112 * Run script sif plugin version has changed.
113 */
114 private function update_check() {
115 if ( ORDERABLE_VERSION === get_site_option( 'orderable_version' ) ) {
116 return;
117 }
118
119 Orderable_Helpers::delete_orderable_transients();
120 update_option( 'orderable_version', ORDERABLE_VERSION );
121 }
122
123 /**
124 * Activate WooCommerce notice.
125 */
126 public static function orderable_notice_woocommerce() {
127 ?>
128 <div class="notice notice-error">
129 <p>
130 <?php _e( 'Orderable requires WooCommerce to be installed and activated.', 'orderable' ); ?>
131 </p>
132 </div>
133 <?php
134 }
135
136 /**
137 * Get Orderable pro version notice.
138 */
139 public static function orderable_notice_pro_version() {
140 ?>
141 <div class="notice notice-error">
142 <p>
143 <?php printf( __( 'Orderable Pro needs to be at least v%s for compatibility. Please update the Orderable Pro plugin.', 'orderable' ), self::$required_pro_version ); ?>
144 <a href="<?php echo esc_url( admin_url( 'update-core.php' ) ); ?>"><?php _e( 'Update now', 'orderable' ); ?></a>.
145 </p>
146 </div>
147 <?php
148 }
149
150 /**
151 * Define Constants.
152 */
153 private function define_constants() {
154 $this->define( 'ORDERABLE_PATH', plugin_dir_path( __FILE__ ) );
155 $this->define( 'ORDERABLE_URL', plugin_dir_url( __FILE__ ) );
156 $this->define( 'ORDERABLE_ASSETS_URL', ORDERABLE_URL . 'assets/' );
157 $this->define( 'ORDERABLE_INC_PATH', ORDERABLE_PATH . 'inc/' );
158 $this->define( 'ORDERABLE_MODULES_PATH', ORDERABLE_INC_PATH . 'modules/' );
159 $this->define( 'ORDERABLE_VENDOR_PATH', ORDERABLE_INC_PATH . 'vendor/' );
160 $this->define( 'ORDERABLE_TEMPLATES_PATH', ORDERABLE_PATH . 'templates/' );
161 $this->define( 'ORDERABLE_TPL_PATH', ORDERABLE_PATH . 'templates/' );
162 $this->define( 'ORDERABLE_BASENAME', plugin_basename( __FILE__ ) );
163 $this->define( 'ORDERABLE_LANGUAGES_PATH', dirname( ORDERABLE_BASENAME ) . '/languages/' );
164 $this->define( 'ORDERABLE_VERSION', self::$version );
165 }
166
167 /**
168 * Define constant if not already set.
169 *
170 * @param string $name
171 * @param string|bool $value
172 */
173 private function define( $name, $value ) {
174 if ( ! defined( $name ) ) {
175 define( $name, $value );
176 }
177 }
178
179 /**
180 * Load classes.
181 */
182 private function load_classes() {
183 require_once ORDERABLE_INC_PATH . 'database/class-database.php';
184 require_once ORDERABLE_INC_PATH . 'class-helpers.php';
185 require_once ORDERABLE_INC_PATH . 'class-settings.php';
186 require_once ORDERABLE_INC_PATH . 'class-modules.php';
187 require_once ORDERABLE_INC_PATH . 'class-assets.php';
188 require_once ORDERABLE_INC_PATH . 'class-products.php';
189 require_once ORDERABLE_INC_PATH . 'class-ajax.php';
190 require_once ORDERABLE_INC_PATH . 'class-orders.php';
191 require_once ORDERABLE_INC_PATH . 'class-admin-notices.php';
192 require_once ORDERABLE_INC_PATH . 'class-webhooks.php';
193 require_once ORDERABLE_INC_PATH . 'class-shortcodes.php';
194 require_once ORDERABLE_INC_PATH . 'class-ask-review.php';
195 require_once ORDERABLE_INC_PATH . 'class-integrations.php';
196
197 Orderable_Settings::run();
198 Orderable_Assets::run();
199 Orderable_Modules::run();
200 Orderable_Products::run();
201 Orderable_Ajax::run();
202 Orderable_Shortcodes::run();
203 Orderable_Ask_Review::run();
204 Orderable_Integrations::run();
205 }
206
207 /**
208 * Validate the Orderable core version number.
209 *
210 * @return bool
211 */
212 private static function validate_pro_version() {
213 if ( ! defined( 'ORDERABLE_PRO_VERSION' ) ) {
214 // Pro version is valid because it doesn't exist.
215 return true;
216 }
217
218 $pro_version = explode( '-', ORDERABLE_PRO_VERSION );
219
220 return version_compare( $pro_version[0], self::$required_pro_version, '>=' );
221 }
222
223 /**
224 * Is Woo active.
225 *
226 * @return bool
227 */
228 public static function is_woo_active() {
229 return in_array( 'woocommerce/woocommerce.php', (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ||
230 in_array( 'woocommerce/woocommerce.php', array_keys( (array) get_site_option( 'active_sitewide_plugins' ), true ) );
231 }
232 }
233
234 $orderable = new Orderable();
235