Esempio n. 1
1
 /**
  * Hooked into transition_post_status. Will initiate search engine pings
  * if the post is being published, is a post type that a sitemap is built for
  * and is a post that is included in sitemaps.
  *
  * @param string   $new_status New post status.
  * @param string   $old_status Old post status.
  * @param \WP_Post $post       Post object.
  */
 function status_transition($new_status, $old_status, $post)
 {
     if ($new_status != 'publish') {
         return;
     }
     wp_cache_delete('lastpostmodified:gmt:' . $post->post_type, 'timeinfo');
     // #17455.
     $options = WPSEO_Options::get_options(array('wpseo_xml', 'wpseo_titles'));
     if (isset($options['post_types-' . $post->post_type . '-not_in_sitemap']) && $options['post_types-' . $post->post_type . '-not_in_sitemap'] === true || $post->post_type === 'nav_menu_item') {
         return;
     }
     if (WP_CACHE) {
         wp_schedule_single_event(time() + 300, 'wpseo_hit_sitemap_index');
     }
     /**
      * Filter: 'wpseo_allow_xml_sitemap_ping' - Check if pinging is not allowed (allowed by default)
      *
      * @api boolean $allow_ping The boolean that is set to true by default.
      */
     if (apply_filters('wpseo_allow_xml_sitemap_ping', true) === false) {
         return;
     }
     // Allow the pinging to happen slightly after the hit sitemap index so the sitemap is fully regenerated when the ping happens.
     $excluded_posts = explode(',', $options['excluded-posts']);
     if (!in_array($post->ID, $excluded_posts)) {
         if (defined('YOAST_SEO_PING_IMMEDIATELY') && YOAST_SEO_PING_IMMEDIATELY) {
             wpseo_ping_search_engines();
         } else {
             wp_schedule_single_event(time() + 300, 'wpseo_ping_search_engines');
         }
     }
 }
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');
    }
}
 /**
  * Get the data from the transient and/or schedule new data to be retrieved.
  *
  * @param	string	$transient	The name of the transient. Must be 43 characters or less including $this->transient_prefix.
  * @param	string	$hook		The name of the hook to retrieve new data.
  * @param	array	$args		An array of arguments to pass to the function.
  *
  * @return	mixed	Either false or the data from the transient.
  */
 public function get_transient($transient, $hook, $args)
 {
     // Build the transient names.
     $transient = $this->prefix . $transient;
     $fallback_transient = $transient . '_';
     if (is_multisite()) {
         if (false === ($data = get_site_transient($transient))) {
             $data = get_site_transient($fallback_transient);
             if (!wp_get_schedule($hook, $args)) {
                 wp_clear_scheduled_hook($hook, $args);
                 wp_schedule_single_event(time(), $hook, $args);
             }
             return $data;
         } else {
             return $data;
         }
     } else {
         if (false === ($data = get_transient($transient))) {
             $data = get_transient($fallback_transient);
             if (!wp_get_schedule($hook, $args)) {
                 wp_clear_scheduled_hook($hook, $args);
                 wp_schedule_single_event(time(), $hook, $args);
             }
             return $data;
         } else {
             return $data;
         }
     }
 }
