Skip to content

Pattern Directory: Log flag status changes only once the flag is fully saved - #816

Merged
obenland merged 3 commits into
trunkfrom
claude/gh-pattern-directory-480
Nov 16, 2026
Merged

obenland merged 3 commits into
trunkfrom
claude/gh-pattern-directory-480

Conversation

@obenland

@obenland obenland commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Fixes #480

Flag status notes on a pattern's log were written from transition_post_status in the Pattern Directory's logging code. That hook fires in the middle of wp_insert_post(), before the flag's terms and meta are saved and before a REST request has finished, so a flag could be logged even when its save didn't complete.

This moves the logging to wp_after_insert_post, as the notifications already do, and reads the old status from the post before the update. It runs at priority 5 so a new flag is still logged ahead of any status change the flag threshold makes on the pattern. A flag with no reporter account is now skipped instead of raising a warning on the missing user; the alternative is logging it with a placeholder handle.

Testing

  • bin/check (composer install, PHP lint, npm ci, CSS/JS lint, PHPUnit against WordPress nightly, Jest): all passed; PHPUnit OK (351 tests).
  • New Flag_Logging_Test covers new, resolved and trashed flags, using an in-memory stand-in for wporg-internal-notes, which CI doesn't load. Its check that a flag is logged only once fully saved fails without the fix.
  • Manually: report a pattern, then resolve the flag in wp-admin; the pattern's log shows both entries.

Props ryelle.

Opened by the wporg bug pipeline, unattended. Risk: needs-review.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Flag activity records now reflect status changes after the flag has been fully saved, including new flags, resolutions, and moves to trash.
    • Unchanged statuses no longer create duplicate activity entries. Records are also skipped when the associated author cannot be found, preventing incomplete log entries.

…y saved

Flag status notes were written on `transition_post_status`, which fires in
the middle of `wp_insert_post()`, before the flag's terms and meta are
saved, and before a REST request has finished. Move the logging to
`wp_after_insert_post`, as the notifications already do, reading the old
status from the post before the update. It runs at priority 5 so a new
flag is still logged ahead of any status change `check_flag_threshold()`
makes on the pattern. A flag without a reporter account is skipped
instead of failing on the missing user.

Fixes #480.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YBAW4tyUi7UPtZygTvpuaQ
Copilot AI lite review requested due to automatic review settings November 15, 2026 04:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: abf2a357-c975-4889-922e-60d44a91c4be
Commits

Reviewing files that changed from the base of the PR and between 075233d and bc7d897.

Files selected for processing: 4

  • public_html/wp-content/plugins/pattern-directory/includes/logging.php
  • public_html/wp-content/plugins/pattern-directory/tests/phpunit/class-flag-logging-test.php
  • public_html/wp-content/plugins/pattern-directory/tests/phpunit/stub-internal-notes.php
  • public_html/wp-content/tests/phpunit/bootstrap.php

No actionable comments were generated in the recent review.

Walkthrough

The flag logging callback now runs after post insertion. It derives the new and prior statuses from the post data and skips logging when the author cannot be found. New PHPUnit tests cover initial logging, deferred hooks, and status changes.

Changes: Flag status logging

Layer / File(s) Summary
Post-insert status logging
public_html/wp-content/plugins/pattern-directory/includes/logging.php
The callback now uses wp_after_insert_post. It derives statuses from the post and prior post, and returns if it cannot find the author.
Callback behavior tests
public_html/wp-content/plugins/pattern-directory/tests/phpunit/class-flag-logging-test.php, public_html/wp-content/plugins/pattern-directory/tests/phpunit/stub-internal-notes.php
Tests cover new flags, deferred after-insert hooks, unchanged statuses, resolution, and trashing. The test stand-in records Internal Notes when the plugin function is unavailable.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: coreymckrill

Merge Risk: Minimal · previous review 07523

Pattern flag logging now runs after the flag is fully saved, and flags without a reporter account are skipped instead of causing a warning. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: flag status logging for Pattern Directory now runs only after the flag is fully saved. It matches the raw summary, which moves the hook to wp_after_insert_post, and th…
Description check Passed The description covers the change and its reason. It explains that the old transition_post_status hook fired before terms and meta were saved. It references issue #480 with a Fixes keyword, describes …
Linked Issues check Passed Issue #480 asks to move pattern-flag logging to wp_after_insert_post. At the reviewed head, logging.php registers flag_status_change with add_action( 'wp_after_insert_post', ..., 5, 4 ). The old hook …
Out of Scope Changes check Passed All changes support issue #480 or its implementation. logging.php changes move the hook and update the function signature to match wp_after_insert_post arguments. The early return when the reporter us…
Full details: Title check

Explanation

The title names the main change: flag status logging for Pattern Directory now runs only after the flag is fully saved. It matches the raw summary, which moves the hook to wp_after_insert_post, and the PR objectives, which describe the same move.

Full details: Description check

Explanation

The description covers the change and its reason. It explains that the old transition_post_status hook fired before terms and meta were saved. It references issue #480 with a Fixes keyword, describes the priority 5 choice and the skip for missing reporter accounts, and lists testing steps. It does not fill the template's 'How to test' numbered steps or the Screenshots section, and it lacks a Props line for the reporter's handle in the template format, though it does state 'Props ryelle'. Screenshots are not needed for this non-visual change. The template's numbered test steps are replaced by a Testing section, which is acceptable.

Full details: Linked Issues check

Explanation

Issue #480 asks to move pattern-flag logging to wp_after_insert_post. At the reviewed head, logging.php registers flag_status_change with add_action( 'wp_after_insert_post', ..., 5, 4 ). The old hook registration on transition_post_status is removed. The function reads the new status from $post->post_status and the old status from $post_before, using 'new' when no prior post exists. This meets the issue's only requirement. The issue has no separate acceptance criteria or automated test requirement. The PR also adds Flag_Logging_Test, which covers new, resolved, and trashed flags. I did not read the test file body directly. I relied on the summary for its contents.

Full details: Out of Scope Changes check

Explanation

All changes support issue #480 or its implementation. logging.php changes move the hook and update the function signature to match wp_after_insert_post arguments. The early return when the reporter user is missing is a behavior change inside the same function. It is disclosed in the PR description and does not affect other code. The test class and the InternalNotes stand-in (stub-internal-notes.php) support verification of the new hook, because CI does not load wporg-internal-notes. No unrelated files appear in the summary. Note: I could not read the diff hunks directly. The assessment relies on the file contents at the head and the supplied summaries.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d9b903f-d38e-4506-adaa-51e8be14adf6
Commits

Reviewing files that changed from the base of the PR and between 1f4941e and 075233d.

Files selected for processing: 3

  • public_html/wp-content/plugins/pattern-directory/includes/logging.php
  • public_html/wp-content/plugins/pattern-directory/tests/phpunit/class-flag-logging-test.php
  • public_html/wp-content/plugins/pattern-directory/tests/phpunit/stub-internal-notes.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

obenland and others added 2 commits November 14, 2026 23:33
… stub

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stub for every test

- A flag whose reporter's account no longer exists was left out of the
  pattern's log entirely. Name the reporter "a deleted user" instead.
- An update fired without the post as it was would be logged as a new
  flag. Skip it, since the old status is unknown.
- Return on an unchanged status before looking up the user, as most
  saves now reach the hook without a status change.
- Move the reason for the hook priority next to the add_action call.
- Load the internal notes stub from the PHPUnit bootstrap. Defining it
  from one test file turned logging on for whichever tests ran after it,
  depending on load order. The test now only reads the stub's record,
  since the real plugin is never loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@obenland
obenland merged commit f0a7592 into trunk Nov 16, 2026
5 checks passed
@obenland
obenland deleted the claude/gh-pattern-directory-480 branch November 16, 2026 19:35
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.

Update the action for logging changes to pattern flags

3 participants