aderaaij / wp-vercel-deploy-hooks

WordPress Plugin to trigger Vercel deploy hooks on command / update
GNU General Public License v3.0
71 stars 18 forks source link

Trigger Vercel build when the post is being moved to trash #6

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi,

I noticed no build is being triggered when the post is being moved to trash. It seems to be reasonable to trigger a build in such situation, at least when an already published post is being removed, doesn't it?

Otherwise I think it's a nice plugin, I'm trying to build a Next.js application with WordPress backend ;)

aderaaij commented 2 years ago

Heya, that's a good question. I think you're absolutely right and it's a feature that wouldn't be too hard to implement. Would you expect that enabled by default or as an option?

ghost commented 2 years ago

I'd expect it to be enabled whenever build trigger after post update is enabled - I'd assume the moving post to trash should be treated as an update.

I can try to make a pull request (unless you are proficient in WordPress and you want it yourself, I somewhat tinker with WordPress, but I don't know PHP). I think we should run it only when we delete a post that is already published.

I wonder which action should we use, is it wp_trash_post or trashed_post? In the first one we'll have access to post status, but it seems it's too early to call it then, trashed_post action is certainly a good time to trigger a build, but we don't have access to post status (it'll be always trash at this point), so we'd have to call it regardless the trashed post status was publish, draft or future. Am I missing something here?

ghost commented 2 years ago

On the other hand we're not checking post status in post_updated, so maybe it won't hurt to use trashed_post hook anyway?

aderaaij commented 2 years ago

true, maybe something we should do. but honestly for now trashed_post seems fine. I'm not completely sure if bulk deleting posts would cause multiple deploys.

I'm totally open to a PR, I have no idea what I'm doing 👍

ghost commented 2 years ago

I've got some idea. Finally I think we should only base on post_updated hook and check if it's a REST API request. I'll try to make a pull request today, I've got a code but I want to make sure it behaves correctly in all cases.