I am now using this
$eventName = $modx->event->name;
switch($eventName) {
case 'OnLoadWebDocument':
$blocked_resource_ids = [32,33]; //IDs of resources to block access to
$current_resource_id = $modx->resource->get('id');
if (in_array($current_resource_id, $blocked_resource_ids)){
$day = (int)date('w'); //A numeric representation of the day (0 for Sunday, 6 for Saturday)
$hour = (int)date('G'); //24-hour format of an hour (0 to 23)
$block_access = false;
//Mon, Tue, Wed, Thur (20:00 to 20:59:59)
if (in_array($day,[1,2,3,4]) && $hour == 20){
$block_access = true;
}
//Sat 18:00 - 21:59:59
if ($day == 6 && $hour >= 18 && $hour < 22){
$block_access = true;
}
if ($block_access) {
$modx->log(modX::LOG_LEVEL_ERROR,'Access blocked to resource ' . $current_resource_id); //Write message to error log
$redirect_id = $modx->getOption('site_unavailable_page',null,1); //read system setting 'site_unavailable_page'
$modx->sendForward($redirect_id);
}
}
break;
}
Pages are not being blocked