OneSignal is a free push notification service for web and mobile apps. This plugin makes it easy to integrate your website with OneSignal Push Notifications. https://onesignal.com
Other
80
stars
42
forks
source link
The status of "Send notification on post publish" checkbox is not saved for the Draft status #292
When "Automatically send a push notification...." option is selected in plugin dashboard and you create a new post - "Send notification on post publish" checkbox on the post page is pre-checked, as expected. But if you are not publishing immediately and if you unchecked this box and saved a draft, the box status is not saved and it becomes checked again as soon as the page refreshes, so that you need to uncheck it once more before publishing.
Steps to Reproduce Issue:
Log in to WordPress.
Create a new post and save as Draft
Observe that "Send notification on post publish" checkbox is pre-checked.
Uncheck "Send notification on post publish" checkbox and save as Draft again
Observe that "Send notification on post publish" checkbox is checked again after the page is refreshed - the checkbox status is not saved.
We've found this code in line 288 of this file: onesignal-admin.php
if ((get_post_meta($post->ID, 'onesignal_send_notification', true) === '1')) { $meta_box_checkbox_send_notification = true; } else { // We check the checkbox if: setting is enabled on Config page, post type is ONLY "post", and the post has not been published (new posts are status "auto-draft") $meta_box_checkbox_send_notification = ($settings_send_notification_on_wp_editor_post && // If setting is enabled $post->post_type === 'post' && // Post type must be type post for checkbox to be auto-checked !in_array($post->post_status, array('publish', 'private', 'trash', 'inherit'), true)); // Post is scheduled, incomplete, being edited, or is awaiting publication } The fix:
Adding 'draft' to the array of post statuses fixes this behaviour and the checkbox status gets saved.
!in_array($post->post_status, array('publish', 'private', 'draft', 'trash', 'inherit'), true));
We have not found a simple way to hook into this without changing the plugin code.
Any ideas how to patch?
Description:
When "Automatically send a push notification...." option is selected in plugin dashboard and you create a new post - "Send notification on post publish" checkbox on the post page is pre-checked, as expected. But if you are not publishing immediately and if you unchecked this box and saved a draft, the box status is not saved and it becomes checked again as soon as the page refreshes, so that you need to uncheck it once more before publishing.
Steps to Reproduce Issue:
A video illustrating the issue https://www.loom.com/share/15fa23ca4f5e4bd8b75492e00d93ecdc
Anything else:
We've found this code in line 288 of this file: onesignal-admin.php
if ((get_post_meta($post->ID, 'onesignal_send_notification', true) === '1')) { $meta_box_checkbox_send_notification = true; } else { // We check the checkbox if: setting is enabled on Config page, post type is ONLY "post", and the post has not been published (new posts are status "auto-draft") $meta_box_checkbox_send_notification = ($settings_send_notification_on_wp_editor_post && // If setting is enabled $post->post_type === 'post' && // Post type must be type post for checkbox to be auto-checked !in_array($post->post_status, array('publish', 'private', 'trash', 'inherit'), true)); // Post is scheduled, incomplete, being edited, or is awaiting publication }
The fix: Adding 'draft' to the array of post statuses fixes this behaviour and the checkbox status gets saved.!in_array($post->post_status, array('publish', 'private', 'draft', 'trash', 'inherit'), true));
We have not found a simple way to hook into this without changing the plugin code. Any ideas how to patch?Thanks, Alex Mayer alex@acewebstudio.com