/**
     * Unschedule possibly previously scheduled task(s)
     * 
     * @access public
     * @param string $hook
     * @param int $subscription_id
     * @param int $timestamp
     * @return void
     */
    public static function unschedule($hook, $subscription_id = null, $timestamp = null)
    {
        // Specific single event?
        if ($timestamp) {

            // Match arguments?
            if ($subscription_id) {
                wp_unschedule_event($timestamp, $hook, array((int)$subscription_id));
            }
            else {
                wp_unschedule_event($timestamp, $hook);
            }
        }

        // All matching events?
        else {

            // Match arguments?
            if ($subscription_id) {
                wp_clear_scheduled_hook($hook, array((int)$subscription_id));
            }
            else {
                wp_clear_scheduled_hook($hook);
            }
        }
    }
Esempio n. 2
0
 /**
  * Unschedule the event
  *
  * @since 1.0
  */
 public function unschedule_event()
 {
     $timestamp = $this->get_next_scheduled();
     if ($timestamp !== false) {
         wp_unschedule_event($timestamp, self::$event_name);
     }
 }
function cart_product_deactivate_plugin()
{
    $next_refresh = wp_next_scheduled('update_cartfeeds_hook');
    if ($next_refresh) {
        wp_unschedule_event($next_refresh, 'update_cartfeeds_hook');
    }
}
 /**
  * Perform one-time operations on plugin deactivation.
  *
  * @since   1.0.0
  */
 public function plugin_deactivate()
 {
     // Remove version check.
     wp_unschedule_event(wp_next_scheduled('slack_notif_check_versions'), 'slack_notif_check_versions');
     // Remove settings from database.
     delete_option('slack_webhook_endpoint');
     delete_option('slack_channel_name');
     delete_option('slack_bot_username');
     delete_option('slack_bot_image');
     delete_option('slack_notif_core_update');
     delete_option('slack_notif_theme_update');
     delete_option('slack_notif_plugin_update');
     delete_option('slack_notif_new_post');
     delete_option('slack_notif_new_page');
     delete_option('slack_notif_new_comment');
     delete_option('slack_notif_new_user');
     delete_option('slack_notif_admin_logged');
     delete_option('slack_notif_core_version');
     delete_option('slack_notif_theme_version');
     delete_option('slack_notif_plugins_version');
     // Delte custom post types settings.
     foreach ($this->postTypes as $postType) {
         delete_option('slack_notif_new_' . $postType->name);
     }
 }
Esempio n. 5
0
function do_cron()
{
    # Lifted from wp-cron.php because it can't handle multiple blogs
    if (false === ($crons = _get_cron_array())) {
        print "no crons.\n";
        return;
    }
    $keys = array_keys($crons);
    $local_time = time();
    if (isset($keys[0]) && $keys[0] > $local_time) {
        print "not yet time.\n";
        return;
    }
    foreach ($crons as $timestamp => $cronhooks) {
        if ($timestamp > $local_time) {
            break;
        }
        foreach ($cronhooks as $hook => $keys) {
            foreach ($keys as $k => $v) {
                $schedule = $v['schedule'];
                if ($schedule != false) {
                    $new_args = array($timestamp, $schedule, $hook, $v['args']);
                    call_user_func_array('wp_reschedule_event', $new_args);
                }
                wp_unschedule_event($timestamp, $hook, $v['args']);
                print $hook . "... ";
                do_action_ref_array($hook, $v['args']);
            }
        }
    }
    # /end lifted from wp-cron.php
}
 /**
  * Sets up gateaway and adds relevant actions/filters
  */
 function __construct()
 {
     //Booking Interception
     if ($this->is_active() && absint(get_option('em_' . $this->gateway . '_booking_timeout')) > 0) {
         $this->count_pending_spaces = true;
     }
     parent::__construct();
     $this->status_txt = __('Awaiting PayPal Payment', 'em-pro');
     add_action('admin_enqueue_scripts', array(&$this, 'gateway_admin_js'));
     if ($this->is_active()) {
         add_action('em_gateway_js', array(&$this, 'em_gateway_js'));
         //Gateway-Specific
         add_action('em_template_my_bookings_header', array(&$this, 'say_thanks'));
         //say thanks on my_bookings page
         add_filter('em_bookings_table_booking_actions_4', array(&$this, 'bookings_table_actions'), 1, 2);
         //add_filter('em_my_bookings_booking_actions', array(&$this,'em_my_bookings_booking_actions'),1,2);
         //set up cron
         $timestamp = wp_next_scheduled('emp_paypal_cron');
         if (absint(get_option('em_paypal_booking_timeout')) > 0 && !$timestamp) {
             $result = wp_schedule_event(time(), 'em_minute', 'emp_paypal_cron');
         } elseif (!$timestamp) {
             wp_unschedule_event($timestamp, 'emp_paypal_cron');
         }
     } else {
         //unschedule the cron
         wp_clear_scheduled_hook('emp_paypal_cron');
     }
 }
 /**
  * Short Description. (use period)
  *
  * Long Description.
  *
  * @since    0.0.1
  */
 public static function deactivate()
 {
     // find out when the last event was scheduled
     $timestamp = wp_next_scheduled('market_exporter_daily');
     // unschedule previous event if any
     wp_unschedule_event($timestamp, 'market_exporter_daily');
 }