Esempio n. 4
0
 public function post_restore()
 {
     if (isset($_POST['job_id']) && isset($_POST['backup_uniqid']) && isset($_POST['_wpnonce']) && isset($_POST['method'])) {
         $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING);
         if (!wp_verify_nonce($nonce, 'my-wp-backup-restore-backup')) {
             wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup'));
         }
         $id = absint($_POST['job_id']);
         $uniqid = sanitize_key($_POST['backup_uniqid']);
         $method = filter_input(INPUT_POST, 'method', FILTER_SANITIZE_STRING);
         $backup = self::get($id, $uniqid);
         if (!isset($backup['duration'])) {
             add_settings_error('', '', __('Invalid backup id/uniqid.', 'my-wp-backup'));
             set_transient('settings_errors', get_settings_errors());
             wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1)));
         }
         if (!$backup->has_archives()) {
             // No local copy and no remote copy === DEAD END.
             if (empty($backup['destinations'])) {
                 add_settings_error('', '', __('Backup files missing.', 'my-wp-backup'));
                 set_transient('settings_errors', get_settings_errors());
                 wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1)));
             }
             if (!isset($backup['destinations'][$method])) {
                 add_settings_error('', '', sprintf(__('No backup files from %s.', 'my-wp-backup'), Job::$destinations[$method]));
                 set_transient('settings_errors', get_settings_errors());
                 wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1)));
             }
         }
         wp_schedule_single_event(time(), 'wp_backup_restore_backup', array(array($id, $uniqid, $method)));
         wp_safe_redirect($this->admin->get_page_url('backup', array('uniqid' => $uniqid, 'action' => 'viewprogress', 'id' => $id)));
     }
 }
 public function doWhenPluginActivates()
 {
     // Requirement Check
     $oRequirement = new FetchTweets_Requirements($this->strFilePath, array('php' => array('version' => '5.2.4', 'error' => 'The plugin requires the PHP version %1$s or higher.'), 'wordpress' => array('version' => '3.3', 'error' => 'The plugin requires the WordPress version %1$s or higher.'), 'functions' => array('curl_version' => sprintf(__('The plugin requires the %1$s to be installed.', 'fetch-tweets'), 'the cURL library')), 'constants' => array()), True, null);
     $oRequirement->checkRequirements();
     // Schedule transient set-ups
     wp_schedule_single_event(time(), 'fetch_tweets_action_setup_transients');
 }
function podlove_init_user_agent_refresh()
{
    foreach (range(0, floor(UserAgent::count() / 500) * 500, 500) as $start_id) {
        wp_schedule_single_event(time() + mt_rand(2, 30), 'podlove_parse_user_agents', [$start_id]);
    }
    // must be done after user agent refresh is finished
    wp_schedule_single_event(time() + 180, 'podlove_delete_bots_from_clean_downloadintents');
}
 protected function _scheduleCacheRenewal($aURLs)
 {
     // Schedules the action to run in the background with WP Cron.
     if (wp_next_scheduled('aal_action_simplepie_renew_cache', array($aURLs))) {
         return;
     }
     wp_schedule_single_event(time(), 'aal_action_simplepie_renew_cache', array($aURLs));
 }
 function __construct()
 {
     $queue = TP_CSV_Queue::get();
     if (!wp_next_scheduled('tp_csv_importer') && 0 < count($queue)) {
         wp_schedule_single_event(time(), 'tp_csv_importer');
     }
     add_action('tp_csv_importer', array($this, 'perform'));
 }
/**
 * Runs the installer.
 *
 * @access public
 * @return void
 */
function do_install_woocommerce()
{
    global $woocommerce_settings, $woocommerce;
    // Do install
    woocommerce_default_options();
    woocommerce_tables_install();
    woocommerce_init_roles();
    // Register post types
    $woocommerce->init_taxonomy();
    // Add default taxonomies
    woocommerce_default_taxonomies();
    // Cron jobs
    wp_clear_scheduled_hook('woocommerce_scheduled_sales');
    wp_clear_scheduled_hook('woocommerce_cancel_unpaid_orders');
    wp_clear_scheduled_hook('woocommerce_cleanup_sessions');
    $ve = get_option('gmt_offset') > 0 ? '+' : '-';
    wp_schedule_event(strtotime('tomorrow ' . $ve . get_option('gmt_offset') . ' HOURS'), 'daily', 'woocommerce_scheduled_sales');
    $held_duration = get_option('woocommerce_hold_stock_minutes', null);
    if (is_null($held_duration)) {
        $held_duration = '60';
    }
    if ($held_duration != '') {
        wp_schedule_single_event(time() + absint($held_duration) * 60, 'woocommerce_cancel_unpaid_orders');
    }
    wp_schedule_event(time(), 'twicedaily', 'woocommerce_cleanup_sessions');
    // Install files and folders for uploading files and prevent hotlinking
    $upload_dir = wp_upload_dir();
    $files = array(array('base' => $upload_dir['basedir'] . '/woocommerce_uploads', 'file' => '.htaccess', 'content' => 'deny from all'), array('base' => $upload_dir['basedir'] . '/woocommerce_uploads', 'file' => 'index.html', 'content' => ''), array('base' => WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs', 'file' => '.htaccess', 'content' => 'deny from all'), array('base' => WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs', 'file' => 'index.html', 'content' => ''));
    foreach ($files as $file) {
        if (wp_mkdir_p($file['base']) && !file_exists(trailingslashit($file['base']) . $file['file'])) {
            if ($file_handle = @fopen(trailingslashit($file['base']) . $file['file'], 'w')) {
                fwrite($file_handle, $file['content']);
                fclose($file_handle);
            }
        }
    }
    // Clear transient cache
    $woocommerce->clear_product_transients();
    // Recompile LESS styles if they are custom
    if (get_option('woocommerce_frontend_css') == 'yes') {
        $colors = get_option('woocommerce_frontend_css_colors');
        if (!empty($colors['primary']) && !empty($colors['secondary']) && !empty($colors['highlight']) && !empty($colors['content_bg']) && !empty($colors['subtext']) && ($colors['primary'] != '#ad74a2' || $colors['secondary'] != '#f7f6f7' || $colors['highlight'] != '#85ad74' || $colors['content_bg'] != '#ffffff' || $colors['subtext'] != '#777777')) {
            woocommerce_compile_less_styles();
        }
    }
    // Queue upgrades
    $current_version = get_option('woocommerce_version', null);
    $current_db_version = get_option('woocommerce_db_version', null);
    if (version_compare($current_db_version, '2.0.9', '<') && null !== $current_db_version) {
        update_option('_wc_needs_update', 1);
    } else {
        update_option('woocommerce_db_version', $woocommerce->version);
    }
    // Update version
    update_option('woocommerce_version', $woocommerce->version);
    // Flush rewrite rules
    flush_rewrite_rules();
}
Esempio n. 10
0
 public function schedule_migrate_old_table()
 {
     global $wpdb;
     if ($wpdb->get_var("SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key = '_links_to'") !== null) {
         if (!wp_get_schedule('idx_migrate_old_table')) {
             wp_schedule_single_event(time(), 'idx_migrate_old_table');
         }
     }
 }
