function wp33423_hotfix() { global $wp_version; /** * Disable this plugin from 4.3.1 */ if (1 !== version_compare("4.3.1", $wp_version) && current_user_can('activate_plugins')) { deactivate_plugins(plugin_basename(__FILE__)); } /** * Prevent 4.3 from messing up the cron array and options table */ remove_action('admin_init', '_wp_check_for_scheduled_split_terms'); /** * Clean the cron array after 4.3 messed it up */ $cron_array = _get_cron_array(); if (isset($cron_array['wp_batch_split_terms'])) { unset($cron_array['wp_batch_split_terms']); _set_cron_array($cron_array); } /** * In order to avoid the wp_batch_split_terms() job being accidentally removed, * check that it's still scheduled while we haven't finished splitting terms. */ if (!get_option('finished_splitting_shared_terms') && !wp_next_scheduled('wp_split_shared_term_batch')) { wp_schedule_single_event(time() + MINUTE_IN_SECONDS, 'wp_split_shared_term_batch'); } }
function pmpro_upgrade_1_8_7() { //fix cron jobs $jobs = _get_cron_array(); // Remove all pmpro cron jobs (for now). foreach ($jobs as $when => $job_array) { foreach ($job_array as $name => $job) { //delete pmpro cron if (false !== stripos($name, 'pmpro_cron')) { unset($jobs[$when][$name]); } } //delete empty cron time slots if (empty($jobs[$when])) { unset($jobs[$when]); } } // Save the data _set_cron_array($jobs); //add the three we want back pmpro_maybe_schedule_event(current_time('timestamp'), 'daily', 'pmpro_cron_expire_memberships'); pmpro_maybe_schedule_event(current_time('timestamp') + 1, 'daily', 'pmpro_cron_expiration_warnings'); pmpro_maybe_schedule_event(current_time('timestamp'), 'monthly', 'pmpro_cron_credit_card_expiring_warnings'); pmpro_setOption("db_version", "1.87"); return 1.87; }
function setUp() { parent::setUp(); wp_set_current_user(self::$editor_id); _set_cron_array(array()); $this->post_ids = array(); }
function setUp() { parent::setUp(); $this->author_id = $this->factory->user->create( array( 'role' => 'editor' ) ); $this->old_current_user = get_current_user_id(); wp_set_current_user( $this->author_id ); _set_cron_array(array()); $this->post_ids = array(); }
function wp_unschedule_event( $timestamp, $hook, $args = array() ) { $crons = _get_cron_array(); $key = md5(serialize($args)); unset( $crons[$timestamp][$hook][$key] ); if ( empty($crons[$timestamp][$hook]) ) unset( $crons[$timestamp][$hook] ); if ( empty($crons[$timestamp]) ) unset( $crons[$timestamp] ); _set_cron_array( $crons ); }
/** Remove all schedules */ public function remove_schedules() { $cron = _get_cron_array(); foreach ($cron as $timestamp => $schedule) { if (!isset($schedule['gf_digest_send_notifications'])) { continue; } unset($cron[$timestamp]['gf_digest_send_notifications']); if (empty($cron[$timestamp])) { unset($cron[$timestamp]); } } _set_cron_array($cron); }
/** * Unschedule an event by hook name * * @see https://core.trac.wordpress.org/ticket/18997#comment:23 * @since 1.0.5 * @return void */ public static function unschedule_event($hook) { $crons = _get_cron_array(); if (empty($crons)) { return; } foreach ($crons as $timestamp => $cron) { if (!empty($cron[$hook])) { unset($crons[$timestamp][$hook]); } if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } } _set_cron_array($crons); }
public static function clear($hook) { $crons = _get_cron_array(); if (empty($crons)) { return; } foreach ($crons as $timestamp => $cron) { if (!empty($cron[$hook])) { unset($crons[$timestamp][$hook]); // Unset empty timestamps if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } } } return _set_cron_array($crons); }
/** * Update subscription WP-Cron tasks to Action Scheduler. * * @since 2.0 */ public static function upgrade_hooks($number_hooks_to_upgrade) { $counter = 0; $cron = _get_cron_array(); foreach ($cron as $timestamp => $actions) { foreach ($actions as $hook => $details) { if ('scheduled_subscription_payment' == $hook || 'scheduled_subscription_expiration' == $hook || 'scheduled_subscription_end_of_prepaid_term' == $hook || 'scheduled_subscription_trial_end' == $hook || 'paypal_check_subscription_payment' == $hook) { foreach ($details as $hook_key => $values) { if (!wc_next_scheduled_action($hook, $values['args'])) { wc_schedule_single_action($timestamp, $hook, $values['args']); unset($cron[$timestamp][$hook][$hook_key]); $counter++; } if ($counter >= $number_hooks_to_upgrade) { break; } } // If there are no other jobs scheduled for this hook at this timestamp, remove the entire hook if (0 == count($cron[$timestamp][$hook])) { unset($cron[$timestamp][$hook]); } if ($counter >= $number_hooks_to_upgrade) { break; } } } // If there are no actions schedued for this timestamp, remove the entire schedule if (0 == count($cron[$timestamp])) { unset($cron[$timestamp]); } if ($counter >= $number_hooks_to_upgrade) { break; } } // Set the cron with the removed schedule _set_cron_array($cron); return $counter; }
function tearDown() { parent::tearDown(); // make sure the schedule is clear _set_cron_array(array()); }
/** * @param int $timestamp Timestamp for when to run the event. * @param string $hook Action hook to execute when cron is run. * @param array $args Optional. Arguments to pass to the hook's callback function. */ public function cron_schedule_single_event($timestamp, $hook, $args = array()) { // don't schedule a duplicate if there's already an identical event due in the next 10 minutes $next = cron_next_scheduled($hook, $args); if ($next && $next <= $timestamp + 600) { return; } $crons = _get_cron_array(); $key = md5(serialize($args)); $crons[$timestamp][$hook][$key] = array('schedule' => false, 'args' => $args); uksort($crons, "strnatcasecmp"); _set_cron_array($crons); }
static function refresh_cron() { if (!extension_loaded('suhosin')) { @ini_set('memory_limit', -1); } // Remove all cron jobs created by NextGEN Gallery $cron = _get_cron_array(); if (is_array($cron)) { foreach ($cron as $timestamp => $job) { if (is_array($job)) { unset($cron[$timestamp]['ngg_delete_expired_transients']); if (empty($cron[$timestamp])) { unset($cron[$timestamp]); } } } } _set_cron_array($cron); }
/** * * * @desc Clean cron array */ private function _clean_cron_array() { //retrive all crons $crons = _get_cron_array(); if (!is_array($crons)) { return; } $local_time = microtime(true); $doing_wp_cron = sprintf('%.22F', $local_time); set_transient('doing_cron', $doing_wp_cron); foreach ($crons as $timestamp => $cronhooks) { foreach ($cronhooks as $hook => $keys) { if ($hook == $this->_hook) { unset($crons[$timestamp][$hook]); } } if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } } //update cron with new array _set_cron_array($crons); delete_transient('doing_cron'); }
/** * Unschedule a previously scheduled cron job using job key. * * @param int $timestamp timestamp for when to run the event. * @param string $hook action hook, the execution of which will be unscheduled. * @param string $key key for arguments to identify the event. */ function gd_unschedule_event($timestamp, $hook, $key) { $crons = _get_cron_array(); unset($crons[$timestamp][$hook][$key]); if (empty($crons[$timestamp][$hook])) { unset($crons[$timestamp][$hook]); } if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } _set_cron_array($crons); }
/** * Unschedule a previously scheduled cron job. * * The $timestamp and $hook parameters are required, so that the event can be * identified. * * @since 2.1.0 * * @param int $timestamp Timestamp for when to run the event. * @param string $hook Action hook, the execution of which will be unscheduled. * @param array $args Arguments to pass to the hook's callback function. * Although not passed to a callback function, these arguments are used * to uniquely identify the scheduled event, so they should be the same * as those used when originally scheduling the event. * @return false|void False when an event is not unscheduled. */ function wp_unschedule_event($timestamp, $hook, $args = array()) { // Make sure timestamp is a positive integer if (!is_numeric($timestamp) || $timestamp <= 0) { return false; } $crons = _get_cron_array(); $key = md5(serialize($args)); unset($crons[$timestamp][$hook][$key]); if (empty($crons[$timestamp][$hook])) { unset($crons[$timestamp][$hook]); } if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } _set_cron_array($crons); }
public function removeAllQueuedMetricsUpdates() { $crons = _get_cron_array(); if (!empty($crons)) { foreach ($crons as $timestamp => $cron) { // Remove single post updates if (!empty($cron['easy_social_metrics_update_single_post'])) { unset($crons[$timestamp]['easy_social_metrics_update_single_post']); } // Remove full post updates if (!empty($cron['easy_social_metrics_lite_automatic_update'])) { unset($crons[$timestamp]['easy_social_metrics_lite_automatic_update']); } } _set_cron_array($crons); wp_clear_scheduled_hook('easy_social_metrics_update_single_post'); wp_clear_scheduled_hook('easy_social_metrics_lite_automatic_update'); } return; }
public static function clear_all_cache() { // clear update transients delete_site_transient('update_plugins'); delete_site_transient('update_themes'); delete_transient('wprc_update_repositories'); delete_transient('wprc_update_extensions_maps'); // clean cache $rmcache = WPRC_Loader::getModel('cached-requests'); $rmcache->cleanCache(); // clear crons $crons = _get_cron_array(); foreach ($crons as $key => $job) { if (isset($job['wprc_schedule_update_plugins'])) { unset($crons[$key]); } if (isset($job['wprc_schedule_update_themes'])) { unset($crons[$key]); } } _set_cron_array($crons); }
/** * Remove the currently-existing and now-removed cron tasks. * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones */ public static function remove_cron_tasks($remove_all = true) { $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; $crons = _get_cron_array(); $crons = is_array($crons) ? $crons : array(); /* reminder that $crons looks like: top-level keys are timestamps, * and their values are arrays. * The 2nd level arrays have keys with each of the cron task hooknames to run at that time * and their values are arrays. * The 3rd level level arrays are keys which are hashes of the cron task's arguments, * and their values are the UN-hashed arguments * eg * array (size=13) * 1429903276 => * array (size=1) * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => * array (size=1) * '561299d6e42c8e079285870ade0e47e6' => * array (size=2) * ... * ... */ foreach (EEH_Activation::get_cron_tasks($cron_tasks_to_remove) as $hook_name => $frequency) { foreach ($crons as $timestamp => $hooks_to_fire_at_time) { if (array_key_exists($hook_name, $hooks_to_fire_at_time)) { unset($crons[$timestamp][$hook_name]); } } } _set_cron_array($crons); }
if (isset($_POST['restorecron']) && isset($_POST['restoretimestamp']) && get_option('cronsnapshot_' . intval($_POST['restoretimestamp']))) { update_option('cron', get_option('cronsnapshot_' . intval($_POST['restoretimestamp']))); } else { if (isset($_GET['timestamp']) && isset($_GET['hook']) && isset($_GET['action']) && $_GET['action'] == 'deletecron') { $crons = _get_cron_array(); $timestamp = intval($_GET['timestamp']); $hook = $_GET['hook']; unset($crons[$timestamp][$hook]); _set_cron_array($crons); echo $timestamp . $hook; foreach ($crons as $timestamp => $content) { if (sizeof($content) == 0) { unset($crons[$timestamp]); } } _set_cron_array($crons); die; } else { if (isset($_GET['snapshottimestamp']) && isset($_GET['action']) && $_GET['action'] == 'deletesnapshot') { $optionname = 'cronsnapshot_' . $_GET['snapshottimestamp']; delete_option($optionname); echo $optionname; } else { $snapshot_count = $wpdb->get_results("SELECT COUNT(*) snapshots FROM {$wpdb->options} WHERE option_name LIKE '%cronsnapshot_%'"); if (!$snapshot_count) { add_option('cronsnapshot_' . $curtime, get_option('cron')); } } } } }
public function st_uninstall($upgrade = NULL) { global $wpdb; if ($upgrade == NULL) { $table_name = $wpdb->prefix . "st_social_widgets"; $wpdb->query('DROP TABLE `' . $table_name . '`'); delete_option('st_template_twitter_noti'); // General Settings delete_option('st_include_in_posts'); delete_option('st_noti_twitter'); delete_option('st_noti_twitter_user'); delete_option('st_twitter_apikey'); // bit.ly delete_option('st_bitly_user'); delete_option('st_bitly_apikey'); delete_option('st_url_shortening_service'); // Advanced options delete_option('st_enable_api'); delete_option('st_hide_donate'); delete_option('st_extend_php_limits'); delete_option('st_css_sheet'); delete_option('st_consumer_key'); delete_option('st_consumer_secret'); // House Keeping delete_option('st_current_version'); } // Can get messy. _set_cron_array(NULL); }
/** * Execute changes as required by PN post WP 4.3.0. * * @since 4.3.1 */ function upgrade_431() { // Fix incorrect cron entries for term splitting $cron_array = _get_cron_array(); if (isset($cron_array['wp_batch_split_terms'])) { unset($cron_array['wp_batch_split_terms']); _set_cron_array($cron_array); } update_option('finished_splitting_shared_terms', false); }
/** * Move scheduled subscription hooks out of wp-cron and into the new Action Scheduler. * * Also set all existing subscriptions to "sold individually" to maintain previous behavior * for existing subscription products before the subscription quantities feature was enabled.. * * @since 1.5 */ public static function ajax_upgrade() { global $wpdb; @set_time_limit(600); @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); set_transient('wc_subscriptions_is_upgrading', 'true', 60 * 2); if ('really_old_version' == $_POST['upgrade_step']) { $database_updates = ''; if ('0' != self::$active_version && version_compare(self::$active_version, '1.2', '<')) { self::upgrade_database_to_1_2(); self::generate_renewal_orders(); update_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '1.2'); $database_updates = '1.2, '; } // Add Variable Subscription product type term if ('0' != self::$active_version && version_compare(self::$active_version, '1.3', '<')) { self::upgrade_database_to_1_3(); update_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '1.3'); $database_updates .= '1.3 & '; } // Moving subscription meta out of user meta and into item meta if ('0' != self::$active_version && version_compare(self::$active_version, '1.4', '<')) { self::upgrade_database_to_1_4(); update_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '1.4'); $database_updates .= '1.4.'; } $results = array('message' => sprintf(__('Database updated to version %s', 'woocommerce-subscriptions'), $database_updates)); } elseif ('products' == $_POST['upgrade_step']) { // Set status to 'sold individually' for all existing subscriptions that haven't already been updated $sql = "SELECT DISTINCT ID FROM {$wpdb->posts} as posts\n\t\t\t\tJOIN {$wpdb->postmeta} as postmeta\n\t\t\t\t\tON posts.ID = postmeta.post_id\n\t\t\t\t\tAND (postmeta.meta_key LIKE '_subscription%')\n\t\t\t\tJOIN {$wpdb->postmeta} AS soldindividually\n\t\t\t\t\tON posts.ID = soldindividually.post_id\n\t\t\t\t\tAND ( soldindividually.meta_key LIKE '_sold_individually' AND soldindividually.meta_value != 'yes' )\n\t\t\t\tWHERE posts.post_type = 'product'"; $subscription_product_ids = $wpdb->get_results($sql); foreach ($subscription_product_ids as $product_id) { update_post_meta($product_id->ID, '_sold_individually', 'yes'); } $results = array('message' => sprintf(__('Marked %s subscription products as "sold individually".', 'woocommerce-subscriptions'), count($subscription_product_ids))); } else { $counter = 0; $before_cron_update = microtime(true); // update all of the current Subscription cron tasks to the new Action Scheduler $cron = _get_cron_array(); foreach ($cron as $timestamp => $actions) { foreach ($actions as $hook => $details) { if ($hook == 'scheduled_subscription_payment' || $hook == 'scheduled_subscription_expiration' || $hook == 'scheduled_subscription_end_of_prepaid_term' || $hook == 'scheduled_subscription_trial_end' || $hook == 'paypal_check_subscription_payment') { foreach ($details as $hook_key => $values) { if (!wc_next_scheduled_action($hook, $values['args'])) { wc_schedule_single_action($timestamp, $hook, $values['args']); unset($cron[$timestamp][$hook][$hook_key]); $counter++; } if ($counter >= self::$upgrade_limit) { break; } } // If there are no other jobs scheduled for this hook at this timestamp, remove the entire hook if (0 == count($cron[$timestamp][$hook])) { unset($cron[$timestamp][$hook]); } if ($counter >= self::$upgrade_limit) { break; } } } // If there are no actions schedued for this timestamp, remove the entire schedule if (0 == count($cron[$timestamp])) { unset($cron[$timestamp]); } if ($counter >= self::$upgrade_limit) { break; } } // Set the cron with the removed schedule _set_cron_array($cron); $results = array('upgraded_count' => $counter, 'message' => sprintf(__('Migrated %s subscription related hooks to the new scheduler (in {execution_time} seconds).', 'woocommerce-subscriptions'), $counter)); } if (isset($counter) && $counter < self::$upgrade_limit) { self::upgrade_complete(); } delete_transient('wc_subscriptions_is_upgrading'); header('Content-Type: application/json; charset=utf-8'); echo json_encode($results); exit; }
/** * @param string $name */ protected static function really_clear_scheduled_hook($name) { $crons = _get_cron_array(); foreach ($crons as $timestamp => $hooks) { foreach ($hooks as $hook => $args) { if ($hook == $name) { unset($crons[$timestamp][$hook]); } } if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } } _set_cron_array($crons); }
/** * Executes changes made in WordPress 4.3.1. * * @since 4.3.1 */ function upgrade_431() { // Fix incorrect cron entries for term splitting $cron_array = _get_cron_array(); if (isset($cron_array['wp_batch_split_terms'])) { unset($cron_array['wp_batch_split_terms']); _set_cron_array($cron_array); } }
/** * Sets up the plugin environment upon first activation. * * Run using the 'activate_' action. */ function action_activate() { $extra_scheds = array('twicedaily' => array('interval' => 43200, 'display' => __('Twice Daily', 'wp-crontrol'))); add_option('crontrol_schedules', $extra_scheds); // if there's never been a cron event, _get_cron_array will return FALSE if (_get_cron_array() === FALSE) { _set_cron_array(array()); } }
/** * Sets up the plugin environment upon first activation. * * Run using the 'activate_' action. */ public function action_activate() { add_option('crontrol_schedules', array()); // if there's never been a cron event, _get_cron_array will return false if (_get_cron_array() === false) { _set_cron_array(array()); } }
public function clear_all_crons($hook) { $crons = _get_cron_array(); if (empty($crons)) { return; } foreach ($crons as $timestamp => $cron) { if (!empty($cron[$hook])) { unset($crons[$timestamp][$hook]); if (empty($crons[$timestamp])) { unset($crons[$timestamp]); } } } _set_cron_array($crons); }
public function do_frequently() { global $wpdb; print "WPEngine Frequent Periodic Tasks: Start\n"; // Check for old wp-cron items that aren't clearing out. Has to be older than a certain // threshold because that means we've done several wp-cron attempts and it's not clearing. // Also only clear certain known problematic things which might be gumming up other non-problematic // things, e.g. Disqus was doing this as a known issue on Nicekicks. if (true) { $now = time(); $problematic_wp_cron_hooks = array('dsq_sync_post', 'dsq_sync_forum'); // bad types $problematic_wp_cron_age_secs = 60 * 60 * 2; // when older than this, delete the entries. $too_old = $now - $problematic_wp_cron_age_secs; // if scheduled timestamp older than this, it needs to be nuked. $crons = _get_cron_array(); if (!empty($crons)) { print "\tLoaded crons array, contains " . count($crons) . " entries.\n"; $changed_cron = FALSE; // did we make any changes? foreach ($crons as $timestamp => $cron) { if ($timestamp < $too_old) { // ancient! foreach ($problematic_wp_cron_hooks as $hook) { // only nuke these if (isset($crons[$timestamp][$hook])) { $changed_cron = true; print "\tRemoved old cron: {$hook}: {$timestamp}: age=" . ($now - $timestamp) . " s\n"; unset($crons[$timestamp][$hook]); } } if (empty($crons[$timestamp])) { // any timestamp with no hooks can always be deleted $changed_cron = true; unset($crons[$timestamp]); } } } if ($changed_cron) { // don't re-write cron unless something actually changed, otherwise *very* inefficient! print "\tRe-writing crons array, now contains " . count($crons) . " entries.\n"; _set_cron_array($crons); } } } // Check for "future" posts (i.e. scheduled) which missed the schedule. This happens on high-traffic // sites when in the middle of a cron job because there's just a single-shot cron event for that post. $sql = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s AND post_date_gmt < UTC_TIMESTAMP()", 'future'); $post_ids = $wpdb->get_col($sql); foreach ($post_ids as $post_id) { print "\tFIXING: Post ID {$post_id} was scheduled but was missed. Publishing now...\n"; wp_publish_post($post_id); print "\t\tFIXED.\n"; } print "Finished.\n"; }
public static function removeAllQueuedUpdates() { $crons = _get_cron_array(); if (!empty($crons)) { foreach ($crons as $timestamp => $cron) { // Remove single post updates if (!empty($cron['social_metrics_update_single_post'])) { unset($crons[$timestamp]['social_metrics_update_single_post']); } // Remove full post updates if (!empty($cron['social_metrics_full_update'])) { unset($crons[$timestamp]['social_metrics_full_update']); } } _set_cron_array($crons); } return; }