Clean up on the wp cron for this plugin.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Aug 2016 13:28:51 +0000 (09:28 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Aug 2016 13:28:51 +0000 (09:28 -0400)
If you deactivate this plugin it will go through and clear the cron
schedules for this plugin.
If you activate the plugin it will also go through and reset the cron
needed for any ical feeds.

activate.php
deactivate.php

index 00cd105..5d1ed58 100644 (file)
@@ -31,6 +31,7 @@ if (!defined('ABSPATH')) {
     die("Please do not call this code directly!");
 }
 
+require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataFeedImport.php';
 /*
  * This class performs all necessary additional work when this
  * plugin is activated.
@@ -83,7 +84,20 @@ class glmMembersEventsPluginActivate
         update_option('glmMembersDatabaseEventsPluginVersion', GLM_MEMBERS_EVENTS_PLUGIN_VERSION);
 
         // Set Roles and Capabilities for this plugin
-        require_once(GLM_MEMBERS_EVENTS_PLUGIN_SETUP_PATH.'/rolesAndCapabilities.php');
+        require_once GLM_MEMBERS_EVENTS_PLUGIN_SETUP_PATH . '/rolesAndCapabilities.php';
+        $this->create_cron_schedules();
+    }
+
+    public function create_cron_schedules()
+    {
+        $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config );
+        $import_feeds = $importFeeds->getList();
+        if ( $import_feeds ) {
+            foreach ( $import_feeds as $key => &$feed ) {
+                // check the next run time
+                wp_schedule_event( time(), GLM_MEMBERS_EVENTS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( (int)$feed['id'] ) );
+            }
+        }
     }
 
     /*
index 76887aa..74ef441 100644 (file)
@@ -30,6 +30,7 @@ if (!defined('ABSPATH')) {
     die("Please do not call this code directly!");
 }
 
+require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataFeedImport.php';
 /*
  * This class performs all necessary additional work when this
  * plugin is deactivated.
@@ -68,6 +69,21 @@ class glmMembersEventsPluginDeactivate
 
         // Delete our version from WordPress Options
         delete_option('glmMembersDatabaseEventsPluginVersion');
+        $this->clear_cron_schedules();
+    }
+
+    public function clear_cron_schedules()
+    {
+        // clear the cron schedule for this plugin
+        wp_clear_scheduled_hook( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT );
+        $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config );
+        $import_feeds = $importFeeds->getList();
+        if ( $import_feeds ) {
+            foreach ( $import_feeds as $key => &$feed ) {
+                // check the next run time
+                wp_clear_scheduled_hook( GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( (int)$feed['id'] ) );
+            }
+        }
     }
 
 }