Esempio n. 11
0
 /**
  * Main scheduling function
  * 
  * @access public
  * @param int $timestamp
  * @param string $hook
  * @param int $subscription_id
  * @return bool
  */
 public static function schedule($timestamp, $hook, $subscription_id)
 {
     if (wp_schedule_single_event($timestamp, $hook, array((int)$subscription_id)) === false) {
         return false;
     }
     else {
         return true;
     }
 }
Esempio n. 12
0
 /**
  * @param string $event
  * @param array $args
  * @return bool
  */
 public function assign($event, array $args = array())
 {
     // we've already scheduled this
     if (wp_next_scheduled($event, $args) !== false) {
         return false;
     }
     wp_schedule_single_event(time() + 1, $event, $args);
     return true;
 }
 /**
  * @since       3.6.2
  */
 private function _scheduleEvent()
 {
     $_sActionName = AdminPageFrameworkLoader_Registry::HOOK_SLUG . '_action_get_development_version';
     $_aArguments = array();
     if (wp_next_scheduled($_sActionName, $_aArguments)) {
         return false;
     }
     wp_schedule_single_event(time(), $_sActionName, $_aArguments);
 }
 /**
  * Register Cron event to invalidate
  *
  * @param array $query
  * @since 4.3.0
  * @access private
  **/
 private function _register_cron_event($query)
 {
     if ($query['Paths']['Items'][0] === '/*') {
         return;
     }
     $query = $this->_merge_transient_invalidation_query($query);
     set_transient(self::C3_CRON_INDALITATION_TARGET, $query, 5 * 60);
     $time = time() + MINUTE_IN_SECONDS * 5;
     wp_schedule_single_event($time, 'c3_cron_invalidation');
 }
Esempio n. 15
0
 /**
  * Schedule the event
  *
  * @since    1.0.0
  * @return void
  */
 public function schedule_event()
 {
     if (!wp_next_scheduled($this->args['name'])) {
         if ($this->args['schedule'] === 'schedule') {
             wp_schedule_event(current_time('timestamp'), $this->args['recurrence'], $this->args['name'], $this->args['args']);
         } elseif ($this->args['schedule'] === 'single') {
             wp_schedule_single_event($this->args['recurrence'], $this->args['name'], $this->args['args']);
         }
     }
 }
