Skip to content

fix: don't send an empty SMS when a comment is deleted before send#93

Open
akzmoudud wants to merge 1 commit into
developfrom
fix/comment-notification-deleted-comment
Open

fix: don't send an empty SMS when a comment is deleted before send#93
akzmoudud wants to merge 1 commit into
developfrom
fix/comment-notification-deleted-comment

Conversation

@akzmoudud

Copy link
Copy Markdown
Contributor

Closes getdokan/texty-pro#31

Problem

WP\Comment::get_message() dereferenced get_comment() with no null check. The comment notification is dispatched synchronously on comment_post, but the comment can be deleted / trashed / flagged as spam before the send fires (e.g. by an anti-spam plugin hooked on comment_post). get_comment() then returns null.

Note on severity: validated against the live code on PHP 8.4 — reading a property on null is a Warning, not a fatal, so there is no 500 (only a method call on null is fatal, and this code only reads properties). The real harm is that the notification still rendered an empty-bodied message and sent/billed it: A new comment added on the post "" by ().

A second, smaller defect: the {ip} token maps to comment_author_ip (lowercase), but the WP_Comment property is comment_author_IP. The case mismatch makes it resolve to null, which triggered a str_replace(): Passing null deprecation on every comment, even the happy path.

Fix

  • Dispatcher::new_comment() bails when get_comment() doesn't return a WP_Comment, so a missing comment never renders or bills an SMS.
  • Comment::get_message() null-guards the comment and coerces every token value to string ((string) ( $comment->$value ?? '' )), so a missing value never reaches str_replace() as null. This also clears the {ip} deprecation.

{post_title} is intentionally left unchanged — it already resolves correctly through WP_Comment's magic __get, which proxies post fields to the post (verified: renders the real title). The issue's claim that {post_title} renders empty is incorrect.

Out of scope (flagged for product decision)

The {ip} token currently renders empty because of the case typo, so the commenter's IP is not exposed today. "Fixing the case" to comment_author_IP would start leaking it into the SMS and logs. Dropping the token is a deliberate product call, not made here.

Acceptance criteria

  • Sending after the comment is deleted returns gracefully (no warning flood, no billed empty SMS).
  • {post_title} and {post_url} resolve to the real post title / permalink.
  • No PHP 8.1 str_replace(null) deprecation.

Verification

Validated on PHP 8.4.11 / WP-CLI:

  • Dispatcher::new_comment( <deleted id> ) → bails cleanly, no send, no warning.
  • get_message() on a deleted comment → no warnings/deprecations.
  • get_message() on a normal comment → renders title + author + URL, no str_replace(null) deprecation.
  • php -l clean; composer phpcs clean (0 errors) on both files.

🤖 Generated with Claude Code

WP\Comment::get_message() dereferenced the result of get_comment()
with no null check. When the comment is deleted, trashed, or flagged as
spam between the `comment_post` hook and the synchronous send (e.g. by an
anti-spam plugin), get_comment() returns null. On PHP 8.x this is a
warning rather than a fatal, but the notification still rendered an
empty-bodied message and sent (and billed) it.

- Guard Dispatcher::new_comment() so a missing comment bails before any
  send — no wasted, billed SMS for a comment that no longer exists.
- Harden get_message(): null-guard the comment, and coerce every token
  value to string so a missing value never reaches str_replace() as null
  (deprecated since PHP 8.1). This also clears the deprecation that the
  typo'd `{ip}` token (comment_author_ip vs comment_author_IP) triggered
  on every comment.

{post_title} is left unchanged — it already resolves correctly through
WP_Comment's magic __get, which proxies post fields to the post.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@akzmoudud, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 16 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e0da48d-9fd6-4262-924e-e6d265d2e956

📥 Commits

Reviewing files that changed from the base of the PR and between 5d20bb9 and 8b92444.

📒 Files selected for processing (2)
  • includes/Dispatcher.php
  • includes/Notifications/WP/Comment.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/comment-notification-deleted-comment

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

Comment @coderabbitai help to get the list of available commands.

@akzmoudud akzmoudud self-assigned this Jun 26, 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.

1 participant