/**
  * 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);
 }
示例#2
0
 /**
  * Actions executed in plugin activation.
  *
  * @since  1.0.0
  */
 public function plugin_activation()
 {
     // Prevent recursion during plugin activation.
     $refresh = lib3()->session->get('refresh_url_rules');
     if ($refresh) {
         return;
     }
     // Update the Membership2 database entries after activation.
     MS_Model_Upgrade::update(true);
     do_action('ms_plugin_activation', $this);
 }
 /**
  * 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');
     }
 }
 /**
  * Display advanced setting forms that can be triggered via an URL param.
  *
  * @since  1.0.0
  *
  * @param  array $desc Array of items to display in the settings header.
  * @return array New Array of items to display. Might include a HTML form.
  */
 protected function advanced_forms($desc)
 {
     // A "Reset" button that can be added via URL param
     // Intentionally not translated (purpose is dev/testing)
     if (!empty($_GET['reset'])) {
         $reset_url = MS_Controller_Plugin::get_admin_url('settings', array('reset' => 1));
         $reset_url = esc_url_raw(add_query_arg(MS_Model_Upgrade::get_token('reset'), $reset_url));
         $cancel_url = esc_url_raw(remove_query_arg('reset'));
         $desc[] = sprintf('<div class="error" style="width:600px;margin:20px auto;text-align:center"><p><b>%1$s</b></p><hr />%2$s</div>', 'Careful: This will completely erase all your Membership2 settings and details!', sprintf('<form method="POST" action="%s" style="padding:20px 0">' . '<label style="line-height:28px">' . '<input type="checkbox" name="confirm" value="yes" /> Yes, reset everything!' . '</label><p>' . '<button class="button-primary">Do it!</button> ' . '<a href="%s" class="button">Cancel</a>' . '</p></form>', $reset_url, $cancel_url));
     }
     // A "Resore" button that can be added via URL param
     // Intentionally not translated (purpose is dev/testing)
     if (!empty($_GET['restore'])) {
         $restore_url = MS_Controller_Plugin::get_admin_url('settings', array('restore' => 1));
         $restore_url = esc_url_raw(add_query_arg(MS_Model_Upgrade::get_token('restore'), $restore_url));
         $cancel_url = esc_url_raw(remove_query_arg('restore'));
         $options = array();
         $files = lib3()->updates->plugin('membership2');
         $files = lib3()->updates->list_files('json');
         foreach ($files as $file) {
             $parts = explode('-', $file);
             if (3 == count($parts)) {
                 $version = str_replace('upgrade_', '', $parts[0]);
                 $version = str_replace('_', '.', $version);
                 $date = substr($parts[1], 0, 4) . '-' . substr($parts[1], 4, 2) . '-' . substr($parts[1], 6, 2);
                 $time = substr($parts[2], 0, 2) . ':' . substr($parts[2], 2, 2) . ':' . substr($parts[2], 4, 2);
                 $label = sprintf('%2$s (%3$s) - Upgrade to %1$s', $version, $date, $time);
             } else {
                 $label = $file;
             }
             $options[$label] = sprintf('<option value="%1$s">%2$s</option>', $file, $label);
         }
         krsort($options);
         $desc[] = sprintf('<div class="error" style="width:600px;margin:20px auto;text-align:center"><p><b>%1$s</b></p><hr />%2$s</div>', 'Careful: This will overwrite and replace existing data with old data from the Snapshot!', sprintf('<form method="POST" action="%s" style="padding:20px 0">' . '<label style="line-height:28px">Snapshot:</label><p>' . '<select name="restore_snapshot">' . implode('', $options) . '</select>' . '</p><label style="line-height:28px">' . '<input type="checkbox" name="confirm" value="yes" /> Yes, overwrite data!' . '</label><p>' . '<button class="button-primary">Do it!</button> ' . '<a href="%s" class="button">Cancel</a>' . '</p></form>', $restore_url, $cancel_url));
     }
     return $desc;
 }