Esempio n. 16
0
 /**
  * Perform the push action.
  *
  * @access public
  * @param boolean $doing_async
  * @return boolean
  */
 public function perform($doing_async = false)
 {
     if ('yes' === $this->settings->get('api_async') && false === $doing_async) {
         // Track this publish event as pending with the timestamp it was sent
         update_post_meta($this->id, 'apple_news_api_pending', time());
         wp_schedule_single_event(time(), \Admin_Apple_Async::ASYNC_PUSH_HOOK, array($this->id, get_current_user_id()));
     } else {
         return $this->push();
     }
 }
Esempio n. 17
0
/**
 * Run an audit
 *
 * @access public
 * @return void
 */
function msa_run_audit()
{
    // Create an audit if we have one in the queue.
    $next_audit = msa_get_next_audit_to_run();
    if (isset($next_audit) && is_array($next_audit)) {
        wp_schedule_single_event(time(), 'msa_run_audit_background', array($next_audit));
        set_transient('msa_schedule_audit', true);
        msa_clear_audit_queue();
    }
}
 /**
  * 
  * @return      boolean
  */
 private function _scheduleBackgroundCacheRenewal($sURL, $iCacheDuration, $aArguments, $sType)
 {
     $_sActionName = $this->sCacheRenwalActionName;
     $_aArguments = array($sURL, $iCacheDuration, $aArguments, $sType);
     if (wp_next_scheduled($_sActionName, $_aArguments)) {
         return false;
     }
     $_bCancelled = wp_schedule_single_event(time(), $_sActionName, $_aArguments);
     return false === $_bCancelled ? false : true;
 }
Esempio n. 19
0
function wppa_schedule_maintenance_proc($slug, $first = false)
{
    // Schedule cron job
    wp_schedule_single_event(time() + ($first ? 10 : 120), 'wppa_cron_event', array($slug));
    // Update appropriate options
    update_option($slug . '_status', 'Scheduled cron job');
    update_option($slug . '_user', 'cron-job');
    // Inform calling Ajax proc about the results
    echo '||' . $slug . '||' . __('Scheduled cron job', 'wp-photo-album-plus') . '||0||reload';
}
Esempio n. 20
0
 /**
  * Schedule the activity report cron job.
  */
 public static function scheduleCronJob()
 {
     self::clearCronJobs();
     if (!wfConfig::get('email_summary_enabled', 1)) {
         return;
     }
     if (is_main_site()) {
         list(, $end_time) = wfActivityReport::getReportDateRange();
         wp_schedule_single_event($end_time, 'wordfence_email_activity_report');
     }
 }
 private function handle_subscription()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         Header('Content-Type: text/plain');
         $this->send_text('200 OK', $_GET['hub_challenge']);
     } else {
         wp_schedule_single_event(time(), 'degg_instagram_fetch', array($this->client_id, $this->tag));
         spawn_cron(time());
         $this->send_text('200 OK', "OK");
     }
 }
 public function flush_rules_after_slug_change($options = array())
 {
     if (array_key_exists($this->slug_option_id, $options)) {
         $old_slug = of_get_option($this->slug_option_id, false);
         $new_slug = $options[$this->slug_option_id];
         // check if new slug is really new
         if ($old_slug !== $new_slug) {
             wp_schedule_single_event(time(), 'presscore_post_type_rewrite_rules_filter_one_time');
         }
     }
 }
Esempio n. 23
0
 private function schedule_next_task_queue_event_if_necessary($next_event_timestamp = null)
 {
     $next_scheduled_event_timestamp = $this->get_next_scheduled_event_timestamp();
     $next_event_timestamp = is_null($next_event_timestamp) ? time() + 30 : $next_event_timestamp;
     if ($next_scheduled_event_timestamp && $next_scheduled_event_timestamp < $next_event_timestamp) {
         return;
     }
     if ($next_scheduled_event_timestamp && $next_scheduled_event_timestamp - $next_event_timestamp <= 60) {
         return;
     }
     wp_schedule_single_event($next_event_timestamp, 'awpcp-task-queue-event', array('created_at' => $next_event_timestamp));
 }
 /**
  * Activate plugin.
  * Reschedules pending tasks.
  * @param boolean $network_wide
  */
 public static function activate($network_wide = false)
 {
     $scheduled = get_option('groups_ws_scheduled', null);
     if (!empty($scheduled)) {
         foreach ($scheduled as $timestamp => $tasks) {
             foreach ($tasks as $task) {
                 if (isset($task['args']) && isset($task['args']['user_id']) && isset($task['args']['subscription_key'])) {
                     wp_schedule_single_event($timestamp, 'groups_ws_subscription_expired', array('user_id' => $task['args']['user_id'], 'subscription_key' => $task['args']['subscription_key']));
                 }
             }
         }
     }
 }
