/**
  * Hooks upgrade function to init.
  *
  * @since 1.2
  */
 public static function init()
 {
     self::$active_version = get_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '0');
     self::$is_wc_version_2 = version_compare(get_option('woocommerce_db_version'), '2.0', '>=');
     self::$about_page_url = admin_url('index.php?page=wcs-about&wcs-updated=true');
     $version_out_of_date = version_compare(self::$active_version, WC_Subscriptions::$version, '<');
     // Set the cron lock on every request with an out of date version, regardless of authentication level, as we can only lock cron for up to 10 minutes at a time, but we need to keep it locked until the upgrade is complete, regardless of who is browing the site
     if ($version_out_of_date) {
         self::set_cron_lock();
     }
     if (isset($_POST['action']) && 'wcs_upgrade' == $_POST['action']) {
         // We're checking for CSRF in ajax_upgrade
         add_action('wp_ajax_wcs_upgrade', __CLASS__ . '::ajax_upgrade', 10);
     } elseif (@current_user_can('activate_plugins')) {
         if (isset($_GET['wcs_upgrade_step']) || $version_out_of_date) {
             $is_upgrading = get_option('wc_subscriptions_is_upgrading', false);
             // Check if we've exceeded the 2 minute upgrade window we use for blocking upgrades (we could seemingly use transients here to get the check for free if transients were guaranteed to exist: http://journal.rmccue.io/296/youre-using-transients-wrong/)
             if (false !== $is_upgrading && $is_upgrading < gmdate('U')) {
                 $is_upgrading = false;
                 delete_option('wc_subscriptions_is_upgrading');
             }
             if (false !== $is_upgrading) {
                 add_action('init', __CLASS__ . '::upgrade_in_progress_notice', 11);
             } else {
                 // Run upgrades as soon as admin hits site
                 add_action('wp_loaded', __CLASS__ . '::upgrade', 11);
             }
         } elseif (is_admin() && isset($_GET['page']) && 'wcs-about' == $_GET['page']) {
             add_action('admin_menu', __CLASS__ . '::updated_welcome_page');
         }
     }
     // While the upgrade is in progress, we need to block PayPal IPN messages to avoid renewals failing to process
     add_action('woocommerce_api_wc_gateway_paypal', __CLASS__ . '::maybe_block_paypal_ipn', 0);
 }
 /**
  * Hooks upgrade function to init.
  * 
  * @since 1.2
  */
 public static function init()
 {
     self::$active_version = get_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '0');
     if (isset($_GET['wcs_upgrade_step']) || version_compare(self::$active_version, WC_Subscriptions::$version, '<') && 'true' != get_transient('wc_subscriptions_is_upgrading')) {
         // If an admin hits the front of the site, run the updates, otherwise, run it as soon as someone hits the backend
         if (current_user_can('update_plugins')) {
             add_action('init', __CLASS__ . '::upgrade', 1);
         } else {
             add_action('admin_init', __CLASS__ . '::upgrade', 1);
         }
     }
 }
 /**
  * Hooks upgrade function to init.
  *
  * @since 1.2
  */
 public static function init()
 {
     self::$active_version = get_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '0');
     self::$upgrade_limit = apply_filters('woocommerce_subscriptions_hooks_to_upgrade', 250);
     self::$about_page_url = admin_url('index.php?page=wcs-about&wcs-updated=true');
     if (isset($_POST['action']) && 'wcs_upgrade' == $_POST['action']) {
         add_action('wp_ajax_wcs_upgrade', __CLASS__ . '::ajax_upgrade', 10);
     } elseif (@current_user_can('activate_plugins')) {
         if ('true' == get_transient('wc_subscriptions_is_upgrading')) {
             self::upgrade_in_progress_notice();
         } elseif (isset($_GET['wcs_upgrade_step']) || version_compare(self::$active_version, WC_Subscriptions::$version, '<')) {
             // Run updates as soon as admin hits site
             add_action('init', __CLASS__ . '::upgrade', 11);
         } elseif (is_admin() && isset($_GET['page']) && 'wcs-about' == $_GET['page']) {
             add_action('admin_menu', __CLASS__ . '::updated_welcome_page');
         }
     }
 }
 /**
  * Hooks upgrade function to init.
  *
  * @since 1.2
  */
 public static function init()
 {
     self::$active_version = get_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '0');
     if ('true' == get_transient('wc_subscriptions_is_upgrading')) {
         self::upgrade_in_progress_notice();
     } elseif (isset($_GET['wcs_upgrade_step']) || version_compare(self::$active_version, WC_Subscriptions::$version, '<')) {
         // Run updates as soon as admin hits site
         if (@current_user_can('activate_plugins')) {
             add_action('init', __CLASS__ . '::upgrade', 1);
         }
     }
     // Maybe upgrade to WC 2.0 data structure (after WC has run it's upgrader)
     self::$is_wc_version_2 = version_compare(get_option('woocommerce_db_version'), '2.0', '>=');
     self::$updated_to_wc_2_0 = get_option('wcs_updated_to_wc_2_0', 'false');
     if (self::$is_wc_version_2 && 'true' != self::$updated_to_wc_2_0) {
         if (@current_user_can('update_plugins')) {
             add_action('init', __CLASS__ . '::upgrade_to_latest_wc', 2);
         } else {
             add_action('admin_init', __CLASS__ . '::upgrade_to_latest_wc', 2);
         }
     }
 }