# orderable/0.2.0/orderable.php

Orderable – Restaurant &amp; Food Ordering System, version 0.2.0. 176 lines.

- Page: https://pluginprobe.com/plugins/orderable/0.2.0/code/orderable.php
- Raw: https://pluginprobe.com/plugins/orderable/0.2.0/raw/orderable.php
- Modified: 2021-09-24T11:57:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/orderable/0.2.0/code/orderable.php#L10-L20`.

```php
<?php
/**
 * Plugin Name: Orderable - Local Ordering System
 * Author URI: https://orderable.com
 * Description: Take local online ordering to a whole new level with Orderable.
 * Version: 0.2.0
 * Author: Orderable
 * Text Domain: orderable
 * WC requires at least: 5.4.0
 * WC tested up to: 5.7.1
 */

defined( 'ABSPATH' ) || exit;

/**
 * Orderable main class.
 */
class Orderable {
	/**
	 * @var string Plugin version.
	 */
	public static $version = '0.2.0';

	/**
	 * @var string Required pro version.
	 */
	public static $required_pro_version = '0.2.0';

	/**
	 * Construct the plugin.
	 */
	public function __construct() {
		$this->define_constants();

		add_action( 'init', array( $this, 'load_textdomain' ), 0 );
		add_action( 'plugins_loaded', array( $this, 'run' ), 20 );
	}

	/**
	 * Load Textdomain.
	 */
	public function load_textdomain() {
		load_plugin_textdomain( 'orderable', false, ORDERABLE_LANGUAGES_PATH );
	}

	/**
	 * Run.
	 */
	public function run() {
		if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true )
			&& ! in_array( 'woocommerce/woocommerce.php', array_keys( get_site_option( 'active_sitewide_plugins' ), true ) ) ) {
			add_action( 'admin_notices', array( __CLASS__, 'orderable_notice_woocommerce' ) );

			return;
		}

		$this->load_classes();
		$this->update_check();

		if ( ! $this->validate_pro_version() ) {
			add_action( 'admin_notices', array( __CLASS__, 'orderable_notice_pro_version' ) );

			$this->define( 'ORDERABLE_PRO_INVALID', true );
		}

		do_action( 'orderable_init' );
	}

	/**
	 * Run script sif plugin version has changed.
	 */
	private function update_check() {
		if ( ORDERABLE_VERSION === get_site_option( 'orderable_version' ) ) {
			return;
		}

		Orderable_Helpers::delete_orderable_transients();
		update_option( 'orderable_version', ORDERABLE_VERSION );
	}

	/**
	 * Activate WooCommerce notice.
	 */
	public static function orderable_notice_woocommerce() {
		?>
		<div class="notice notice-error">
			<p>
				<?php _e( 'Orderable requires WooCommerce to be installed and activated.', 'orderable' ); ?>
			</p>
		</div>
		<?php
	}

	/**
	 * Get Orderable pro version notice.
	 */
	public static function orderable_notice_pro_version() {
		?>
		<div class="notice notice-error">
			<p>
				<?php printf( __( 'Orderable Pro needs to be at least v%s for compatibility. Please update the Orderable Pro plugin.', 'orderable' ), self::$required_pro_version ); ?>
				<a href="<?php echo esc_url( admin_url( 'update-core.php' ) ); ?>"><?php _e( 'Update now', 'orderable' ); ?></a>.
			</p>
		</div>
		<?php
	}

	/**
	 * Define Constants.
	 */
	private function define_constants() {
		$this->define( 'ORDERABLE_PATH', plugin_dir_path( __FILE__ ) );
		$this->define( 'ORDERABLE_URL', plugin_dir_url( __FILE__ ) );
		$this->define( 'ORDERABLE_ASSETS_URL', ORDERABLE_URL . 'assets/' );
		$this->define( 'ORDERABLE_INC_PATH', ORDERABLE_PATH . 'inc/' );
		$this->define( 'ORDERABLE_MODULES_PATH', ORDERABLE_INC_PATH . 'modules/' );
		$this->define( 'ORDERABLE_VENDOR_PATH', ORDERABLE_INC_PATH . 'vendor/' );
		$this->define( 'ORDERABLE_TEMPLATES_PATH', ORDERABLE_PATH . 'templates/' );
		$this->define( 'ORDERABLE_TPL_PATH', ORDERABLE_PATH . 'templates/' );
		$this->define( 'ORDERABLE_BASENAME', plugin_basename( __FILE__ ) );
		$this->define( 'ORDERABLE_LANGUAGES_PATH', dirname( ORDERABLE_BASENAME ) . '/languages/' );
		$this->define( 'ORDERABLE_VERSION', self::$version );
	}

	/**
	 * Define constant if not already set.
	 *
	 * @param string      $name
	 * @param string|bool $value
	 */
	private function define( $name, $value ) {
		if ( ! defined( $name ) ) {
			define( $name, $value );
		}
	}

	/**
	 * Load classes.
	 */
	private function load_classes() {
		require_once ORDERABLE_INC_PATH . 'class-helpers.php';
		require_once ORDERABLE_INC_PATH . 'class-settings.php';
		require_once ORDERABLE_INC_PATH . 'class-modules.php';
		require_once ORDERABLE_INC_PATH . 'class-assets.php';
		require_once ORDERABLE_INC_PATH . 'class-products.php';
		require_once ORDERABLE_INC_PATH . 'class-ajax.php';
		require_once ORDERABLE_INC_PATH . 'class-orders.php';
		require_once ORDERABLE_INC_PATH . 'class-admin-notices.php';

		Orderable_Settings::run();
		Orderable_Assets::run();
		Orderable_Modules::run();
		Orderable_Products::run();
		Orderable_Ajax::run();
		Orderable_Admin_Notices::run();
	}

	/**
	 * Validate the Orderable core version number.
	 *
	 * @return bool
	 */
	private static function validate_pro_version() {
		if ( ! defined( 'ORDERABLE_PRO_VERSION' ) ) {
			// Pro version is valid because it doesn't exist.
			return true;
		}

		$pro_version = explode( '-', ORDERABLE_PRO_VERSION );

		return version_compare( $pro_version[0], self::$required_pro_version, '>=' );
	}
}

$orderable = new Orderable();

```
