is_environment_compatible() ) { add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); } } /** * Cloning instances is forbidden due to singleton pattern. * * @since 3.6.0 */ public function __clone() { _doing_it_wrong( __FUNCTION__, sprintf( 'You cannot clone instances of %s.', get_class( $this ) ), '3.6.0' ); } /** * Unserializing instances is forbidden due to singleton pattern. * * @since 3.6.0 */ public function __wakeup() { _doing_it_wrong( __FUNCTION__, sprintf( 'You cannot unserialize instances of %s.', get_class( $this ) ), '3.6.0' ); } /** * Initializes the plugin. * * @since 3.6.0 */ public function init_plugin() { if ( ! $this->plugins_compatible() ) { return; } $this->load_framework(); // load the main plugin class require_once( plugin_dir_path( __FILE__ ) . 'class-wc-csv-import-suite.php' ); // fire it up! wc_csv_import_suite(); } /** * Loads the base framework classes. * * @since 3.6.0 */ protected function load_framework() { if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\' . $this->get_framework_version_namespace() . '\\SV_WC_Plugin' ) ) { require_once( plugin_dir_path( __FILE__ ) . 'vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php' ); } if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\' . $this->get_framework_version_namespace() . '\\SV_WP_Async_Request' ) ) { require_once( plugin_dir_path( __FILE__ ) . 'vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-async-request.php' ); } if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\' . $this->get_framework_version_namespace() . '\\SV_WP_Background_Job_Handler' ) ) { require_once( plugin_dir_path( __FILE__ ) . 'vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php' ); } } /** * Gets the framework version in namespace form. * * @since 3.6.0 * * @return string */ protected function get_framework_version_namespace() { return 'v' . str_replace( '.', '_', $this->get_framework_version() ); } /** * Gets the framework version used by this plugin. * * @since 3.6.0 * * @return string */ protected function get_framework_version() { return self::FRAMEWORK_VERSION; } /** * Checks the server environment and other factors and deactivates plugins as necessary. * * Based on http://wptavern.com/how-to-prevent-wordpress-plugins-from-activating-on-sites-with-incompatible-hosting-environments * * @since 3.6.0 */ public function activation_check() { if ( ! $this->is_environment_compatible() ) { $this->deactivate_plugin(); wp_die( self::PLUGIN_NAME . ' could not be activated. ' . $this->get_environment_message() ); } } /** * Checks the environment on loading WordPress, just in case the environment changes after activation. * * @since 3.6.0 */ public function check_environment() { if ( ! $this->is_environment_compatible() && is_plugin_active( plugin_basename( __FILE__ ) ) ) { $this->deactivate_plugin(); $this->add_admin_notice( 'bad_environment', 'error', self::PLUGIN_NAME . ' has been deactivated. ' . $this->get_environment_message() ); } } /** * Adds notices for out-of-date WordPress and/or WooCommerce versions. * * @since 3.6.0 */ public function add_plugin_notices() { if ( ! $this->is_wp_compatible() ) { $this->add_admin_notice( 'update_wordpress', 'error', sprintf( '%s requires WordPress version %s or higher. Please %supdate WordPress »%s', '' . self::PLUGIN_NAME . '', self::MINIMUM_WP_VERSION, '', '' ) ); } if ( ! $this->is_wc_compatible() ) { $this->add_admin_notice( 'update_woocommerce', 'error', sprintf( '%1$s requires WooCommerce version %2$s or higher. Please %3$supdate WooCommerce%4$s to the latest version, or %5$sdownload the minimum required version »%6$s', '' . self::PLUGIN_NAME . '', self::MINIMUM_WC_VERSION, '', '', '', '' ) ); } } /** * Determines if the required plugins are compatible. * * @since 3.6.0 * * @return bool */ protected function plugins_compatible() { return $this->is_wp_compatible() && $this->is_wc_compatible(); } /** * Determines if the WordPress compatible. * * @since 3.6.0 * * @return bool */ protected function is_wp_compatible() { return version_compare( get_bloginfo( 'version' ), self::MINIMUM_WP_VERSION, '>=' ); } /** * Determines if the WooCommerce compatible. * * @since 3.6.0 * * @return bool */ protected function is_wc_compatible() { return defined( 'WC_VERSION' ) && version_compare( WC_VERSION, self::MINIMUM_WC_VERSION, '>=' ); } /** * Deactivates the plugin. * * @since 3.6.0 */ protected function deactivate_plugin() { deactivate_plugins( plugin_basename( __FILE__ ) ); if ( isset( $_GET['activate'] ) ) { unset( $_GET['activate'] ); } } /** * Adds an admin notice to be displayed. * * @since 3.6.0 * * @param string $slug the slug for the notice * @param string $class the css class for the notice * @param string $message the notice message */ public function add_admin_notice( $slug, $class, $message ) { $this->notices[ $slug ] = array( 'class' => $class, 'message' => $message ); } /** * Displays any admin notices. * * @since 3.6.0 */ public function admin_notices() { foreach ( (array) $this->notices as $notice_key => $notice ) : ?>
array( 'href' => array() ) ) ); ?>