# Delayed publication

**URL:** <https://discourse.getcockpit.com/t/delayed-publication/165>\
**Category:** Addons\
**Created:** [July 19, 2018, 8:42am UTC](https://discourse.getcockpit.com/t/delayed-publication/165 "2018-07-19T08:42:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [July 19, 2018, 8:42am UTC](https://discourse.getcockpit.com/t/delayed-publication/165/1 "2018-07-19T08:42:21Z")

</div>

Set a specific date/time for an entry to switch from unpublished to published, assisted by a cron job.

Should this be an addon or is it more close to core?

What would be the best approach to add this to Cockpit?

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [July 20, 2018, 6:54pm UTC](https://discourse.getcockpit.com/t/delayed-publication/165/2 "2018-07-20T18:54:14Z")

</div>

I would do this using plain PHP in you webpage / frontend. No need for using crons or making things more complex then they need to be.

Just add a (datepicker-)field for the desired publishing-date to your collection.

Then when processing the entries that have been fetched from the cockpit-api/collection, create a PHP DateTime Object ([http://php.net/manual/de/class.datetime.php](http://php.net/manual/de/class.datetime.php)) from the (datepicker-)field that holds the publishing-date.

Next create one more DateTime-object with the very current datetime (the obj will automatically contain the current time when you just do `new DateTime()`) and compare them to each other using the date-/datetime-diff functions like so: [https://stackoverflow.com/questions/19031235/php-check-if-date-is-past-to-a-certain-date-given-in-a-certain-format/19031322](https://stackoverflow.com/questions/19031235/php-check-if-date-is-past-to-a-certain-date-given-in-a-certain-format/19031322) .

If the date of the entry is less recent then the current datetime, it may be shown because the publishing date was exeeded

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [July 20, 2018, 7:09pm UTC](https://discourse.getcockpit.com/t/delayed-publication/165/3 "2018-07-20T19:09:20Z")

</div>

That could work, but it doesn’t flip the Published flag.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [July 20, 2018, 7:12pm UTC](https://discourse.getcockpit.com/t/delayed-publication/165/4 "2018-07-20T19:12:14Z")

</div>

a field that defines a date when the post should be published renders a dedicated “published” boolean-field completely redundant

but if you want to have a dedicated boolean field and want it to be auto-set to true as the publishing-data of an entry is exeeded, you can use webhooks (with the event “collections.find.before” (see [https://github.com/agentejo/cockpit/issues/661](https://github.com/agentejo/cockpit/issues/661) for all events that can be hooked)) in order to update a entry which’s publishing time is in the past

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [July 25, 2018, 2:08pm UTC](https://discourse.getcockpit.com/t/delayed-publication/165/5 "2018-07-25T14:08:55Z")

</div>

I can see some scenarios where that make sense, think it can be implemented as an addon without too much effort:

1. Addon provides a new field type (publishing availability) with two values (from and to)
2. Addon implements the collections.find.after hook, and if the field type is present and the required conditions are not met (from/to date from field value matches the current date) will filter out the entry

Using above approach you can define a period range where the contents will be returned or not.

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [July 25, 2018, 3:05pm UTC](https://discourse.getcockpit.com/t/delayed-publication/165/6 "2018-07-25T15:05:45Z")

</div>

This makes a lot of sense. Thanks!

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [July 29, 2018, 8:55pm UTC](https://discourse.getcockpit.com/t/delayed-publication/165/7 "2018-07-29T20:55:34Z")

</div>

Since this is an interesting use case I created a new addon that provides the functionality that described above:

> **[pauloamgomes/Cockpit-PublicationPeriod](https://github.com/pauloamgomes/Cockpit-PublicationPeriod)**
>
> This Cockpit CMS addon extends Cockpit CMS core functionality by introducing the possibility to limit the collection entries based on an Publication Period field - pauloamgomes/Cockpit-PublicationP...

Hope that helps.

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [July 30, 2018, 6:59am UTC](https://discourse.getcockpit.com/t/delayed-publication/165/8 "2018-07-30T06:59:14Z")

</div>

That’s awesome! Thanks!
