2

Is there a way, via an Event or otherwise, to catch the first time a post is saved and isn't in disabled mode? I want to send out an email alert to users when a new entry is published, but I want it to be possible to work on it in disabled mode first.

If I use the entries.onSaveEntry event, it comes with the a param for isNewEntry, but I can't use this because it's only true the very first time an entry is saved, even if it's saved in disabled status. After that it will always return false.

It wouldn't be difficult to add an additional field to the entry that would track whether or not emails were sent, but I was wondering if there's a more straightforward way to handle it.

1 Answer 1

2

There isn't an "event" that gets fired when an entry goes live, but you should be able to listen to the onSaveEntry event, then check the same criteria that Craft uses to determine if an entry is live or not.

As far as tracking if it's the first time the entry had a live status or not, it's kind of lame, but your plugin could have a Record/table that kept track of the entry ID and status so you'd know if it was the first time an entry ID had a status of Live or not.

4
  • Would there be a way to differentiate between the first time it's published live and if it gets saved again, like if a typo needed to be corrected or something?
    – John O
    Jul 7, 2016 at 1:19
  • Updated answer.
    – Brad Bell
    Jul 7, 2016 at 4:27
  • Correct me if I'm wrong... you wouldn't even need a separate Record/table. You could simply have a separate field on the entry, which would get updated once the entry goes live. (A date field would work nicely here.)
    – Lindsey D
    Jul 7, 2016 at 17:30
  • @LindseyD yup, that should work, too
    – Brad Bell
    Jul 7, 2016 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.