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. ?>

prefix . Globals::ATUM_PRODUCT_DATA_TABLE; $items_table = $wpdb->prefix . AtumOrderPostType::ORDER_ITEMS_TABLE; $itemmeta_table = $wpdb->prefix . AtumOrderPostType::ORDER_ITEM_META_TABLE; // Delete the ATUM tables in db. $wpdb->query( "DROP TABLE IF EXISTS $product_data_table" ); // WPCS: unprepared SQL ok. $wpdb->query( "DROP TABLE IF EXISTS $items_table" ); // WPCS: unprepared SQL ok. $wpdb->query( "DROP TABLE IF EXISTS $itemmeta_table" ); // WPCS: unprepared SQL ok. // Delete all the posts of ATUM's custom post types and their meta. $atum_post_types = array( PurchaseOrders::get_post_type(), InventoryLogs::get_post_type(), Suppliers::POST_TYPE, ); foreach ( $atum_post_types as $atum_post_type ) { $args = array( 'post_type' => $atum_post_type, 'posts_per_page' => - 1, 'fields' => 'ids', 'post_status' => 'any', ); $atum_posts = get_posts( $args ); if ( ! empty( $atum_posts ) ) { $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN (" . implode( ',', $atum_posts ) . ')' ); // WPCS: unprepared SQL ok. $wpdb->delete( $wpdb->posts, array( 'post_type' => $atum_post_type ) ); } } $atum_prefix = 'atum_'; // Delete all the ATUM order notes. $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_type LIKE '" . ATUM_PREFIX . "%'" ); // WPCS: unprepared SQL ok. // Delete all the user meta related to ATUM. $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '" . ATUM_PREFIX . "%'" ); // WPCS: unprepared SQL ok. // Delete the ATUM options. delete_option( ATUM_PREFIX . 'version' ); $settings = get_option( ATUM_PREFIX . 'settings') ; // Save delete data setting. if ( $settings && ! empty( $settings ) ) { $delete_data_setting = [ 'delete_data' => $settings['delete_data'] ]; update_option( ATUM_PREFIX . 'settings', $delete_data_setting ); } // Delete marketing popup transient. delete_transient( 'atum-marketing-popup' ); } } /******************* * Instance methods *******************/ /** * Cannot be cloned */ public function __clone() { _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', ATUM_TEXT_DOMAIN ), '1.0.0' ); } /** * Cannot be serialized */ public function __sleep() { _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', ATUM_TEXT_DOMAIN ), '1.0.0' ); } /** * Get Singleton instance * * @return Bootstrap instance */ public static function get_instance() { if ( ! ( self::$instance && is_a( self::$instance, __CLASS__ ) ) ) { self::$instance = new self(); } return self::$instance; } }