Esempio n. 8
0
function wp_clear_scheduled_hook($hook)
{
    $args = array_slice(func_get_args(), 1);
    while ($timestamp = wp_next_scheduled($hook, $args)) {
        wp_unschedule_event($timestamp, $hook, $args);
    }
}
/**
 * Remove plugin data from database
 */
function wpga_uninstallPlugin()
{
    /* Plugin main options */
    delete_option(WPGA_PREFIX . '_options');
    delete_option(WPGA_PREFIX . '_used_totp');
    $args = array('meta_query' => array('relation' => 'OR', array('key' => 'wpga_attempts', 'value' => '', 'compare' => '!='), array('key' => 'wpga_secret', 'value' => '', 'compare' => '!=')));
    $users = new WP_User_Query($args);
    /* Delete all user metas */
    if (!empty($users->results)) {
        foreach ($users->results as $key => $user) {
            delete_user_meta($user->ID, 'wpga_active');
            delete_user_meta($user->ID, 'wpga_attempts');
            delete_user_meta($user->ID, 'wpga_secret');
            delete_user_meta($user->ID, 'wpga_backup_key');
            delete_user_meta($user->ID, 'wpga_backup_key_time');
            delete_user_meta($user->ID, 'wpga_apps_passwords');
            delete_user_meta($user->ID, 'wpga_apps_passwords_log');
        }
    }
    /**
     * Remove cron task
     */
    $timestamp = wp_next_scheduled('wpas_clean_totps');
    wp_unschedule_event($timestamp, 'wpas_clean_totps');
}
function rm_stop_cron()
{
    if (wp_next_scheduled('rm_job_hook')) {
        wp_unschedule_event(wp_next_scheduled('rm_job_hook'), 'rm_job_hook');
        //error_log("stopped batch!");
    }
}
 /**
  * On an early action hook, check if the hook is scheduled - if not, schedule it.
  *
  * @version 2.5.7
  * @since   2.5.7
  */
 function schedule_the_events()
 {
     $update_intervals = array('minutely', 'hourly', 'twicedaily', 'daily', 'weekly');
     $total_number = apply_filters('booster_get_option', 1, get_option('wcj_products_xml_total_files', 1));
     for ($i = 1; $i <= $total_number; $i++) {
         $event_hook = 'wcj_create_products_xml_hook_' . $i;
         if ('yes' === get_option('wcj_products_xml_enabled_' . $i, 'yes')) {
             $selected_interval = apply_filters('booster_get_option', 'weekly', get_option('wcj_create_products_xml_period_' . $i, 'weekly'));
             foreach ($update_intervals as $interval) {
                 $event_timestamp = wp_next_scheduled($event_hook, array($interval, $i));
                 if ($selected_interval === $interval) {
                     update_option('wcj_create_products_xml_cron_time_' . $i, $event_timestamp);
                 }
                 if (!$event_timestamp && $selected_interval === $interval) {
                     wp_schedule_event(time(), $selected_interval, $event_hook, array($selected_interval, $i));
                 } elseif ($event_timestamp && $selected_interval !== $interval) {
                     wp_unschedule_event($event_timestamp, $event_hook, array($interval, $i));
                 }
             }
         } else {
             // unschedule all events
             update_option('wcj_create_products_xml_cron_time_' . $i, '');
             foreach ($update_intervals as $interval) {
                 $event_timestamp = wp_next_scheduled($event_hook, array($interval, $i));
                 if ($event_timestamp) {
                     wp_unschedule_event($event_timestamp, $event_hook, array($interval, $i));
                 }
             }
         }
     }
 }
