/** * Delete from wp option table * * @since 1.0.0 */ public function delete() { do_action('ms_model_option_delete_before', $this); $option_key = $this->option_key(); MS_Factory::delete_option($option_key); wp_cache_delete($option_key, 'MS_Model_Option'); do_action('ms_model_option_delete_after', $this); }
/** * 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); }