'woocommerce-csv-import-suite', 'supports_hpos' => true, 'dependencies' => [ 'php_extensions' => [ 'mbstring', ], ], ] ); // cleanup expired imports add_action( 'wc_customer_order_csv_import_scheduled_import_cleanup', [ $this, 'cleanup_imports' ] ); } /** * Loads and initializes the plugin lifecycle handler. * * @since 3.6.0 */ protected function init_lifecycle_handler() { require_once( $this->get_plugin_path() . '/src/Lifecycle.php' ); $this->lifecycle_handler = new \SkyVerge\WooCommerce\CSV_Import_Suite\Lifecycle( $this ); } /** * Initializes the plugin. * * @internal * * @since 3.6.0 */ public function init_plugin() { // load required files. $this->includes(); // schedule cleanup of imported files which are older than 14 days $this->schedule_import_cleanup(); } /** * Schedule once-daily cleanup of old import jobs. * * @internal * * @since 3.4.0 */ public function schedule_import_cleanup() { if ( ! wp_next_scheduled( 'wc_customer_order_csv_import_scheduled_import_cleanup' ) ) { wp_schedule_event( strtotime( 'tomorrow +15 minutes' ), 'daily', 'wc_customer_order_csv_import_scheduled_import_cleanup' ); } } /** * Includes required files. * * @internal * * @since 3.0.0 */ public function includes() { // background job handler to add usage_count meta to coupons that don't have a value defined require_once( $this->get_plugin_path() . '/src/Background_Fix_Coupons_Usage_Count.php' ); if ( 'yes' !== get_option( 'wc_csv_import_suite_coupons_usage_count_fixed', 'no' ) ) { $this->background_fix_coupons_usage_count = new Background_Fix_Coupons_Usage_Count(); } $this->background_import = $this->load_class( '/src/class-wc-csv-import-suite-background-import.php', 'WC_CSV_Import_Suite_Background_Import' ); $this->importers = $this->load_class( '/src/class-wc-csv-import-suite-importers.php', 'WC_CSV_Import_Suite_Importers' ); if ( is_admin() ) { $this->admin = $this->load_class( '/src/admin/class-wc-csv-import-suite-admin.php', 'WC_CSV_Import_Suite_Admin' ); } if ( wp_doing_ajax() ) { require_once( $this->get_plugin_path() . '/src/class-wc-csv-import-suite-parser.php' ); $this->ajax = $this->load_class( '/src/class-wc-csv-import-suite-ajax.php', 'WC_CSV_Import_Suite_AJAX' ); } } /** * Gets the admin handler instance. * * @since 3.0.0 * * @return \WC_CSV_Import_Suite_Admin */ public function get_admin_instance() { return $this->admin; } /** * Gets the importers handler instance. * * @since 3.0.0 * * @return \WC_CSV_Import_Suite_Importers */ public function get_importers_instance() { return $this->importers; } /** * Gets the background import handler instance. * * @since 3.0.0 * * @return \WC_CSV_Import_Suite_Background_Import */ public function get_background_import_instance() { return $this->background_import; } /** * Gets the background fix coupons usage count handler instance. * * @since 3.8.3 */ public function get_background_fix_coupons_usage_count_instance() { return $this->background_fix_coupons_usage_count; } /** * Gets the AJAX handler instance. * * @since 3.0.0 * * @return \WC_CSV_Import_Suite_AJAX */ public function get_ajax_instance() { return $this->ajax; } /** * Determines if on the current page is the settings page. * * @since 2.3 * * @return bool */ public function is_plugin_settings() { return isset( $_GET['page'] ) && self::PLUGIN_ID === $_GET['page']; } /** * Gets the "Import" plugin action link to go directly to the plugin settings page (if any). * * @since 2.3 * * @param string|null $plugin_id the plugin identifier * @return string */ public function get_settings_link( $plugin_id = null ) { if ( $settings_url = $this->get_settings_url( $plugin_id ) ) { $settings_url = sprintf( '%s', $settings_url, __( 'Import', 'woocommerce-csv-import-suite' ) ); } else { $settings_url = ''; } return $settings_url; } /** * Gets the plugin configuration URL. * * @since 2.3 * * @param string|null $plugin_id the plugin identifier * @return string */ public function get_settings_url( $plugin_id = null ) { // link to the import page return admin_url( 'admin.php?page=' . self::PLUGIN_ID ); } /** * Gets the plugin documentation url. * * @since 2.3.0 * * @return string */ public function get_documentation_url() { return 'https://docs.woocommerce.com/document/customer-order-csv-import-suite/'; } /** * Gets the plugin support URL. * * @since 2.3.0 * * @return string */ public function get_support_url() { return 'https://woocommerce.com/my-account/marketplace-ticket-form/'; } /** * Gets the plugin sales page URL. * * @since 3.6.0 * * @return string */ public function get_sales_page_url() { return 'https://woocommerce.com/products/customerorder-csv-import-suite/'; } /** * Gets the plugin name, localized. * * @since 2.3 * * @return string */ public function get_plugin_name() { return __( 'WooCommerce Customer/Order/Coupon CSV Import', 'woocommerce-csv-import-suite' ); } /** * Gets __FILE__. * * @since 2.3 * * @return string the full path and filename of the plugin file */ protected function get_file() { return __FILE__; } /** * Gets the main Customer/Order/Coupon CSV Import Suite instance. * * Ensures only one instance is/can be loaded. * * @since 2.7.0 * * @return WC_CSV_Import_Suite */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Adds an entry to the debug log if enabled. * * @since 3.1.1 * * @param string $message the log message * @param null $_ unused */ public function log( $message, $_ = null ) { if ( $this->logging_enabled() ) { parent::log( $message ); } } /** * Determines if debug logging is enabled for a given importer. * * @since 3.1.1 * * @return bool */ public function logging_enabled() { $this->logging_enabled = 'yes' === get_option( 'wc_csv_import_suite_debug_mode', 'no' ); /** * Filters whether debug logging is enabled. * * @since 3.1.1 * * @param bool $logging_enabled whether logging is enabled */ return (bool) apply_filters( 'wc_csv_import_suite_logging_enabled', $this->logging_enabled ); } /** * Cleans up (removes) imported files which are older than 14 days. * * @internal * * @since 3.4.0 */ public function cleanup_imports() { wc_csv_import_suite()->get_background_import_instance()->remove_expired_imports(); } /** * Removes the import finished notice from user meta. * * @since 3.1.0 * * @param string $import_id Import job ID * @param int $user_id */ public function remove_import_finished_notice( $import_id, $user_id ) { $import_notices = get_user_meta( $user_id, '_wc_csv_import_suite_notices', true ); if ( ! empty( $import_notices ) && in_array( $import_id, $import_notices, true ) ) { unset( $import_notices[ array_search( $import_id, $import_notices, false ) ] ); update_user_meta( $user_id, '_wc_csv_import_suite_notices', $import_notices ); } // also remove the message from user dismissed notices $dismissed_notices = wc_csv_import_suite()->get_admin_notice_handler()->get_dismissed_notices( $user_id ); $message_id = 'wc_csv_import_suite_finished_' . $import_id; if ( ! empty( $dismissed_notices ) && isset( $dismissed_notices[ $message_id ] ) ) { unset( $dismissed_notices[ $message_id ] ); update_user_meta( $user_id, '_wc_plugin_framework_csv_import_suite_dismissed_messages', $dismissed_notices ); } } } /** * Returns the One True Instance of Customer/Order/Coupon CSV Import Suite. * * @since 2.7.0 * * @return \WC_CSV_Import_Suite */ function wc_csv_import_suite() { return WC_CSV_Import_Suite::instance(); }