perfecty-push-wp icon indicating copy to clipboard operation
perfecty-push-wp copied to clipboard

Multiple notifications on post updating

Open matteomorreale opened this issue 3 years ago • 8 comments

Hi, I've find out that if I set on "true" the toggle for notification on post publishing, any other action without reloading the page (like a post updating action) ends in another push notification sent. If the page is reloaded, no further post notification happens, so it's like that the toggle keeps stay on and sends notifications. This happened to me on 4 sites, 3 of mine and 1 of a friend, so this seems to be an issue not related to my use or configuration (except for Varnish that we both use).

Is it possible to set a time limit before multiple notifications can be sent for the same post?

matteomorreale avatar Aug 30 '21 07:08 matteomorreale

Hi @matteomorreale, the notification is send if the "Send notification on publish" checkbox is checked. In the old WordPress editor the save button performed a page submit which caused the page to be refreshed and the checkbox to reset, however in the new Gutenberg editor (or Block editor), the save is done via Ajax, and thus the webpage is never reloaded and the checkbox remains checked.

The solution would be: detect if in the Gutenberg editor the post is being saved and uncheck the "Send notification on publish" box. This needs to be done in the Client side (Javascript), so we might need a subscribe to the isSavingPost or isAutosavingPost events like:

https://wholesomecode.ltd/blog/hook-save-action-wordpress-gutenberg/ https://wordpress.stackexchange.com/questions/319054/trigger-javascript-on-gutenberg-block-editor-save

rwngallego avatar Aug 30 '21 23:08 rwngallego

FYI @MocioF

rwngallego avatar Aug 30 '21 23:08 rwngallego

Hi @matteomorreale, the notification is send if the "Send notification on publish" checkbox is checked. In the old WordPress editor the save button performed a page submit which caused the page to be refreshed and the checkbox to reset, however in the new Gutenberg editor (or Block editor), the save is done via Ajax, and thus the webpage is never reloaded and the checkbox remains checked.

The solution would be: detect if in the Gutenberg editor the post is being saved and uncheck the "Send notification on publish" box. This needs to be done in the Client side (Javascript), so we might need a subscribe to the isSavingPost or isAutosavingPost events like:

https://wholesomecode.ltd/blog/hook-save-action-wordpress-gutenberg/ https://wordpress.stackexchange.com/questions/319054/trigger-javascript-on-gutenberg-block-editor-save

Hi @rwngallego, I thought this was the issue, that's why I've proposed a temporary workaround that can easily be useful for other things: set a time limit, if another notification push for the same post is sent in this timeshift, the push is ignored.

matteomorreale avatar Aug 31 '21 07:08 matteomorreale

Yeah, I understand. We can start by implementing the logic above first because that will fix the root cause. If necessary we can revisit the time limit again in the future. I consider that once we have the validation in the Gutenberg editor, it will not be possible to send consecutive push messages unless the user consciously marks the checkbox.

rwngallego avatar Aug 31 '21 21:08 rwngallego

Hi, I also ran into this issue. Whenever I update a post, a new notification is sent. But I only want to send it on the initial publish.

Is there a workaround do disable the setting and do it with a php snippet instead? This is really bugging me, as we cannot use notifications like that.

Cheers Nico

NicoHood avatar Oct 09 '22 07:10 NicoHood

You can reload the page after the publication and double check that the flag isn't flagged. In that way it won't push again

matteomorreale avatar Oct 10 '22 13:10 matteomorreale

I see, there is a per-post setting which I did not see in the first place. Isnt there a way to fix this properly? This doesnt sound too complicated, or is it?

NicoHood avatar Oct 10 '22 19:10 NicoHood

I also noticed that an update on a custom post type (astra theme hooks) will also trigger a push notification, which of course is not desired. We would need to disable that as well.

NicoHood avatar Oct 11 '22 12:10 NicoHood