// Remove OneSignal action for post updates
function prevent_onesignal_notifications_on_update($new_status, $old_status, $post) {
error_log("OneSignal Action Check: post_id={$post->ID}, new_status=$new_status, old_status=$old_status");
if ($new_status === 'publish' && $old_status === 'publish') {
remove_action('transition_post_status', 'onesignal_schedule_notification', 10, 3);
error_log("OneSignal Action Removed: Blocked notification for post update (post_id={$post->ID})");
}
}
add_action('transition_post_status', 'prevent_onesignal_notifications_on_update', 5, 3);
// Set os_update meta for new publications and block for updates
function override_onesignal_update_flag($new_status, $old_status, $post) {
error_log("OneSignal Status Transition: post_id={$post->ID}, new_status=$new_status, old_status=$old_status");
if ($new_status === 'publish' && $old_status === 'publish') {
update_post_meta($post->ID, 'os_update', 0); // Disable notifications for updates
error_log("OneSignal: Disabled os_update meta for post update (post_id={$post->ID})");
} elseif ($new_status === 'publish' && $old_status !== 'publish') {
update_post_meta($post->ID, 'os_update', 1); // Enable notifications for new publications
error_log("OneSignal: Enabled os_update meta for new publication (post_id={$post->ID})");
}
}
add_action('transition_post_status', 'override_onesignal_update_flag', 10, 3);
Got sick of waiting for an update so added the above to my functions.php to stop sending notifications on update.
I then have the checkbox for “Send notification when post is published or updated” checked and it only sends on publish.