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

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