Using Gravity Forms ‘gform_polls_cron_schedule’ PHP filter

The gform_polls_cron_schedule filter allows you to modify the frequency of the cron job that calculates poll data. By default, it is set to hourly to avoid heavy loads on the server.

Usage

add_filter('gform_polls_cron_schedule', 'your_function_name', 10, 1);

Parameters

  • $schedules (array): An array of the current schedules.

More information

See Gravity Forms Docs: gform_polls_cron_schedule

Important: The Polls Add-On must be deactivated and reactivated in order to reschedule the task.

Examples

Add twice hourly schedule

Add a new cron schedule to run twice hourly.

add_filter('gform_polls_cron_schedule', 'gform_polls_cron_add_twice_hourly');

function gform_polls_cron_add_twice_hourly($schedules) {
    // Adds twice hourly to the existing schedules
    $schedules['twicehourly'] = array(
        'interval' => 1800, // number of seconds in the interval
        'display' => 'Twice Hourly'
    );
    return $schedules;
}

Add daily schedule

Add a new cron schedule to run daily.

add_filter('gform_polls_cron_schedule', 'gform_polls_cron_add_daily');

function gform_polls_cron_add_daily($schedules) {
    // Adds daily to the existing schedules
    $schedules['daily'] = array(
        'interval' => 86400, // number of seconds in the interval
        'display' => 'Daily'
    );
    return $schedules;
}

Add weekly schedule

Add a new cron schedule to run weekly.

add_filter('gform_polls_cron_schedule', 'gform_polls_cron_add_weekly');

function gform_polls_cron_add_weekly($schedules) {
    // Adds weekly to the existing schedules
    $schedules['weekly'] = array(
        'interval' => 604800, // number of seconds in the interval
        'display' => 'Weekly'
    );
    return $schedules;
}

Add bi-weekly schedule

Add a new cron schedule to run every two weeks.

add_filter('gform_polls_cron_schedule', 'gform_polls_cron_add_biweekly');

function gform_polls_cron_add_biweekly($schedules) {
    // Adds bi-weekly to the existing schedules
    $schedules['biweekly'] = array(
        'interval' => 1209600, // number of seconds in the interval
        'display' => 'Bi-Weekly'
    );
    return $schedules;
}

Remove hourly schedule

Remove the default hourly schedule.

add_filter('gform_polls_cron_schedule', 'gform_polls_cron_remove_hourly');

function gform_polls_cron_remove_hourly($schedules) {
    // Removes the hourly schedule
    unset($schedules['hourly']);
    return $schedules;
}