Example of executing code after first post to a thread?

Kevin

Well-known member
Any examples of executing some code after the first, and only the first, post of a thread? Essentially I just want to have some code kick in after somebody replies to an existing thread for the first time and if that post response is not flagged for spam, etc..

If there are any examples I could check out, that'd be really appreciated, thanks. :)
 
Hi
I haven't tried it, but try setting up a code listener (entity_post_save), and running your code only if
$post->Thread->first_post_id == $post->post_id

PHP:
class PostListener
{
    public static function postSave(Entity $post)
    {
        // Ensure the entity is a Post
        if (!$post instanceof Post) {
            return;
        }

        if ($post->isInsert()) { // New post was created
            if ($post->Thread->first_post_id == $post->post_id){
                self::callYourFunction();
            }
        }
    }
    
    protected static function callYourFunction() {
        /* Your code */
    }
}
 
Last edited:
Back
Top Bottom