Package.php
119 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Returns information about the package and handles init. |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * This namespace isn't compatible with the PSR-4 |
| 8 | * which ensures that the copy in the standalone plugin will not be autoloaded. |
| 9 | */ |
| 10 | namespace Automattic\WooCommerce\Admin\Composer; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Automattic\WooCommerce\Admin\Notes\Notes; |
| 15 | use Automattic\WooCommerce\Admin\Notes\NotesUnavailableException; |
| 16 | use Automattic\WooCommerce\Internal\Admin\FeaturePlugin; |
| 17 | |
| 18 | /** |
| 19 | * Main package class. |
| 20 | */ |
| 21 | class Package { |
| 22 | |
| 23 | /** |
| 24 | * Version. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | const VERSION = '3.3.0'; |
| 29 | |
| 30 | /** |
| 31 | * Package active. |
| 32 | * |
| 33 | * @var bool |
| 34 | */ |
| 35 | private static $package_active = false; |
| 36 | |
| 37 | /** |
| 38 | * Active version |
| 39 | * |
| 40 | * @var bool |
| 41 | */ |
| 42 | private static $active_version = null; |
| 43 | |
| 44 | /** |
| 45 | * Init the package. |
| 46 | * |
| 47 | * Only initialize for WP 5.3 or greater. |
| 48 | */ |
| 49 | public static function init() { |
| 50 | // Avoid double initialization when the feature plugin is in use. |
| 51 | if (defined( 'WC_ADMIN_VERSION_NUMBER' ) ) { |
| 52 | self::$active_version = WC_ADMIN_VERSION_NUMBER; |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | $feature_plugin_instance = FeaturePlugin::instance(); |
| 57 | |
| 58 | // Indicate to the feature plugin that the core package exists. |
| 59 | if ( ! defined( 'WC_ADMIN_PACKAGE_EXISTS' ) ) { |
| 60 | define( 'WC_ADMIN_PACKAGE_EXISTS', true ); |
| 61 | } |
| 62 | |
| 63 | self::$package_active = true; |
| 64 | self::$active_version = self::VERSION; |
| 65 | $feature_plugin_instance->init(); |
| 66 | |
| 67 | // Unhook the custom Action Scheduler data store class in active older versions of WC Admin. |
| 68 | remove_filter( 'action_scheduler_store_class', array( $feature_plugin_instance, 'replace_actionscheduler_store_class' ) ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Return the version of the package. |
| 73 | * |
| 74 | * @return string |
| 75 | */ |
| 76 | public static function get_version() { |
| 77 | return self::VERSION; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Return the active version of WC Admin. |
| 82 | * |
| 83 | * @return string |
| 84 | */ |
| 85 | public static function get_active_version() { |
| 86 | return self::$active_version; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Return whether the package is active. |
| 91 | * |
| 92 | * @return bool |
| 93 | */ |
| 94 | public static function is_package_active() { |
| 95 | return self::$package_active; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Return the path to the package. |
| 100 | * |
| 101 | * @return string |
| 102 | */ |
| 103 | public static function get_path() { |
| 104 | return dirname( __DIR__ ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Checks if notes have been initialized. |
| 109 | */ |
| 110 | private static function is_notes_initialized() { |
| 111 | try { |
| 112 | Notes::load_data_store(); |
| 113 | } catch ( NotesUnavailableException $e ) { |
| 114 | return false; |
| 115 | } |
| 116 | return true; |
| 117 | } |
| 118 | } |
| 119 |