Ejemplo n.º 1
0
 /**
  * Schedule currency rates updates.
  *
  * Schedules a wp_cron job to update currencies at set interval.
  *
  * @since 1.4.0
  *
  * @param string $api_key
  * @param string $interval
  */
 public function schedule_updates($api_key = '', $interval = '')
 {
     if (empty($api_key) || empty($interval)) {
         $option = get_option('wp_currencies_settings');
         $api_key = isset($option['api_key']) ? $option['api_key'] : '';
         $interval = isset($option['update_interval']) ? $option['update_interval'] : '';
     }
     if ($api_key && $interval) {
         if (!wp_next_scheduled('wp_currencies_update')) {
             wp_schedule_event(time(), $interval, 'wp_currencies_update');
         } else {
             wp_reschedule_event(time(), $interval, 'wp_currencies_update');
         }
     }
 }
Ejemplo n.º 2
0
function post_news_action()
{
    if (time() - wp_next_scheduled('post_news') > 900) {
        post_news();
        wp_reschedule_event(time(), 'apn_quarter', 'post_news');
    }
}
 protected function result()
 {
     define('DOING_CRON', true);
     set_time_limit(0);
     $args = $this->input();
     if (false === ($crons = _get_cron_array())) {
         return new WP_Error('no-cron-event', 'Currently there are no cron events', 400);
     }
     $timestamps_to_run = array_keys($crons);
     $gmt_time = microtime(true);
     if (isset($timestamps_to_run[0]) && $timestamps_to_run[0] > $gmt_time) {
         return new WP_Error('no-cron-event', 'Currently there are no cron events ready to be run', 400);
     }
     $locked = $this->is_cron_locked($gmt_time);
     if (is_wp_error($locked)) {
         return $locked;
     }
     $lock = $this->lock_cron();
     $processed_events = array();
     foreach ($crons as $timestamp => $cronhooks) {
         if ($timestamp > $gmt_time && !isset($args['hook'])) {
             break;
         }
         foreach ($cronhooks as $hook => $hook_data) {
             if (isset($args['hook']) && !in_array($hook, $args['hook'])) {
                 continue;
             }
             foreach ($hook_data as $hash => $hook_item) {
                 $schedule = $hook_item['schedule'];
                 $arguments = $hook_item['args'];
                 if ($schedule != false) {
                     wp_reschedule_event($timestamp, $schedule, $hook, $arguments);
                 }
                 wp_unschedule_event($timestamp, $hook, $arguments);
                 do_action_ref_array($hook, $arguments);
                 $processed_events[] = array($hook => $arguments);
                 // If the hook ran too long and another cron process stole the lock,
                 // or if we things are taking longer then 20 seconds then quit.
                 if ($this->get_cron_lock() != $lock || $gmt_time + 20 > microtime(true)) {
                     $this->maybe_unlock_cron($lock);
                     return array('success' => $processed_events);
                 }
             }
         }
     }
     $this->maybe_unlock_cron($lock);
     return array('success' => $processed_events);
 }
