-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webhook course.created
(and likely other ${post_type}.created
) event does not fire
#151
Comments
@thomasplevy and this is the actual hook the webhook "listens to": The So basically the 'product.created' and 'product.updated' are webhooks are both potentially fired when the I think we can then adopt a similar approach, why not?! |
Thanks for the research! If we were to consider a resource new by the same criteria (if the hook is triggered within 10 seconds of the post creation date) then we might as well reduce the amount of code we'd need to rewrite and remove the check that skips the firing of the hook if the post's status is "auto-draft": lifterlms-rest/includes/models/class-llms-rest-webhook.php Lines 268 to 271 in 63daaa1
Right? |
That might be fine, WooCommerce also doesn't "skip" the check above: |
I think you're right and using the WC time-check method probably makes the most sense... I've just run a few tests to review the data on the post object and the So if we remove the check on the 3rd parameter in favor of a check on the post_date (within 10 seconds seem just fine like WC we should fix the issue and still ensure that this only runs when actually publishing something. Additionally if the post is switched to a draft and then back to published later the initial post_date remains unchanged so we wouldn't accidentally trigger created hooks again in the future with this method either |
@eri-trabiccolo do you want to tackle this tomorrow or should I have at it? |
@thomasplevy |
@eri-trabiccolo Perfect thanks |
@thomasplevy |
@thomasplevy WIP here: I just ran some very rough tests that seem to be fine, |
@thomasplevy
I hope that it can do that in less than 10 seconds... What do you think? |
@thomasplevy
I did the same test then with the WIP https://github.com/eri-trabiccolo/lifterlms-rest/tree/webhooks
from this point several other These (and probably also the one above with the scheduled posts) are the problems that I've found until now. In the future, though, we need to implement a more solid solution, and we can still get inspiration from wc - as said the 10s rule, for my understanding, is applied only to distinguish newly created and updated posts with actions triggered by the post editor (meta boxes), while it relies on more ad hoc action hooks for the rest. Translated: we need these hooks. We actually already have action hooks we can use because we have:
What we need is some kind of unification but maybe we can already start using the hooks above - should already cover the various scenarios right? -, and adapt the code just a little bit (once again, thanks woocommerce). Meantime, though, I open the PR with the WIP that at least fixes this very issue, and, for what I could test, doesn't create drawbacks EXCEPT for the edge cases aforementioned. I really hope you, dear reader, liked what you read until now, as much as I liked to write it :/ (*) It kinda works with rest api creation too, but let's consider that a course is not a common post, most of its valuable information is contained in the post metas, which are "set" AFTER the post is inserted into the db - in this case, though, we can use specific rest api action hooks, see: https://github.com/gocodebox/lifterlms-rest/blob/1.0.0-beta.10/includes/abstracts/class-llms-rest-posts-controller.php#L299 |
While I feel that using the other hooks is probably better I think we still run into some issues... Mainly, if we use the metabox processing hooks we still run into a situation where the post might not be really finished. From my perspective this is just as unreliable as what this WIP introduces. I think we should add the generator hooks -- possibly. Currently the generator users WP core functions for post insertion so this would result in the core hook taking care of it. Although we'd still have the not completely finished post issue here since we inserst and then update meta... REST is in a similar boat... Maybe with all that said we need to introduce (into the LLMS core) a hook for each post type that runs after meta information is updated. We don't have a great "save()" method on our data models like WooCommerce does so their in a simpler situation. For them my primitive understanding of progammatic product creation is:
All the hooks can be triggered on save ensuring that there's no "empty" product sent to creation webhooks. This likely is why their 10s rule works better for them than it does for us.. In any event I've merged the WIP so we can close the pending support request and I'm going to leave this open for further improvement in the future. |
That's true and it's true for WC too.
What do you mean? This generator hook is fired at the end of the process:
Well not really, we have an hook that is fired at the very end of the creation process, again, after all the metas have been added:
I'm not sure about this Thomas, when you create a product through the editor, for what I can see, only the |
@eri-trabiccolo I don't know. Solve the problem please. |
Reproduction
Create a new webhook for the
course.created
topic.Publish a new course
Expectation
The webhook will be delivered when the course is created
Actual
The webhook is not delivered
Information
We utilize the WP core
save_post_{$post_type}
hook to trigger the publication of a course. Since this event is fired by WP for both post creation and update we watch the 3rd argument passed to the hook,$update
which istrue
during an update andfalse
during a post creation.If that 3rd argument is
true
we don't fire the webhook.However, this is problematic because WordPress creates the post first as an auto-draft and then fires the hook with
$update=false
but at this stage most users would very likely NOT expect the hook to fire.I believe we need to re-evaluate the hook utilized for publication and can maybe use the
transition_post_status
hooks instead.HS-113632
The text was updated successfully, but these errors were encountered: