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

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