From: Steve Sutton Date: Thu, 25 Aug 2016 13:25:09 +0000 (-0400) Subject: Setup the cron task and make sure we cleaning up X-Git-Tag: v1.1.0^2~6^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=39bf8ba36a434fb73c90bba5af2589002c411a01;p=WP-Plugins%2Fglm-member-db-leads.git Setup the cron task and make sure we cleaning up Clean up by deactivate class. Deactivating the plugin will clear all cron tasks for this plugin. --- diff --git a/deactivate.php b/deactivate.php index eef378a..bc8c2da 100644 --- a/deactivate.php +++ b/deactivate.php @@ -56,6 +56,12 @@ class glmMembersLeadsPluginDeactivate // Delete our version from WordPress Options delete_option('glmMembersDatabaseLeadsPluginVersion'); + $this->clear_cron_schedules(); } + public function clear_cron_schedules() + { + wp_clear_scheduled_hook( GLM_MEMBERS_LEADS_PLUGIN_CRON_EVENT ); + } + } diff --git a/defines.php b/defines.php index afd677d..b28b20e 100644 --- a/defines.php +++ b/defines.php @@ -31,6 +31,10 @@ if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') { } define('GLM_MEMBERS_LEADS_PLUGIN_HTTP_PROTOCOL', $pageProtocol); +// Cron defines +define( 'GLM_MEMBERS_LEADS_PLUGIN_CRON_EVENT', 'glm_membersLeads_cron' ); +define( 'GLM_MEMBERS_LEADS_PLUGIN_CRON_RECURRANCE', 'twicedaily' ); + // Get various pieces of the URL $urlParts = parse_url(get_bloginfo('url')); $pageUri = explode('?', $_SERVER['REQUEST_URI']); // Bust this up to access URL path and script name only diff --git a/index.php b/index.php index 11763ba..fbcdd03 100644 --- a/index.php +++ b/index.php @@ -200,7 +200,7 @@ add_filter('glm-member-db-register-addon','glmMembersRegisterLeads', 10, 1); function glmMembersLeadsPluginDeactivate () { global $wpdb, $config; - require_once (GLM_MEMBERS_LEADS_PLUGIN_PATH . '/deactivate.php'); + require_once GLM_MEMBERS_LEADS_PLUGIN_PATH . '/deactivate.php'; $x = new glmMembersLeadsPluginDeactivate($wpdb, $config); return false; } @@ -232,3 +232,23 @@ class glm_member_db_leads_bootstrap { } } + +// Cron task to generate the Leads Stats +add_action( + GLM_MEMBERS_LEADS_PLUGIN_CRON_EVENT, + function( $id ) { + if ( $id ) { + $admin_url = admin_url(); + $ical_feed_import_url = $admin_url + . 'admin-ajax.php?action=glm_members_admin_ajax&glm_action=statCollector'; + $response = wp_remote_get( $ical_feed_import_url ); + $response_headers = wp_remote_retrieve_headers( $response ); + $response_body = wp_remote_retrieve_body( $response ); + } + }, + 10, + 1 +); +if ( !wp_next_scheduled( GLM_MEMBERS_LEADS_PLUGIN_CRON_EVENT ) ) { + wp_schedule_event( time(), GLM_MEMBERS_LEADS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_LEADS_PLUGIN_CRON_EVENT ); +}