/**
  * Prepare object.
  *
  * @since  1.0.0
  */
 public function __construct()
 {
     do_action('ms_model_plugin_constructor', $this);
     // Upgrade membership database if needs to.
     MS_Model_Upgrade::init();
     /*
      * Create our own copy of the full admin menu to be used in the
      * Membership2 settings.
      *
      * These hooks are only executed in the admin side.
      */
     $this->add_action('_network_admin_menu', 'store_admin_menu', 1);
     $this->add_action('_user_admin_menu', 'store_admin_menu', 1);
     $this->add_action('_admin_menu', 'store_admin_menu', 1);
     $this->add_action('network_admin_menu', 'store_admin_menu', 99999);
     $this->add_action('user_admin_menu', 'store_admin_menu', 99999);
     $this->add_action('admin_menu', 'store_admin_menu', 99999);
     // Register all Add-ons and load rules BEFORE the user is initialized.
     $this->add_action('ms_load_member', 'load_addons', 1);
     $this->add_action('ms_load_member', 'load_rules', 1);
     // Setup the page protection AFTER the user was initialized.
     $this->add_action('ms_init_done', 'setup_rules', 1);
     $this->add_action('ms_init_done', 'setup_protection', 2);
     $this->add_action('ms_init_done', 'setup_admin_protection', 3);
     /*
      * Some plugins (such as MarketPress) can trigger the set_current_user
      * action hook before this object is initialized. To ensure correct
      * loading order we use the `init` hook, which is called directly after
      * the correct set_current_user call.
      *
      * Most of the plugin logic requires the current user to be known,
      * that's why we do a explicit check here to make sure we have a valid
      * user.
      */
     // Initialize the current member
     $this->run_action('init', 'init_member', 1);
     /*
      * ******************************************************************* *
      *   Hooks below are only set up when Content Protection is enabled
      * ******************************************************************* *
      */
     if (!MS_Plugin::is_enabled()) {
         return;
     }
     // Setup the CRON hooks.
     $this->run_action('init', 'setup_cron_services', 1);
     $this->add_filter('cron_schedules', 'cron_time_period');
     $this->add_filter('ms_run_cron_services', 'run_cron_services');
     $this->add_action('ms_cron_check_membership_status', 'check_membership_status');
     $this->add_action('template_redirect', 'protect_current_page', 1);
     // Init gateways and communications to register actions/filters
     $this->run_action('init', array('MS_Model_Gateway', 'get_gateways'), 2);
     $this->run_action('init', array('MS_Model_Communication', 'init'), 2);
 }
 /**
  * Prepare object.
  *
  * @since  1.0.0
  */
 public function __construct()
 {
     do_action('ms_model_plugin_constructor', $this);
     /**
      * Define MS_PROCESS_PER_BATCH, set the number of members will be processed per batch
      *
      * Default value is 500
      */
     if (defined('MS_PROCESS_PER_BATCH') && MS_PROCESS_PER_BATCH) {
         $this->_process_per_batch = intval(MS_PROCESS_PER_BATCH);
     }
     // Upgrade membership database if needs to.
     MS_Model_Upgrade::init();
     /*
      * Create our own copy of the full admin menu to be used in the
      * Membership2 settings.
      *
      * These hooks are only executed in the admin side.
      */
     $this->add_action('_network_admin_menu', 'store_admin_menu', 1);
     $this->add_action('_user_admin_menu', 'store_admin_menu', 1);
     $this->add_action('_admin_menu', 'store_admin_menu', 1);
     $this->add_action('network_admin_menu', 'store_admin_menu', 99999);
     $this->add_action('user_admin_menu', 'store_admin_menu', 99999);
     $this->add_action('admin_menu', 'store_admin_menu', 99999);
     // Register all Add-ons and load rules BEFORE the user is initialized.
     $this->add_action('ms_load_member', 'load_addons', 1);
     $this->add_action('ms_load_member', 'load_rules', 1);
     // Setup the page protection AFTER the user was initialized.
     $this->add_action('ms_init_done', 'setup_rules', 1);
     $this->add_action('ms_init_done', 'setup_protection', 2);
     $this->add_action('ms_init_done', 'setup_admin_protection', 3);
     /*
      * Some plugins (such as MarketPress) can trigger the set_current_user
      * action hook before this object is initialized. To ensure correct
      * loading order we use the `init` hook, which is called directly after
      * the correct set_current_user call.
      *
      * Most of the plugin logic requires the current user to be known,
      * that's why we do a explicit check here to make sure we have a valid
      * user.
      */
     // Initialize the current member
     $this->run_action('init', 'init_member', 11);
     // Load AFTER the default hook.
     /*
      * ******************************************************************* *
      *   Hooks below are only set up when Content Protection is enabled
      * ******************************************************************* *
      */
     if (!MS_Plugin::is_enabled()) {
         return;
     }
     // Setup the CRON hooks.
     $this->run_action('init', 'setup_cron_services', 1);
     $this->add_filter('cron_schedules', 'cron_time_period');
     $this->add_filter('ms_run_cron_services', 'run_cron_services');
     $this->add_action('ms_cron_check_membership_status', 'check_membership_status');
     $this->add_action('template_redirect', 'protect_current_page', 1);
     // Init gateways and communications to register actions/filters.
     $this->run_action('init', array('MS_Model_Gateway', 'get_gateways'), 2);
     $this->run_action('init', array('MS_Model_Communication', 'init'), 2);
     // Old plugin is enabled? Show a warning!
     if (class_exists('M_Membership')) {
         lib3()->ui->admin_message(__('<b>Warning</b>: The old version of the Membership plugin is active and causes conflicts with the new Membership 2 plugin. Please disable the old Membership plugin.', 'membership2'), 'red');
     }
 }