/** * Reads the options from options table * * @since 1.0.0 */ public function refresh() { $option_key = $this->option_key(); $settings = MS_Factory::get_option($option_key); MS_Factory::populate_model($this, $settings); wp_cache_set($option_key, $this, 'MS_Model_Option'); }
/** * Checks, if some BuddyPress pages overlap with M2 membership pages. * * In some cases people used the same page-ID for both BuddyPress * registration and M2 registration. This will cause problems and must be * resolved to have M2 and BuddyPress work symbiotically. * * @since 1.0.1.1 */ protected function collission_check() { $buddy_pages = MS_Factory::get_option('bp-pages'); if (!is_array($buddy_pages)) { // Okay, no BuddyPress pages set up yet. return; } $duplicates = array(); foreach ($buddy_pages as $type => $page_id) { $collission = MS_Model_Pages::get_page_by('id', $page_id); if ($collission) { $title = $collission->post_title; if (!$title) { $title = $collission->post_name; } $duplicates[] = sprintf('%s - %s', $page_id, $title); } } if (count($duplicates)) { $msg = sprintf('%s<br><br>%s', sprintf(__('BuddyPress uses a page that is also used as a Membership page by Membership 2.<br>Please assign a different page for either %sMembership 2%s or %sBuddyPress%s to avoid conflicts.', 'membership2'), '<a href="' . MS_Controller_Plugin::get_admin_url('settings') . '">', '</a>', '<a href="' . admin_url('admin.php?page=bp-page-settings') . '">', '</a>'), implode('<br>', $duplicates)); lib3()->ui->admin_message($msg, 'error'); } }
/** * Check membership status. * * Execute actions when time/period condition are met. * E.g. change membership status, add communication to queue, create invoices. * * @since 1.0.0 */ public function check_membership_status() { do_action('ms_model_plugin_check_membership_status_before', $this); if ($this->member->is_simulated_user()) { return; } /* * For performance reasons we only process a small batch at once. * Here we find out, which subscriptions should be processed during * the current request. */ $offset = (int) MS_Factory::get_option('ms_batch_check_offset_flag'); // Find the next X subscriptions from DB. $args = apply_filters('ms_model_plugin_check_membership_status_get_subscription_args', array('status' => 'valid', 'orderby' => 'ID', 'posts_per_page' => $this->_process_per_batch, 'offset' => $offset, 'nopaging' => false)); $subscriptions = MS_Model_Relationship::get_subscriptions($args); if (count($subscriptions) < $this->_process_per_batch) { // We processed all subscriptions. Clean up. MS_Factory::delete_option('ms_batch_check_offset_flag'); } else { // We did not process all subscriptions. Remember where to continue. MS_Factory::update_option('ms_batch_check_offset_flag', $offset + $this->_process_per_batch); // Re-scheduling the cron job will run it again on next page load. $hook = 'ms_cron_check_membership_status'; wp_clear_scheduled_hook($hook); $this->setup_cron_services($hook); } // Perform the actual status checks! foreach ($subscriptions as $subscription) { error_log('This is ' . $subscription->id); $subscription->check_membership_status(); } do_action('ms_model_plugin_check_membership_status_after', $this); }