Skip to content

Replace hardcoded scheduling intervals with dynamic cron expression support #482

@saraichinwag

Description

@saraichinwag

Problem

Flow scheduling is limited to 10 hardcoded intervals defined in SchedulerIntervals.php:

Every 5 Minutes, Hourly, Every 2 Hours, Every 4 Hours, Every 6 Hours,
Twice Daily, Daily, Every 3 Days, Weekly, Monthly

Users inevitably need an interval that doesn't exist (e.g., every 3 hours, every 8 hours, twice a week, weekdays only at 9am). Adding each one manually doesn't scale.

Proposal

Replace the dropdown of hardcoded intervals with cron expression support. One text input, infinite flexibility.

UI

Two modes in the scheduling selector:

  1. Simple mode (default) — Keep the existing presets as quick-select buttons for common intervals. These just populate the cron field.
  2. Advanced mode — Raw cron expression input with a human-readable preview ("Runs every 3 hours", "Runs at 9am on weekdays").

Backend

  • Store cron_expression in scheduling_config instead of/alongside interval
  • After each flow execution, compute next run from the cron expression
  • Action Scheduler already supports arbitrary timestamps via as_schedule_single_action() — no WordPress cron intervals needed
  • Backward compatible: existing interval values map to cron expressions (every_4_hours0 */4 * * *)

Examples

Want Cron Expression
Every 3 hours 0 */3 * * *
Every 90 minutes */90 * * * *
Weekdays at 9am 0 9 * * 1-5
Twice a week (Mon/Thu) 0 9 * * 1,4
1st and 15th of month 0 0 1,15 * *
Every 4 hours during business hours 0 9,13,17 * * *

Libraries

PHP cron parsing: dragonmantank/cron-expression is the standard (used by Laravel). Single dependency, calculates next run date from expression.

Migration

Existing flows with interval: "every_4_hours" should auto-migrate to cron_expression: "0 */4 * * *" on plugin update. The interval field can remain for backward compat but cron_expression takes priority when present.

Files

  • inc/Engine/Filters/SchedulerIntervals.php — current hardcoded intervals (can become the "simple mode" presets)
  • inc/Abilities/Flow/CreateFlowAbility.php — flow creation with scheduling
  • inc/Abilities/Flow/FlowHelpers.php — interval resolution
  • Flow scheduling in Action Scheduler hooks

Impact

Removes a recurring friction point. Every time someone needs a new interval, it currently requires a code change and plugin update. Cron expressions solve this permanently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions