Currently, cron jobs created through the API are server-level resources:

POST /api/servers/{server}/crontabs

There is no way to associate a cron job with a specific site. As a result, when a site is deleted, cron jobs created for that site through the API remain on the server and must be found and removed separately.

However, when a WordPress cron job is created through the Ploi panel under:

WordPress → Create cron job

the cron job is attached to that specific site and is automatically removed when the site is deleted.

Would it be possible to expose the same functionality through the API?

A backward-compatible solution could be to add an optional site_id attribute to the existing create-crontab endpoint:

{
  "user": "ploi",
  "command": "/home/ploi/example.com/wp-cron.php",
  "frequency": "*/5 * * * *",
  "site_id": 123
}

When site_id is provided, Ploi could validate that the site belongs to the specified server and store the relationship between the cron job and the site. The command itself would remain fully controlled by the API consumer.

I believe an explicit site_id would be safer than trying to detect the related site automatically from the command path. Automatic detection could become ambiguous when:

  • a command references a file inside a nested directory;
  • one site is installed inside another site's directory;
  • the command contains multiple paths or shell operations;
  • the provided command path does not match the site's configured root directory.

Optionally, site-scoped endpoints could also be provided, for example:

  • POST /api/servers/{server}/sites/{site}/crontabs
  • GET /api/servers/{server}/sites/{site}/crontabs
  • DELETE /api/servers/{server}/sites/{site}/crontabs/{crontab}

However, simply supporting an optional site_id in the existing crontab API would likely solve the main issue without duplicating the entire crontab API.

The main goal is to make API-created cron jobs behave consistently with cron jobs created through the Ploi panel, especially by automatically cleaning them up when the associated site is deleted.

Allow API-created cron jobs to be attached to a site

1 total vote
  • Olek moved item to project API

    8 hours ago
  • Olek created the item

    8 hours ago
Quick Actions
Activity
View recent activity and updates
Use arrow keys to navigate