Esempio n. 25
0
 function update_cache($new_status = '', $old_status = '')
 {
     $cond = 'publish' == $new_status || 'publish' == $old_status || empty($new_status) && empty($old_status);
     // delete post or update options
     if (!$cond) {
         return;
     }
     if ($this->options->cron) {
         wp_clear_scheduled_hook('smart_archives_update');
         wp_schedule_single_event(time(), 'smart_archives_update');
     } else {
         do_action('smart_archives_update');
     }
 }
Esempio n. 26
0
 /**
  * Add a form
  * 
  * @access public
  * @since 2.9
  * @return int $form_id
  */
 public function create($defaults = array())
 {
     $form_id = nf_insert_object('form');
     $date_updated = date('Y-m-d', current_time('timestamp'));
     nf_update_object_meta($form_id, 'date_updated', $date_updated);
     foreach ($defaults as $meta_key => $meta_value) {
         nf_update_object_meta($form_id, $meta_key, $meta_value);
     }
     // Add a single event hook that will check to see if this is an orphaned function.
     $timestamp = strtotime('+24 hours', time());
     $args = array('form_id' => $form_id);
     wp_schedule_single_event($timestamp, 'nf_maybe_delete_form', $args);
     return $form_id;
 }
Esempio n. 27
0
 function schedule_drip_mail($prev_unit_id, $course_id, $user_id, $next_unit_id, $timestamp)
 {
     if (isset($this->schedule) && is_array($this->schedule)) {
         if ($this->schedule['drip'] === 'yes') {
             $drip_schedule = $this->schedule['drip_schedule'];
             $drip_schedule = $timestamp - $drip_schedule * 3600;
             $args = array($next_unit_id, $course_id, $user_id);
             wp_clear_scheduled_hook('wplms_send_drip_mail', array($unit_id, $course_id, $user_id));
             if (!wp_next_scheduled('wplms_send_drip_mail', $args)) {
                 wp_schedule_single_event($drip_schedule, 'wplms_send_drip_mail', $args);
             }
         }
     }
 }
Esempio n. 28
0
function es_schedule_emails($user, $event)
{
    $event_date_str = get_post_meta($event->ID, '_EventStartDate', true);
    $event_date = new DateTime($event_date_str, new DateTimeZone("UTC"));
    $month_earlier = clone $event_date;
    $month_earlier->sub(new DateInterval("P1M"));
    $week_earlier = clone $event_date;
    $week_earlier->sub(new DateInterval("P1W"));
    // TEST
    // $month_earlier = (new DateTime())->add(new DateInterval("PT1M"));
    // $week_earlier = (new DateTime())->add(new DateInterval("PT1M"));
    wp_schedule_single_event($week_earlier->getTimestamp(), 'reminder_week_earlier', array($user, $event, $event_date));
    wp_schedule_single_event($month_earlier->getTimestamp(), 'reminder_month_earlier', array($user, $event, $event_date));
}
Esempio n. 29
0
 public function flush()
 {
     $options = red_get_options();
     $total = $this->expire_logs('redirection_logs', $options['expire_redirect']);
     $total += $this->expire_logs('redirection_404', $options['expire_404']);
     if ($total >= self::DELETE_MAX) {
         $next = time() + self::DELETE_KEEP_ON * 60;
         // There are still more logs to clear - keep on doing until we're clean or until the next normal event
         if ($next < wp_next_scheduled(self::DELETE_HOOK)) {
             wp_schedule_single_event($next, self::DELETE_HOOK);
         }
     }
     $this->optimize_logs();
 }
 public static function pagespeed_cron_check()
 {
     $count = get_option("mainwp_child_pagespeed_count_checking");
     if ($count >= 7) {
         $recheck = true;
         $count = 0;
     } else {
         $recheck = false;
         $count++;
     }
     update_option('mainwp_child_pagespeed_count_checking', $count);
     $worker_args = array(array(), false, $recheck);
     wp_schedule_single_event(time(), 'googlepagespeedinsightschecknow', $worker_args);
 }