Ejemplo n.º 4
0
function incsub_support_init()
{
    global $wpdb, $ticket_status, $ticket_priority, $incsub_support_page, $incsub_support_page_long;
    if (preg_match('/mu\\-plugin/', __FILE__) > 0) {
        load_muplugin_textdomain(INCSUB_SUPPORT_LANG_DOMAIN, dirname(plugin_basename(__FILE__)) . '/languages');
    } else {
        load_plugin_textdomain(INCSUB_SUPPORT_LANG_DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/languages');
    }
    if (is_admin()) {
        wp_register_style('incsub_support_admin_css', plugins_url('incsub-support/css/wp_admin.css'), array(), INCSUB_SUPPORT_VERSION);
        wp_register_script('incsub_support_admin_js', plugins_url('incsub-support/js/wp_admin.js'), array('jquery'), INCSUB_SUPPORT_VERSION, true);
    }
    $wpdb->tickets = incsub_support_tablename('tickets');
    $wpdb->tickets_messages = incsub_support_tablename('tickets_messages');
    $wpdb->tickets_cats = incsub_support_tablename('tickets_cats');
    $wpdb->faq = incsub_support_tablename('faq');
    $wpdb->faq_cats = incsub_support_tablename('faq_cats');
    $ticket_priority = array(0 => __("Low", INCSUB_SUPPORT_LANG_DOMAIN), 1 => __("Normal", INCSUB_SUPPORT_LANG_DOMAIN), 2 => __("Elevated", INCSUB_SUPPORT_LANG_DOMAIN), 3 => __("High", INCSUB_SUPPORT_LANG_DOMAIN), 4 => __("Critical", INCSUB_SUPPORT_LANG_DOMAIN));
    $ticket_status = array(0 => __("New", INCSUB_SUPPORT_LANG_DOMAIN), 1 => __("In progress", INCSUB_SUPPORT_LANG_DOMAIN), 2 => __("Waiting on User to reply", INCSUB_SUPPORT_LANG_DOMAIN), 3 => __("Waiting on Admin to reply", INCSUB_SUPPORT_LANG_DOMAIN), 4 => __("Stalled", INCSUB_SUPPORT_LANG_DOMAIN), 5 => __("Closed", INCSUB_SUPPORT_LANG_DOMAIN));
    $incsub_support_imap = get_site_option('incsub_support_imap', array('host' => 'imap.gmail.com', 'port' => '993', 'ssl' => '/ssl', 'mailbox' => 'INBOX', 'username' => '', 'password' => ''));
    if (isset($_POST['incsub_support_menu_name'])) {
        update_site_option('incsub_support_menu_name', $_POST['incsub_support_menu_name']);
    }
    if (isset($_POST['incsub_support_from_name'])) {
        update_site_option('incsub_support_from_name', $_POST['incsub_support_from_name']);
    }
    if (isset($_POST['incsub_support_from_mail'])) {
        update_site_option('incsub_support_from_mail', $_POST['incsub_support_from_mail']);
    }
    if (isset($_POST['incsub_support_fetch_imap'])) {
        update_site_option('incsub_support_fetch_imap', $_POST['incsub_support_fetch_imap']);
        if (get_site_option('incsub_support_imap_frequency', '') != $_POST['incsub_support_imap_frequency']) {
            if (wp_reschedule_event(0, $_POST['incsub_support_imap_frequency'], 'incsub_support_fetch_imap') === false) {
                wp_schedule_event(0, $_POST['incsub_support_imap_frequency'], 'incsub_support_fetch_imap');
            }
            update_site_option('incsub_support_imap_frequency', $_POST['incsub_support_imap_frequency']);
        }
        if (empty($_POST['incsub_support_imap']['password'])) {
            $_POST['incsub_support_imap']['password'] = $incsub_support_imap['password'];
        }
        update_site_option('incsub_support_imap', $_POST['incsub_support_imap']);
        if (isset($_POST['test']) && $_POST['incsub_support_fetch_imap'] == "enabled") {
            if (incsub_support_fetch_imap()) {
                wp_redirect("{$incsub_support_settings_page}?page=support-options&updated=true&tested=true");
            } else {
                wp_redirect("{$incsub_support_settings_page}?page=support-options&updated=true&tested=false");
            }
        } else {
            wp_redirect("{$incsub_support_settings_page}?page=support-options&updated=true");
        }
    }
}
Ejemplo n.º 5
0
function reschedule_delete_spam()
{
    wp_reschedule_event(time() + 60, 'daily', 'wordpress_spam_cleaner');
}
Ejemplo n.º 6
0
function wpr_create_campaign()
{
    global $wpdb, $wpr_table_campaigns, $wpr_table_templates;
    $options = unserialize(get_option("wpr_options"));
    if ($_POST['keywords'] == "" && $_POST['type'] == "keyword") {
        echo '<div class="updated"><p>' . __("Please enter at least one keyword!", "wprobot") . '</p></div>';
    } elseif ($_POST['feeds'] == "" && $_POST['type'] == "rss") {
        echo '<div class="updated"><p>' . __("Please enter at least one RSS feed!", "wprobot") . '</p></div>';
    } elseif ($_POST['nodes'] == "" && $_POST['type'] == "nodes") {
        echo '<div class="updated"><p>' . __("Please enter at least one Amazon BrowseNode!", "wprobot") . '</p></div>';
    } elseif ($_POST['categories'] == "") {
        echo '<div class="updated"><p>' . __("Please enter at least one category!", "wprobot") . '</p></div>';
    } elseif ($_POST['interval'] == "") {
        echo '<div class="updated"><p>' . __("Please enter a post interval!", "wprobot") . '</p></div>';
    } elseif ($_POST['name'] == "") {
        echo '<div class="updated"><p>' . __("Please enter a name for your campaign!", "wprobot") . '</p></div>';
    } elseif ($_POST['title1'] == "" || $_POST['content1'] == "" || $_POST['chance1'] == "") {
        echo '<div class="updated"><p>' . __("Please enter at least one template for your campaign!", "wprobot") . '</p></div>';
    } elseif ($_POST['amazon_department'] == "All" && $_POST['type'] == "nodes") {
        echo '<div class="updated"><p>' . __("Amazon Department can not be 'All' in a BrowseNodes campaign! You can to select the correct Department your Nodes belong to (Amazon API requirement).", "wprobot") . '</p></div>';
    } else {
        $type = $_POST['type'];
        // Keywords
        $_POST['keywords'] = stripslashes($_POST['keywords']);
        $keywordsinput = str_replace("\r", "", $_POST['keywords']);
        $keywordsinput = explode("\n", $keywordsinput);
        $i = 0;
        $keywords = array();
        if ($_POST["edit"]) {
            // GET OLD KEYWORDS FOR NUMs $oldcamp->postspan
            $edit = 1;
            $oldcamp = $wpdb->get_row("SELECT keywords,postspan FROM {$wpr_table_campaigns} WHERE id = '" . $_POST["edit"] . "'");
            $oldkeywords = unserialize($oldcamp->keywords);
        }
        if ($type == "keyword") {
            foreach ($keywordsinput as $keyword) {
                if ($keyword != "") {
                    $keywords[$i] = array($keyword);
                    if ($edit == 1) {
                        $kwnums = false;
                        foreach ($oldkeywords as $key => $oldkeyword) {
                            if ($oldkeyword[0] == $keyword) {
                                $kwnums = $oldkeyword[1];
                            }
                        }
                    }
                    if ($kwnums != false) {
                        $keywords[$i][] = $kwnums;
                    } else {
                        $keywords[$i][] = array("total" => 0);
                    }
                    $keywords[$i]["skipped"] = 0;
                }
                $i++;
            }
        } elseif ($type == "rss") {
            $rssinput = str_replace("\r", "", $_POST['feeds']);
            $rssinput = explode("\n", $rssinput);
            foreach ($rssinput as $rss) {
                if ($rss != "") {
                    $keywords[$i] = array($keywordsinput[$i]);
                    if ($edit == 1) {
                        $kwnums = false;
                        foreach ($oldkeywords as $key => $oldkeyword) {
                            if ($oldkeyword[0] == $keywordsinput[$i]) {
                                $kwnums = $oldkeyword[1];
                            }
                        }
                    }
                    if ($kwnums != false) {
                        $keywords[$i][] = $kwnums;
                    } else {
                        $keywords[$i][] = array("total" => 0);
                    }
                    $keywords[$i]["skipped"] = 0;
                    $keywords[$i]["feed"] = $rss;
                }
                $i++;
            }
        } elseif ($type == "nodes") {
            $nodesinput = str_replace("\r", "", $_POST['nodes']);
            $nodesinput = explode("\n", $nodesinput);
            foreach ($nodesinput as $node) {
                $nodename = wpr_aws_getnodename($node);
                echo $nodename;
                if ($node != "" && $nodename != false) {
                    $keywords[$i] = array($keywordsinput[$i]);
                    if ($edit == 1) {
                        $kwnums = false;
                        foreach ($oldkeywords as $key => $oldkeyword) {
                            if ($oldkeyword[0] == $keywordsinput[$i]) {
                                $kwnums = $oldkeyword[1];
                            }
                        }
                    }
                    if ($kwnums != false) {
                        $keywords[$i][] = $kwnums;
                    } else {
                        $keywords[$i][] = array("total" => 0);
                    }
                    $keywords[$i]["skipped"] = 0;
                    $keywords[$i]["bnn"] = "{$nodename}";
                    $keywords[$i]["node"] = $node;
                }
                $i++;
            }
        }
        $keywords = $wpdb->escape(serialize($keywords));
        // Categories
        if ($_POST['multisingle'] == "single") {
            $categories = array();
            //$categories["type"] = "single";
            $categories[0]["id"] = $_POST['categories'];
        } else {
            $categories = array();
            $_POST['categories'] = stripslashes($_POST['categories']);
            $categoriesinput = str_replace("\r", "", $_POST['categories']);
            $categoriesinput = explode("\n", $categoriesinput);
            $i = 0;
            foreach ($categoriesinput as $category) {
                if ($category != "") {
                    $category_ID = $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE name = '" . $category . "'");
                    if (!$category_ID && $_POST['createcats'] == "yes") {
                        $category_ID = wp_create_category(ucwords($category));
                    }
                    $categories[$i]["name"] = $category;
                    $categories[$i]["id"] = $category_ID;
                }
                $i++;
            }
            /*if(count($categories) == 1) {
            			$categories["type"] = "single";
            		} else {
            			$categories["type"] = "multi";			
            		}	*/
        }
        $categories = $wpdb->escape(serialize($categories));
        // Templates
        $templates = array();
        for ($i = 1; $i <= $_POST['tnum']; $i++) {
            if ($_POST["chance{$i}"] > 0) {
                $templates[$i]["title"] = stripslashes($_POST["title{$i}"]);
                $templates[$i]["content"] = stripslashes($_POST["content{$i}"]);
                $templates[$i]["chance"] = $_POST["chance{$i}"];
                $templates[$i]["comments"]["amazon"] = $_POST["comments_amazon{$i}"];
                $templates[$i]["comments"]["flickr"] = $_POST["comments_flickr{$i}"];
                $templates[$i]["comments"]["yahooanswers"] = $_POST["comments_yahoo{$i}"];
                $templates[$i]["comments"]["youtube"] = $_POST["comments_youtube{$i}"];
            }
        }
        //$templates = array_values($templates); -- MAKES FIRST TEMPLATE "0"
        $templates = serialize($templates);
        // Optional settings
        $amadept = $_POST['amazon_department'];
        $yahoocat = $_POST['yahoo_category'];
        $ebaycat = $_POST['ebay_category'];
        $_POST['replace'] = stripslashes($_POST['replace']);
        $replaceinput = str_replace("\r", "", $_POST['replace']);
        $replaceinput = explode("\n", $replaceinput);
        $i = 0;
        $replaces = array();
        foreach ($replaceinput as $replace) {
            if ($replace != "") {
                $replace = explode("|", $replace);
                $replaces[$i]["from"] = $replace[0];
                $replaces[$i]["to"] = str_replace('\\"', "", $replace[1]);
                $replaces[$i]["chance"] = $replace[2];
            }
            $i++;
        }
        $replaces = $wpdb->escape(serialize($replaces));
        $_POST['exclude'] = stripslashes($_POST['exclude']);
        $exclude = str_replace("\r", "", $_POST['exclude']);
        $exclude = explode("\n", $exclude);
        foreach ($exclude as $key => $value) {
            if ($value == "") {
                unset($array[$key]);
            }
        }
        $exclude = array_values($exclude);
        $exclude = $wpdb->escape(serialize($exclude));
        $name = $_POST['name'];
        $postevery = $_POST['interval'];
        $cr_period = $_POST['period'];
        $postspan = "WPR_" . $postevery . "_" . $cr_period;
        $customfield = array();
        $customfield["name"] = $_POST['cf_name'];
        $customfield["value"] = $_POST['cf_value'];
        $customfield = serialize($customfield);
        $translation = array();
        $translation["chance"] = $_POST['transchance'];
        $translation["from"] = $_POST['trans1'];
        $translation["to1"] = $_POST['trans2'];
        $translation["to2"] = $_POST['trans3'];
        $translation["to3"] = $_POST['trans4'];
        $translation["comments"] = $_POST['trans_comments'];
        $translation = serialize($translation);
        if ($_POST['autopost'] == "yes") {
            $pause = 0;
        } else {
            $pause = 1;
        }
        if ($_POST["edit"]) {
            $uid = $_POST["edit"];
            $update = "UPDATE " . $wpr_table_campaigns . " SET name = '{$name}', ctype = '{$type}', keywords = '{$keywords}'\n\t\t\t\t\t, categories = '{$categories}', templates = '{$templates}', cinterval = '{$postevery}', period = '{$cr_period}', postspan = '{$postspan}'\n\t\t\t\t\t, replacekws = '{$replaces}', excludekws = '{$exclude}', amazon_department = '{$amadept}', ebay_cat = '{$ebaycat}', yahoo_cat = '{$yahoocat}'\n\t\t\t\t\t, translation = '{$translation}', customfield = '{$customfield}', pause = '{$pause}' WHERE id = {$uid}";
            $results = $wpdb->query($update);
            if ($results) {
                if ($postspan != $oldcamp->postspan) {
                    wpr_set_schedule($postevery, $cr_period);
                    wp_reschedule_event(time(), $postspan, "wprobothook", array($uid));
                    wpr_delete_schedule($oldcamp->cinterval, $oldcamp->period);
                }
                echo '<div class="updated"><p>' . __('Campaign has been updated! Go to the <a href="?page=wpr-single&id=' . $uid . '">control panel</a> to view details.', "wprobot") . '</p></div>';
            } else {
                echo '<div class="updated"><p>' . __("Campaign could not be updated!", "wprobot") . '</p></div>';
            }
        } else {
            $insert = "INSERT INTO " . $wpr_table_campaigns . " SET name = '{$name}', ctype = '{$type}', keywords = '{$keywords}'\n\t\t\t, categories = '{$categories}', templates = '{$templates}', cinterval = '{$postevery}', period = '{$cr_period}', postspan = '{$postspan}'\n\t\t\t, replacekws = '{$replaces}', excludekws = '{$exclude}', amazon_department = '{$amadept}', ebay_cat = '{$ebaycat}', yahoo_cat = '{$yahoocat}'\n\t\t\t, translation = '{$translation}', customfield = '{$customfield}', pause = '{$pause}'";
            $result = $wpdb->query($insert);
            $insid = mysql_insert_id();
            if ($result) {
                $sql = "SELECT LAST_INSERT_ID() FROM " . $wpr_table_campaigns;
                $id = $wpdb->get_var($sql);
                $linkid = $id;
                if ($linkid != $insid) {
                    $linkid = $insid;
                }
                wpr_set_schedule($postevery, $cr_period);
                $lag = $_POST['delaystart'] * 3600;
                if ($lag == "" || !is_numeric($lag) || $lag < 0) {
                    $lag = 200;
                }
                wp_schedule_event(time() + $lag, $postspan, "wprobothook", array($id));
                $next = wp_next_scheduled("wprobothook", array($id));
                if ($next == 0 || $next == "0" || $next == null || $next == "") {
                    wp_schedule_event(time() + $lag, $postspan, "wprobothook", array($id));
                }
                echo '<div class="updated"><p>' . __('Campaign "' . $name . '" has been added! Go to the <a href="?page=wpr-single&id=' . $linkid . '">control panel</a> to view details.', 'wprobot') . '</p></div>';
            }
        }
    }
}
Ejemplo n.º 7
0
 function post_update($instance)
 {
     //always reset the cron, because we just updated and the interval should start from now
     wp_clear_scheduled_hook('advanced_steam_widget_update', array($this->number));
     wp_reschedule_event(time(), "advanced_steam_widget_interval_" . $this->number, 'advanced_steam_widget_update', array($this->number));
     return $instance;
 }
 /**
  * Check that an event has a callback to run, and allow the check to be overridden
  * Empty events are, by default, skipped and removed/rescheduled
  *
  * @param $event  array  Event data
  *
  * @return bool
  */
 private function action_has_callback_or_should_run_anyway($event)
 {
     // Event has a callback, so let's get on with it
     if (false !== has_action($event['action'])) {
         return true;
     }
     // Run the event anyway, perhaps because callbacks are added using the `all` action
     if (apply_filters('a8c_cron_control_run_event_with_no_callbacks', false, $event)) {
         return true;
     }
     // Remove or reschedule the empty event
     if (false === $event['args']['schedule']) {
         wp_unschedule_event($event['timestamp'], $event['action'], $event['args']['args']);
     } else {
         $timestamp = $event['timestamp'] + (isset($event['args']['interval']) ? $event['args']['interval'] : 0);
         wp_reschedule_event($timestamp, $event['args']['schedule'], $event['action'], $event['args']['args']);
         unset($timestamp);
     }
     return false;
 }