Esempio n. 12
0
 /**
  * Unschedule License cron
  */
 public function unschedule()
 {
     $timestamp = wp_next_scheduled('license_wp_license_expiring_email');
     // unschedule
     if (false !== $timestamp) {
         wp_unschedule_event($timestamp, 'license_wp_license_expiring_email');
     }
 }
Esempio n. 13
0
 /**
  * Clear a schedule for an account
  *
  * @param $account_id
  * @param $frequency
  */
 public function clear_schedule($account_id, $frequency)
 {
     $args = array('account_id' => $account_id, 'frequency' => 'schedule', 'schedule' => $frequency);
     $timestamp = wp_next_scheduled('igp_scheduled_post_account', $args);
     if ($timestamp) {
         wp_unschedule_event($timestamp, 'igp_scheduled_post_account', $args);
     }
 }
Esempio n. 14
0
function amen_unschedule_crons()
{
    $crons = _get_cron_array();
    foreach ($crons as $time => $cron_data) {
        foreach ($cron_data as $cron_event => $data) {
            'amenemailprayers' == $cron_event ? wp_unschedule_event($time, $cron_event) : FALSE;
        }
    }
}
Esempio n. 15
0
function vidtrial_update_cron()
{
    $frequency = get_option('vidtrial_schedule_freq');
    if (!$frequency) {
        $frequency = "daily";
    }
    $timestamp = wp_next_scheduled("vidtrial_cron_schedule_hook");
    if ($timestamp !== false) {
        wp_unschedule_event($timestamp, "vidtrial_cron_schedule_hook");
    }
    wp_schedule_event(time(), $frequency, "vidtrial_cron_schedule_hook");
}
Esempio n. 16
0
 public function yop_poll_setup_schedule()
 {
     $schedule_timestamp = wp_next_scheduled('yop_poll_hourly_event', array());
     $yop_poll_options = get_option('yop_poll_options', false);
     if ('yes' == $yop_poll_options['start_scheduler']) {
         if (!$schedule_timestamp) {
             wp_schedule_event(strtotime(substr(current_time('mysql'), 0, 14) . '00:01'), 'hourly', 'yop_poll_hourly_event', array());
         }
     } else {
         wp_unschedule_event($schedule_timestamp, 'yop_poll_hourly_event', array());
     }
 }
 public static function doSetup()
 {
     add_filter('cron_schedules', 'add_xml_refresh_interval');
     //Delete old (faulty) scheduled cron job from prior versions
     $next_refresh = wp_next_scheduled('the_name_of_my_custom_interval');
     if ($next_refresh) {
         wp_unschedule_event($next_refresh, 'the_name_of_my_custom_interval');
     }
     $next_refresh = wp_next_scheduled('purple_xml_updatefeeds_hook');
     if ($next_refresh) {
         wp_unschedule_event($next_refresh, 'purple_xml_updatefeeds_hook');
     }
 }
