bootstrapped ) { throw new AtumException( 'already_bootstrapped', __( 'ATUM plugin can only be called once', ATUM_TEXT_DOMAIN ), self::ALREADY_BOOTSTRAPED ); } // The ATUM comments must be instantiated before checking dependencies to ensure that are not displayed // in queries when any dependency is not met. AtumComments::get_instance(); // Check that the plugin dependencies are met. $this->check_dependencies(); // Bootstrap the plugin. Main::get_instance(); $this->bootstrapped = TRUE; } catch ( AtumException $e ) { if ( in_array( $e->getCode(), array( self::ALREADY_BOOTSTRAPED, self::DEPENDENCIES_UNSATISFIED ) ) ) { $this->admin_message = $e->getMessage(); add_action( 'admin_notices', array( $this, 'show_bootstrap_warning' ) ); } } } /** * Check the plugin dependencies before bootstrapping * * @since 0.0.2 * * @throws AtumException */ private function check_dependencies() { // WooCommerce required. if ( ! function_exists( 'WC' ) ) { throw new AtumException( 'woocommerce_disabled', __( 'ATUM requires WooCommerce to be activated', ATUM_TEXT_DOMAIN ), self::DEPENDENCIES_UNSATISFIED ); } // WooCommerce "Manage Stock" global option must be enabled. else { $woo_inventory_page = 'page=wc-settings&tab=products§ion=inventory'; // Special case for when the user is currently changing the stock option. if ( isset( $_POST['_wp_http_referer'] ) && FALSE !== strpos( $_POST['_wp_http_referer'], $woo_inventory_page ) ) { // It's a checkbox, so it's not sent with the form if unchecked. $display_stock_option_notice = ! isset( $_POST['woocommerce_manage_stock'] ); } else { $manage = get_option( 'woocommerce_manage_stock' ); $display_stock_option_notice = ! $manage || 'no' === $manage; } if ( $display_stock_option_notice ) { $stock_option_msg = __( "You need to enable WooCommerce 'Manage Stock' option for ATUM plugin to work.", ATUM_TEXT_DOMAIN ); if ( ! isset( $_GET['page'] ) || 'wc-settings' !== $_GET['page'] || ! isset( $_GET['tab'] ) || 'products' !== $_GET['tab'] || ! isset( $_GET['section'] ) || 'inventory' !== $_GET['section'] ) { $stock_option_msg .= ' ' . sprintf( /* translators: the first one is the WC inventory settings page link and the second is the link closing tag */ __( 'Go to %1$sWooCommerce inventory settings%2$s to fix this.', ATUM_TEXT_DOMAIN ), '', '' ); } throw new AtumException( 'woocommerce_manage_stock_disabled', $stock_option_msg, self::DEPENDENCIES_UNSATISFIED ); } } // Minimum PHP version required: 5.6. if ( version_compare( phpversion(), ATUM_PHP_MINIMUM_VERSION, '<' ) ) { throw new AtumException( 'php_min_version_required', __( 'ATUM requires PHP version ' . ATUM_PHP_MINIMUM_VERSION . ' or greater. Please, update or contact your hosting provider.', ATUM_TEXT_DOMAIN ), self::DEPENDENCIES_UNSATISFIED ); } // Minimum WordPress version required: 4.0. global $wp_version; if ( version_compare( $wp_version, ATUM_WP_MINIMUM_VERSION, '<' ) ) { /* translators: the first one is the WP updates page link and the second is the link closing tag */ throw new AtumException( 'wordpress_min_version_required', sprintf( __( 'ATUM requires WordPress version ' . ATUM_WP_MINIMUM_VERSION . ' or greater. Please, %1$supdate now%2$s.', ATUM_TEXT_DOMAIN ), '', '' ), self::DEPENDENCIES_UNSATISFIED ); } // Minimum WooCommerce version required: 3.0. if ( version_compare( WC()->version, ATUM_WC_MINIMUM_VERSION, '<' ) ) { /* translators: the first one is the WP updates page link and the second is the link closing tag */ throw new AtumException( 'woocommerce_min_version_required', sprintf( __( 'ATUM requires WooCommerce version ' . ATUM_WC_MINIMUM_VERSION . ' or greater. Please, %1$supdate now%2$s.', ATUM_TEXT_DOMAIN ), '', '' ), self::DEPENDENCIES_UNSATISFIED ); } } /** * Display an admin notice if was not possible to bootstrap the plugin * * @since 0.0.2 */ public function show_bootstrap_warning() { if ( ! empty( $this->admin_message ) ) : ?>
admin_message; // WPCS: XSS ok. ?>