Kirby 4 Article Schedule Publish Hooks

Hi,

I am on Kirby 4.

I am looking for a hook that would be executed when a page/article is being published on future date per Published Date setting.

When i choose date in the future and set the status to public it auto changes it to unlisted and then on the publish date it is being changed to public.

How can i run some code when that status is being change to public in the future? Seems like standard hooks are not executed at this point.

How is the status changed?

Yeah, I had hoped you might put some light on that as i cannot find the way it switches from unlisted to public on that specific time in the future, does Kirby has some job that run and might be doing that?

So i am guessing that is not part of core Kirby features to publish article in the future?

That is the upgraded version from Kirby 3 and it already had Published Date field.

No, definitely not. Something like that is usually done with some sort of cron job. Did you purchase a theme that adds that functionality maybe?

What do you need that hook for? You could trigger a hook from the code that does the status change, but for that we need to know where that code is running.

Your demo, has field date, which if i put a future date and change to publish status, will that not prevent the article to be published until that date?

No, not at all. And in particular, the status of the page will not be changed automatically depending on date. Although I cannot tell from the top of my head what the demo code does, need to check.

Whether a published page is show in a blog list on the frontend, depends on what you do in the frontend. If you filter by date <= time(), then the page will not be listed. However, unless a page has draft status or you have some other mechanism in place to prevent access to such a page, it is accessible via URL to somebody who manages to guess the URL.

So if you want to make 100% sure the page is not viewable by someone trying out urls, you have several options:

  • The page remains in draft status, and a cron job changes the status to published depending on day
  • You prevent access to such pages via a route that prevents access if the date is not published yet.

Edit: I just checked the blog related code in the demo and cannot see anything that would hide a blog article with a future date.

If I wouldn’t want to bother with cron jobs, I’d change a page with a future date to listed, and in the frontend, filter by date.

Additionally, I’d probably add either a route that sends people to the error page if the page has a date in the future, or add an if statement in the article template that redirects to the error page when page not supposed to be shown yet.

1 Like

Let’s say due to the above i want to extend cache class Kirby\Cache\FileCache to be able to provide $created argument to match it with the future time - that argument which is not supported in the current implementation:

public function set(string $key, $value, int $minutes = 0): bool

Plugin cache settings:

'cache' => [
            'active' => true,
            'type' => 'file',
            'extension' => 'json',
        ],

I can create custom plugin with extended class and new set method that provides that option but how do i make Kirby to use that class instead of core one?

I’m a bit at a loss now, what do you want with the Cache class here?

Custom cache driver is the answer :slight_smile: