Skip to content

fix: cancel scheduled notification when reverting a post to draft.#427

Merged
sherwinski merged 4 commits into
mainfrom
fix/cancel-scheduled-notification-on-draft-revert
Jun 24, 2026
Merged

fix: cancel scheduled notification when reverting a post to draft.#427
sherwinski merged 4 commits into
mainfrom
fix/cancel-scheduled-notification-on-draft-revert

Conversation

@marclucraft

Copy link
Copy Markdown
Contributor

One Line Summary

fix: Cancel scheduled notification when reverting a post to draft. Updated version to 3.9.1

Motivation

Customer follow up via Support

Previously, reverting a scheduled post to Draft or Pending Review left the
corresponding OneSignal notification queued — it would still fire at the
original scheduled time even though the post was no longer going to publish.

Scope

  • Affected: Scheduled posts (future status) that are reverted to Draft or
    Pending Review before their publish time.
  • Not affected: Posts being published, posts having their scheduled date
    changed via quick-edit (existing behaviour unchanged), post deletion/trash,
    v2 legacy code, JS/CSS behaviour, any other status transitions.

Testing

Manual

  1. Install the plugin with a valid OneSignal App ID and REST API key.
  2. Create a new post, set the publish date to tomorrow, check Send push
    notification
    , and save as Scheduled.
  3. Confirm a scheduled notification appears in the OneSignal dashboard with the
    correct send time.
  4. Reopen the post in WordPress, switch its status to Draft, and update.
  5. Expected: The notification is cancelled in the OneSignal dashboard and no
    push is delivered at the original scheduled time.
  6. Repeat step 4 using Pending Review — same expected outcome.
  7. Verify the inverse: trash a scheduled post still cancels the notification
    (regression check on the shared helper).
  8. Verify: changing a scheduled post's date via quick-edit still cancels and
    re-creates the notification (regression).

Test in both Classic editor and Block (Gutenberg) editor.
WordPress 6.x+, PHP 7.4+.

Unit / Integration

Three new integration tests added to tests/integration/TestAPIIntegration.php:

  • test_cancel_notification_when_scheduled_post_reverts_to_draft — verifies the
    DELETE API call is made and post meta is cleared on a future → draft transition.

  • test_no_cancellation_when_no_notification_stored_on_draft_revert — verifies
    no HTTP request is made when there is no stored notification ID.

  • test_no_cancellation_for_disallowed_post_type_on_draft_revert — verifies the
    post-type guard prevents cancellation for unregistered post types.

  • composer test passes locally

Affected code checklist

  • PHP plugin code (v3/)
  • v2/ legacy code
  • JS / CSS assets
  • Build / CI
  • Tests
  • Documentation (README, readme.txt, etc.)

Checklist

  • Code follows existing style in the touched files
  • Tested manually in the relevant editor(s)
    • Gutenberg/Block editor
    • Classic editor
  • No new lint or test errors introduced
  • Linear ticket / GitHub issue linked above
  • readme.txt and plugin version bumped if user-facing (release PRs only)

@marclucraft marclucraft requested a review from sherwinski June 16, 2026 08:58
@sherwinski

Copy link
Copy Markdown
Contributor

Thanks @marclucraft, let me give this a test locally and review before moving to merge.

Comment thread tests/integration/TestAPIIntegration.php
Comment thread v3/onesignal-notification.php Outdated
…l_and_clear_notification

The handler was renamed from onesignal_cancel_notification_on_post_delete but the
hook-registration test still referenced the old name, making the assertion
self-referential and decoupled from the production registration.
…rt branch

The elseif already follows the publish/future branch, so new_status can never be
publish or future here; the extra checks were dead.
Keep version metadata and changelog updates to a dedicated release PR.
@sherwinski sherwinski merged commit 2bc81f0 into main Jun 24, 2026
9 checks passed
@sherwinski sherwinski deleted the fix/cancel-scheduled-notification-on-draft-revert branch June 24, 2026 20:25
@github-actions github-actions Bot mentioned this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants