Skip to content

Refactor WordPress integration to remove TaskScheduler in favor of new task system #18

@alexstandiford

Description

@alexstandiford

Summary

The phpnomad/tasks package has been rewritten in v2.0.0 to introduce a modern, dependency-injection-friendly, platform-agnostic task system. This update deprecates the legacy TaskScheduler and CanScheduleTasks model and replaces it with a new, unified architecture centered around:

  • Explicit Task value objects
  • Declarative handler registration via HasTaskHandlers (used in initializers)
  • Sequential CanHandleTask handler execution
  • Unified TaskStrategy for both dispatch and handler resolution

This issue proposes refactoring the WordPress integration to fully adopt the new task system.

Why

The current WordPress integration schedules tasks using TaskScheduler, which is tightly coupled to the now-deprecated CanScheduleTasks API.

That implementation is:

  • Incompatible with the new task system introduced in v2.0.0
  • Difficult to test or extend in modern, DI-driven PHP applications
  • Architecturally inconsistent with PHPNomad’s event system and initializer-driven design

Bringing the WordPress integration in line with the new task model will simplify the codebase, improve maintainability, and ensure consistency across all platform integrations.

What Needs to Happen

  • Remove TaskScheduler and all usage of CanScheduleTasks
  • Implement a WordPressTaskStrategy that uses wp_schedule_single_event() for dispatch and add_action() for execution
  • Ensure handlers are attached based on their associated task's Task::getId() value
  • Support HasTaskHandlers inside WordPress initializers for registering task-to-handler chains
    • Provide clear documentation on how to define tasks, write handlers, and register them for WordPress users

Compatibility and Versioning

This refactor will require a major version bump to the WordPress integration package, as it is not backward-compatible with the previous TaskScheduler model.

Users will also need to upgrade to phpnomad/tasks v2.0.0 and migrate any scheduled task logic to the new architecture.

Related

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