Esempio n. 18
0
 /**
  * Perform one-time operations on plugin deactivation.
  */
 public function plugin_deactivate()
 {
     // Remove version check.
     wp_unschedule_event(wp_next_scheduled('slack_workshop_check_versions'), 'slack_workshop_check_versions');
     // Remove settings from database.
     delete_option('slack_workshop_webhook_endpoint');
     delete_option('slack_workshop_channel_name');
     delete_option('slack_workshop_user_name');
     delete_option('slack_workshop_channel_token');
     // Delete custom post types settings.
     foreach ($this->postTypes as $postType) {
         delete_option('slack_workshop_notif_new_' . $postType->name);
     }
 }
Esempio n. 19
0
 function zoo_on_deactivation()
 {
     // unschedule cron jobs
     // Get the timestamp for the next event.
     $timestamp = wp_next_scheduled('zoo_classified_import');
     wp_unschedule_event($timestamp, 'zoo_classified_import');
     wp_clear_scheduled_hook('zoo_classified_import');
     $timestamp = wp_next_scheduled('zoo_classified_backup');
     wp_unschedule_event($timestamp, 'zoo_classified_backup');
     wp_clear_scheduled_hook('zoo_classified_backup');
     $timestamp = wp_next_scheduled('zoo_delete_expired_classifieds');
     wp_unschedule_event($timestamp, 'zoo_delete_expired_classifieds');
     wp_clear_scheduled_hook('zoo_delete_expired_classifieds');
 }
 /**
  * On an early action hook, check if the hook is scheduled - if not, schedule it.
  *
  * @version 2.5.5
  */
 function schedule_the_events()
 {
     $selected_interval = get_option('wcj_currency_exchange_rates_auto', 'daily');
     foreach ($this->update_intervals as $interval => $desc) {
         $event_hook = 'auto_update_exchange_rates_hook';
         $event_timestamp = wp_next_scheduled($event_hook, array($interval));
         if ($selected_interval === $interval) {
             update_option('wcj_currency_exchange_rate_cron_time', $event_timestamp);
         }
         if (!$event_timestamp && $selected_interval === $interval) {
             wp_schedule_event(time(), $selected_interval, $event_hook, array($selected_interval));
         } elseif ($event_timestamp && $selected_interval !== $interval) {
             wp_unschedule_event($event_timestamp, $event_hook, array($interval));
         }
     }
 }
 /**
  * On an early action hook, check if the hook is scheduled - if not, schedule it.
  */
 function schedule_the_events()
 {
     $selected_interval = apply_filters('wcj_get_option_filter', 'manual', get_option('wcj_price_by_country_auto_exchange_rates', 'manual'));
     foreach ($this->update_intervals as $interval => $desc) {
         if ('manual' === $interval) {
             continue;
         }
         $event_hook = 'auto_update_exchange_rates_hook';
         //_' . $interval;
         $event_timestamp = wp_next_scheduled($event_hook, array($interval));
         if (!$event_timestamp && $selected_interval === $interval) {
             wp_schedule_event(time(), $selected_interval, $event_hook, array($selected_interval));
         } elseif ($event_timestamp && $selected_interval !== $interval) {
             wp_unschedule_event($event_timestamp, $event_hook, array($interval));
         }
     }
 }
Esempio n. 22
0
 function refresh_podcast($post_id, $post)
 {
     if ($this->is_refreshing || $post->post_type != 'podcast') {
         return;
     }
     $this->is_refreshing = true;
     $pu = new PublisherUpdater();
     $pu->update($post_id);
     $this->is_refreshing = false;
     /* Schedule auto-refresh */
     $action_name = 'recast_cron_' . $post_id;
     if (wp_next_scheduled($action_name)) {
         wp_unschedule_event(wp_next_scheduled($action_name), $action_name);
     }
     wp_schedule_event(time() + 3600, 'daily', $action_name);
     // Run again in an hour
 }
Esempio n. 23
0
 /**
  * Clears out given hook
  *
  * @param string $hookName
  */
 public static function unscheduleCronEvents($hookName = SUBSCRIBE_CRON)
 {
     $events = get_option('cron');
     error_reporting(0);
     if (!empty($events)) {
         foreach ($events as $time => $cron) {
             if (!empty($cron)) {
                 foreach ($cron as $hook => $dings) {
                     if ($hook == $hookName) {
                         foreach ($dings as $sig => $data) {
                             wp_unschedule_event($time, $hook, $data['args']);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 24
0
 /**
  * Makes sure Social CRONs are not scheduled more than once.
  *
  * @return void
  */
 public function action_check_crons()
 {
     // this is an internal only call, so manually calling URL decode
     if (urldecode($this->request->query('social_api_key')) != Social::option('system_cron_api_key')) {
         Social::log('API key failed');
         wp_die('Oops, invalid API key.');
     }
     $crons = _get_cron_array();
     $social_crons = array('15' => false);
     foreach ($crons as $timestamp => $_crons) {
         foreach ($_crons as $key => $cron) {
             foreach ($social_crons as $cron_key => $status) {
                 $event_key = 'social_cron_' . $cron_key . '_core';
                 if ($key == $event_key and $social_crons[$cron_key]) {
                     wp_unschedule_event($timestamp, $event_key);
                     Social::log('Unscheduled extra event: ' . $event_key);
                 } else {
                     $social_crons[$cron_key] = true;
                 }
             }
         }
     }
 }
 function save_setting()
 {
     $settings = maybe_unserialize(base64_decode($_POST['settings']));
     if (is_array($settings) && count($settings) > 0) {
         $result = array();
         $reload = '';
         $opts = $settings;
         $validUsers = array();
         $invalidUsers = array();
         foreach (explode(',', $opts['liveTraf_ignoreUsers']) as $val) {
             $val = trim($val);
             if (strlen($val) > 0) {
                 if (get_user_by('login', $val)) {
                     $validUsers[] = $val;
                 } else {
                     $invalidUsers[] = $val;
                 }
             }
         }
         if (count($invalidUsers) > 0) {
             // return array('errorMsg' => "The following users you selected to ignore in live traffic reports are not valid on this system: " . htmlentities(implode(', ', $invalidUsers)) );
             $result['invalid_users'] = htmlentities(implode(', ', $invalidUsers));
         }
         if (count($validUsers) > 0) {
             $opts['liveTraf_ignoreUsers'] = implode(',', $validUsers);
         } else {
             $opts['liveTraf_ignoreUsers'] = '';
         }
         if (!$opts['other_WFNet']) {
             $wfdb = new wfDB();
             global $wpdb;
             $p = $wpdb->base_prefix;
             $wfdb->queryWrite("delete from {$p}" . 'wfBlocks where wfsn=1 and permanent=0');
         }
         $regenerateHtaccess = false;
         if (wfConfig::get('bannedURLs', false) !== $opts['bannedURLs']) {
             $regenerateHtaccess = true;
         }
         foreach ($opts as $key => $val) {
             if (in_array($key, self::$options_filter)) {
                 if ('apiKey' !== $key) {
                     //Don't save API key yet
                     wfConfig::set($key, $val);
                 }
             }
         }
         if ($regenerateHtaccess) {
             wfCache::addHtaccessCode('add');
         }
         if ('1' === $opts['autoUpdate']) {
             wfConfig::enableAutoUpdate();
         } else {
             if ('0' === $opts['autoUpdate']) {
                 wfConfig::disableAutoUpdate();
             }
         }
         if (isset($opts['disableCodeExecutionUploads'])) {
             try {
                 if ($opts['disableCodeExecutionUploads']) {
                     wfConfig::disableCodeExecutionForUploads();
                 } else {
                     wfConfig::removeCodeExecutionProtectionForUploads();
                 }
             } catch (wfConfigException $e) {
                 return array('error' => $e->getMessage());
             }
         }
         if (isset($opts['email_summary_enabled'])) {
             if (!empty($opts['email_summary_enabled'])) {
                 wfConfig::set('email_summary_enabled', 1);
                 wfConfig::set('email_summary_interval', $opts['email_summary_interval']);
                 wfConfig::set('email_summary_excluded_directories', $opts['email_summary_excluded_directories']);
                 wfActivityReport::scheduleCronJob();
             } else {
                 wfConfig::set('email_summary_enabled', 0);
                 wfActivityReport::disableCronJob();
             }
         }
         $sch = isset($opts['scheduleScan']) ? $opts['scheduleScan'] : '';
         if (get_option('mainwp_child_wordfence_cron_time') !== $sch) {
             update_option('mainwp_child_wordfence_cron_time', $sch);
             $sched = wp_next_scheduled('mainwp_child_wordfence_cron_scan');
             if (false !== $sched) {
                 wp_unschedule_event($sched, 'mainwp_child_wordfence_cron_scan');
             }
         }
         $result['cacheType'] = wfConfig::get('cacheType');
         $result['paidKeyMsg'] = false;
         $apiKey = trim($_POST['apiKey']);
         if (!$apiKey) {
             //Empty API key (after trim above), then try to get one.
             $api = new wfAPI('', wfUtils::getWPVersion());
             try {
                 $keyData = $api->call('get_anon_api_key');
                 if ($keyData['ok'] && $keyData['apiKey']) {
                     wfConfig::set('apiKey', $keyData['apiKey']);
                     wfConfig::set('isPaid', 0);
                     $result['apiKey'] = $keyData['apiKey'];
                     $result['isPaid'] = 0;
                     $reload = 'reload';
                 } else {
                     throw new Exception("We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element.");
                 }
             } catch (Exception $e) {
                 $result['error'] = 'Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: ' . htmlentities($e->getMessage());
                 return $result;
             }
         } else {
             if (wfConfig::get('apiKey') !== $apiKey) {
                 $api = new wfAPI($apiKey, wfUtils::getWPVersion());
                 try {
                     $res = $api->call('check_api_key', array(), array());
                     if ($res['ok'] && isset($res['isPaid'])) {
                         wfConfig::set('apiKey', $apiKey);
                         wfConfig::set('isPaid', $res['isPaid']);
                         //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
                         $result['apiKey'] = $apiKey;
                         $result['isPaid'] = $res['isPaid'];
                         if ($res['isPaid']) {
                             $result['paidKeyMsg'] = true;
                         }
                         $reload = 'reload';
                     } else {
                         throw new Exception('We could not understand the Wordfence API server reply when updating your API key.');
                     }
                 } catch (Exception $e) {
                     $result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities($e->getMessage());
                     return $result;
                 }
             } else {
                 try {
                     $api = new wfAPI($apiKey, wfUtils::getWPVersion());
                     $res = $api->call('ping_api_key', array(), array());
                 } catch (Exception $e) {
                     $result['error'] = 'Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities($e->getMessage());
                     return $result;
                 }
             }
         }
         $result['ok'] = 1;
         $result['reload'] = $reload;
         return $result;
     }
 }
Esempio n. 26
0
 */
if ($doing_cron_transient != $doing_wp_cron) {
    return;
}
foreach ($crons as $timestamp => $cronhooks) {
    if ($timestamp > $gmt_time) {
        break;
    }
    foreach ($cronhooks as $hook => $keys) {
        foreach ($keys as $k => $v) {
            $schedule = $v['schedule'];
            if ($schedule != false) {
                $new_args = array($timestamp, $schedule, $hook, $v['args']);
                call_user_func_array('wp_reschedule_event', $new_args);
            }
            wp_unschedule_event($timestamp, $hook, $v['args']);
            /**
             * Fires scheduled events.
             *
             * @ignore
             * @since 2.1.0
             *
             * @param string $hook Name of the hook that was scheduled to be fired.
             * @param array  $args The arguments to be passed to the hook.
             */
            do_action_ref_array($hook, $v['args']);
            // If the hook ran too long and another cron process stole the lock, quit.
            if (_get_cron_lock() != $doing_wp_cron) {
                return;
            }
        }
 protected function handleFbaCronSettings($schedule)
 {
     WPLA()->logger->info("handleFbaCronSettings( {$schedule} )");
     // remove scheduled event
     $timestamp = wp_next_scheduled('wpla_fba_report_schedule');
     wp_unschedule_event($timestamp, 'wpla_fba_report_schedule');
     if (!wp_next_scheduled('wpla_fba_report_schedule')) {
         wp_schedule_event(time(), $schedule, 'wpla_fba_report_schedule');
     }
 }
 /** 
  *	Unschedule the cron event on deactivation.
  *
  *	@author		Nate Jacobs
  *	@date		9/14/14
  *	@since		1.1
  */
 public function deactivation()
 {
     // make sure the user can activate/deactivate plugins
     if (!current_user_can('activate_plugins')) {
         return;
     }
     // get the name of the plugin
     $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
     // make sure it is a valid request
     check_admin_referer("deactivate-plugin_{$plugin}");
     // unschedule the cron event
     wp_unschedule_event(wp_next_scheduled('tng_wp_rss_update'), 'tng_wp_rss_update');
 }
 /**
  * Initialize the widget by setting localization, filters, and administration functions.
  *
  * @since	1.0.0
  */
 public function __construct()
 {
     // Load plugin text domain
     add_action('init', array($this, 'widget_textdomain'));
     // Upgrade check
     add_action('init', array($this, 'upgrade_check'));
     // Check location on template redirect
     add_action('template_redirect', array($this, 'is_single'));
     // Hook fired when a new blog is activated on WP Multisite
     add_action('wpmu_new_blog', array($this, 'activate_new_site'));
     // Notices check
     add_action('admin_notices', array($this, 'check_admin_notices'));
     // Create the widget
     parent::__construct('wpp', 'WordPress Popular Posts', array('classname' => 'popular-posts', 'description' => __('The most Popular Posts on your blog.', $this->plugin_slug)));
     // Get user options
     $this->user_settings = get_site_option('wpp_settings_config');
     if (!$this->user_settings) {
         add_site_option('wpp_settings_config', $this->default_user_settings);
         $this->user_settings = $this->default_user_settings;
     } else {
         $this->user_settings = $this->__merge_array_r($this->default_user_settings, $this->user_settings);
     }
     // Allow WP themers / coders to override data sampling status (active/inactive)
     $this->user_settings['tools']['sampling']['active'] = apply_filters('wpp_data_sampling', $this->user_settings['tools']['sampling']['active']);
     // Add the options page and menu item.
     add_action('admin_menu', array($this, 'add_plugin_admin_menu'));
     // Register admin styles and scripts
     add_action('admin_print_styles', array($this, 'register_admin_styles'));
     add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts'));
     add_action('admin_init', array($this, 'thickbox_setup'));
     // Register site styles and scripts
     if ($this->user_settings['tools']['css']) {
         add_action('wp_enqueue_scripts', array($this, 'register_widget_styles'));
     }
     add_action('wp_enqueue_scripts', array($this, 'register_widget_scripts'));
     // Add plugin settings link
     add_filter('plugin_action_links', array($this, 'add_plugin_settings_link'), 10, 2);
     // Set plugin directory
     $this->plugin_dir = plugin_dir_url(__FILE__);
     // Get blog charset
     $this->charset = get_bloginfo('charset');
     // Add ajax table truncation to wp_ajax_ hook
     add_action('wp_ajax_wpp_clear_data', array($this, 'clear_data'));
     // Add thumbnail cache truncation to wp_ajax_ hook
     add_action('wp_ajax_wpp_clear_thumbnail', array($this, 'clear_thumbnails'));
     // Add ajax hook for widget
     add_action('wp_ajax_wpp_get_popular', array($this, 'get_popular'));
     add_action('wp_ajax_nopriv_wpp_get_popular', array($this, 'get_popular'));
     // Check if images can be created
     if (extension_loaded('ImageMagick') || extension_loaded('GD') && function_exists('gd_info')) {
         // Enable thumbnail feature
         $this->thumbnailing = true;
         // Get available thumbnail size(s)
         $this->default_thumbnail_sizes = $this->__get_image_sizes();
     }
     // Set default thumbnail
     $this->default_thumbnail = $this->plugin_dir . "no_thumb.jpg";
     $this->default_user_settings['tools']['thumbnail']['default'] = $this->default_thumbnail;
     if (!empty($this->user_settings['tools']['thumbnail']['default'])) {
         $this->default_thumbnail = $this->user_settings['tools']['thumbnail']['default'];
     } else {
         $this->user_settings['tools']['thumbnail']['default'] = $this->default_thumbnail;
     }
     // Set uploads folder
     $wp_upload_dir = wp_upload_dir();
     $this->uploads_dir['basedir'] = $wp_upload_dir['basedir'] . "/" . $this->plugin_slug;
     $this->uploads_dir['baseurl'] = $wp_upload_dir['baseurl'] . "/" . $this->plugin_slug;
     if (!is_dir($this->uploads_dir['basedir'])) {
         if (!wp_mkdir_p($this->uploads_dir['basedir'])) {
             $this->uploads_dir['basedir'] = $wp_upload_dir['basedir'];
             $this->uploads_dir['baseurl'] = $wp_upload_dir['baseurl'];
         }
     }
     // qTrans plugin support
     if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
         $this->qTrans = true;
     }
     // Remove post/page prefetching!
     remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
     // Add the update hooks only if the logging conditions are met
     if (0 == $this->user_settings['tools']['log']['level'] && !is_user_logged_in() || 1 == $this->user_settings['tools']['log']['level'] || 2 == $this->user_settings['tools']['log']['level'] && is_user_logged_in()) {
         add_action('wp_head', array(&$this, 'print_ajax'));
         // Register views from everyone and/or connected users
         if (0 != $this->user_settings['tools']['log']['level']) {
             add_action('wp_ajax_update_views_ajax', array($this, 'update_views_ajax'));
         }
         // Register views from everyone and/or visitors only
         if (2 != $this->user_settings['tools']['log']['level']) {
             add_action('wp_ajax_nopriv_update_views_ajax', array($this, 'update_views_ajax'));
         }
     }
     // Add shortcode
     add_shortcode('wpp', array(&$this, 'shortcode'));
     // Purge post data from DB on deletion
     add_action('admin_init', array($this, 'purge_post_init'));
     // Enable data purging at midnight
     if (1 == $this->user_settings['tools']['log']['limit']) {
         add_action('wpp_cache_event', array($this, 'purge_data'));
         if (!wp_next_scheduled('wpp_cache_event')) {
             $tomorrow = time() + 86400;
             $midnight = mktime(0, 0, 0, date("m", $tomorrow), date("d", $tomorrow), date("Y", $tomorrow));
             wp_schedule_event($midnight, 'daily', 'wpp_cache_event');
         }
     } else {
         // Remove the scheduled event if exists
         if ($timestamp = wp_next_scheduled('wpp_cache_event')) {
             wp_unschedule_event($timestamp, 'wpp_cache_event');
         }
     }
 }
Esempio n. 30
0
 function setup_cron()
 {
     add_filter("simple_history/maybe_purge_db", array($this, "maybe_purge_db"));
     if (!wp_next_scheduled('simple_history/maybe_purge_db')) {
         wp_schedule_event(time(), 'daily', 'simple_history/maybe_purge_db');
         //error_log("not scheduled, so do schedule");
     } else {
         //error_log("is scheduled");
     }
     // Remove old schedule (only author dev sites should have it)
     $old_next_scheduled = wp_next_scheduled('simple_history/purge_db');
     if ($old_next_scheduled) {
         wp_unschedule_event($old_next_scheduled, 'simple_history/purge_db');
     }
 }