nr / scheduledpageactions
Schedule actions like publish, unpublish or hide for ProcessWire pages
Package info
github.com/neuerituale/ScheduledPageActions
Type:pw-module
pkg:composer/nr/scheduledpageactions
Requires
- php: >=7.4
- hari/pw-module: ~1.0
Requires (Dev)
None
Suggests
- nr/processcronjobs: Manage the execution of the scheduled page actions as cron job
Provides
None
Conflicts
None
Replaces
None
README
Schedule actions like publish, unpublish or hide for ProcessWire pages. Editors add actions with a date and time in a Schedule tab of the page editor. The actions are executed by LazyCron, the ProcessCronJobs module or a real cron job.
Features
- “Schedule” tab in the page editor for all configured templates
- Built-in actions: Publish, Unpublish, Hide, Unhide, Lock, Unlock, Move to trash – each can be enabled or disabled
- Custom actions, registered with a hook – every action has a label and a description of what it does
- Permission check when an action is scheduled: users can only schedule actions they are allowed to perform at that time
- Overview of all actions under Setup > Scheduled Page Actions with “Execute now” and “Delete”
- Works with LazyCron, ProcessCronJobs or a system cron job (
cron.php) - Executed and failed actions are logged and cleaned up automatically after a configurable number of days
Screenshots
Schedule tab in the page editor – scheduled and executed actions of the page; new actions are added in the last row.
Overview under Setup > Scheduled Page Actions – all actions of all pages, the next ones on top.
Admin themes
Works with AdminThemeUikit and AdminThemeBridge. The module needs neither
jQuery nor UIkit: its script is plain JavaScript, the help overlay is a native <dialog>, and the colors use
Bridge's design tokens (--pw-surface, --pw-line, --pw-status-* …) with fallbacks, so Bridge's dark mode works too.
Requirements
- ProcessWire 3.0.179 or newer
- PHP 7.4 or newer
Installation
- Copy the files to
/site/modules/ScheduledPageActions/or install with Composer:composer require nr/scheduledpageactions - In the admin go to Modules > Refresh and install Scheduled Page Actions. The admin page Setup > Scheduled Page Actions (ProcessScheduledPageActions) is installed automatically.
- Open the module settings and choose the templates whose pages can have scheduled actions.
- Give the permission
scheduled-page-actionsto all roles that should schedule actions (superusers always can).
Configuration
| Setting | Description |
|---|---|
| Templates | Pages using these templates get the “Schedule” tab. Actions of pages using other templates fail when they are due. |
| Actions | All registered actions (built-in and custom) with their description. Disabled actions cannot be scheduled, and pending ones fail when they are due. Lock, Unlock and Move to trash are disabled by default; newly registered custom actions are enabled unless they set 'enabled' => false. |
| Trigger | LazyCron, ProcessCronJobs or Real cron job. The details next to it show whether the module is installed and the interval, or the crontab line for cron.php. |
| Interval | How often LazyCron / ProcessCronJobs checks for due actions. ProcessCronJobs also offers direct (on every call of its cron path). |
| Delete executed actions after (days) | 0 deletes actions right after execution, -1 never deletes them. |
Permissions
To see the “Schedule” tab, a user needs the permission scheduled-page-actions and edit access to the page.
When an action is scheduled (or executed manually with “Execute now”), it is checked whether the user is allowed to
perform the action itself:
| Action | Required |
|---|---|
| Publish | $page->publishable() (respects page-publish) |
| Unpublish | $page->publishable(), the template allows unpublishing, not the homepage |
| Hide / Unhide | $page->editable() |
| Lock / Unlock | page-edit and page-lock |
| Move to trash | $page->trashable() |
| Custom actions | their allowed callback, default $page->editable() |
Actions executed by the cron run without a permission check, because the permission was checked when they were scheduled.
To change the checks, hook ScheduledPageActions::isActionAllowed:
$wire->addHookAfter('ScheduledPageActions::isActionAllowed', function(HookEvent $event) { [$name, $page] = $event->arguments; if($name === 'trash' && !$event->wire()->user->hasRole('chief-editor')) $event->return = false; });
Execution
Due actions are executed by ScheduledPageActions::run(). Each action is claimed in the database before it is executed,
so it never runs twice, even when several triggers run at the same time.
LazyCron
Default. Choose LazyCron as trigger and an interval. LazyCron is triggered by page views, so actions may be executed later than scheduled on sites with little traffic.
Real cron job
cron.php runs all due actions from the command line. It can be used together with any trigger setting; choose
Real cron job to disable the other triggers. The module settings show the crontab line with the correct path.
* * * * * php /path/to/site/modules/ScheduledPageActions/cron.php >/dev/null 2>&1
If the module is not located in /site/modules/ScheduledPageActions/, set the ProcessWire root with PW_ROOT:
* * * * * PW_ROOT=/path/to/processwire php /path/to/ScheduledPageActions/cron.php
You can also call it from your own script:
$modules->get('ScheduledPageActions')->run();
ProcessCronJobs
Install ProcessCronJobs, choose ProcessCronJobs as trigger and an
interval. The module registers the cron job ScheduledPageActions, which you can monitor and run in the ProcessCronJobs
admin.
ProcessCronJobs runs its jobs when its path is called (default /cron/), usually by a real cron job:
* * * * * curl --silent "https://example.com/cron/" >/dev/null 2>&1
The interval limits how often the job runs on these calls. direct (only available for ProcessCronJobs) runs it on every call, so the cron job alone controls the timing.
Custom actions
Custom actions are registered with a hook after ScheduledPageActions::registerActions, e.g. in /site/init.php,
/site/ready.php or the init() method of your own module:
$wire->addHookAfter('ScheduledPageActions::registerActions', function(HookEvent $event) { /** @var ScheduledPageActions $spa */ $spa = $event->object; $spa->registerAction('archive', [ 'label' => 'Archive', 'description' => 'Moves the page below /archive/.', // required: executes the action, return false or throw an exception on failure 'execute' => function(Action $action) { $page = $action->page; // loaded with include=all, output formatting is off $page->parent = wire()->pages->get('/archive/'); return $page->save(); }, // optional: can the user schedule the action for this page? Default: $page->editable() 'allowed' => function(Page $page, User $user) { return $page->editable() && $user->hasRole('chief-editor'); }, // optional: enabled by default (default true), can be changed in the module settings 'enabled' => true, ]); });
| Key | Description |
|---|---|
label |
Shown in the page editor, the overview and the module settings. |
description |
What the action does. Shown in the module settings, below the action select in the page editor and as tooltip in the tables. |
execute |
function(Action $action), required. An action fails if it throws an exception or returns false. The error is shown in the overview and logged. |
allowed |
function(Page $page, User $user): bool, optional. Checked when the action is scheduled or executed with “Execute now”. |
enabled |
Default state until it is changed in the module settings (default true). |
The action name may contain letters, digits, underscore and dash. Registering an existing name (e.g. publish)
replaces the built-in action.
The built-in actions call hookable methods, so you can also hook them, e.g. ScheduledPageActions::scheduledPageActionPublish.
Hooks
| Hook | Description |
|---|---|
ScheduledPageActions::registerActions() |
Registers the built-in actions – hook after it to register custom actions. |
ScheduledPageActions::getActions() |
Enabled actions (name => label). |
ScheduledPageActions::isActionAllowed(string $name, Page $page) |
Can the current user schedule/execute this action? |
ScheduledPageActions::isPageSupported(Page $page) |
Can the page have scheduled actions? |
ScheduledPageActions::executeAction(Action $action) |
Execute a single action. |
ScheduledPageActions::actionDone(Action $action, $result) |
After an action was executed successfully. |
ScheduledPageActions::actionFailed(Action $action, string $message) |
After an action failed. |
ScheduledPageActions::run() |
Execute all due actions, returns the number of executed actions. |
ScheduledPageActions::cleanup() |
Delete old executed actions. |
Example: notify the author after a page was published.
$wire->addHookAfter('ScheduledPageActions::actionDone', function(HookEvent $event) { /** @var Action $action */ $action = $event->arguments(0); if($action->name !== 'publish') return; $mail = $event->wire()->mail->new(); $mail->to($action->createdUser->email)->subject("Published: {$action->page->title}")->send(); });
API
/** @var ScheduledPageActions $spa */ $spa = $modules->get('ScheduledPageActions'); // schedule an action $action = new Action(); $action->setArray([ 'name' => 'unpublish', 'date' => '2030-01-01 00:00', 'page' => $pages->get('/news/old-news/'), ]); $spa->addAction($action); // find actions $spa->findActions(['page' => $page]); // all actions of a page $spa->findActions(['due' => true]); // due actions $spa->findActions(['done' => false]); // pending and due actions
addAction() does not check permissions – use isActionAllowed() first if needed.
Logs
scheduled-page-actions-successscheduled-page-actions-errors
Translations
A German translation ships in languages/de.csv. With LanguageSupport installed, open Modules > Site > Scheduled Page Actions and click install translations (ProcessWire >= 3.0.181) to import it into a language of your choice.
License
MIT, see LICENSE.

