0 ) ) { update_option( self::SNAPSHOT_OPTION, 1 ); } self::uninstall_hook_on_main_site( class_exists( 'Freemius' ) ); } /** * On a subsite of a network, puts Freemius' uninstall hook on the main * site too, so deleting the plugin runs Uninstall::run(). * * Freemius registers WordPress' uninstall hook when the plugin is * deactivated, in the current site's `uninstall_plugins` option. Network * Admin deletes plugins as the main site and reads only the main site's * option, so a copy that was only ever active (and deactivated) on a * subsite was deleted without its uninstall hook, and its data stayed. * Never done at activation: Freemius takes the hook away on activation * on purpose, so WordPress does not load a plugin's main file only to * check that it can be uninstalled. * * @param bool $freemius Whether the Freemius SDK runs (never with the stub). * @return bool Whether the hook was put on the main site. */ public static function uninstall_hook_on_main_site( $freemius ) { if ( ! $freemius || ! is_multisite() || is_main_site() ) { return false; } switch_to_blog( get_main_site_id() ); register_uninstall_hook( EUCHECK_FILE, array( 'Freemius', '_uninstall_plugin_hook' ) ); restore_current_blog(); return true; } /** * Creates the table when it is missing or older than this version. */ public static function maybe_upgrade() { if ( get_option( self::DB_OPTION ) !== self::DB_VERSION ) { self::create_table(); add_option( Settings::OPTION, Settings::defaults() ); if ( ! get_option( 'eucheck_log_started' ) ) { update_option( self::SNAPSHOT_OPTION, 1 ); } } } /** * Starts the snapshot once WooCommerce and Action Scheduler are ready. * Only admin, cron and WP-CLI requests look, so shop pages never do. */ public static function maybe_queue_snapshot() { if ( ! is_admin() && ! wp_doing_cron() && ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { return; } if ( get_option( self::SNAPSHOT_OPTION ) ) { delete_option( self::SNAPSHOT_OPTION ); self::queue( 0 ); } } /** * Queues one snapshot batch in the background. * * @param int $after Last product ID already recorded, 0 to start. */ public static function queue( $after ) { $args = array( 'after' => (int) $after ); if ( function_exists( 'as_enqueue_async_action' ) ) { as_enqueue_async_action( Recorder::SNAPSHOT_HOOK, $args, 'eu-check' ); return; } wp_schedule_single_event( time(), Recorder::SNAPSHOT_HOOK, $args ); } /** * Creates or updates the table. */ public static function create_table() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $table = PriceLog::table(); $collate = $wpdb->get_charset_collate(); dbDelta( "CREATE TABLE {$table} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, product_id bigint(20) unsigned NOT NULL, parent_id bigint(20) unsigned NOT NULL DEFAULT 0, regular_price decimal(19,4) DEFAULT NULL, sale_price decimal(19,4) DEFAULT NULL, price decimal(19,4) NOT NULL, currency char(3) NOT NULL DEFAULT '', valid_from datetime NOT NULL, valid_to datetime DEFAULT NULL, PRIMARY KEY (id), KEY product_from (product_id,valid_from), KEY product_open (product_id,valid_to), KEY parent_id (parent_id) ) {$collate};" ); update_option( self::DB_OPTION, self::DB_VERSION ); } }