fix: don't send an empty SMS when a comment is deleted before send#93
fix: don't send an empty SMS when a comment is deleted before send#93akzmoudud wants to merge 1 commit into
Conversation
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>
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Closes getdokan/texty-pro#31
Problem
WP\Comment::get_message()dereferencedget_comment()with no null check. The comment notification is dispatched synchronously oncomment_post, but the comment can be deleted / trashed / flagged as spam before the send fires (e.g. by an anti-spam plugin hooked oncomment_post).get_comment()then returnsnull.A second, smaller defect: the
{ip}token maps tocomment_author_ip(lowercase), but theWP_Commentproperty iscomment_author_IP. The case mismatch makes it resolve tonull, which triggered astr_replace(): Passing nulldeprecation on every comment, even the happy path.Fix
Dispatcher::new_comment()bails whenget_comment()doesn't return aWP_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 reachesstr_replace()asnull. This also clears the{ip}deprecation.{post_title}is intentionally left unchanged — it already resolves correctly throughWP_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" tocomment_author_IPwould start leaking it into the SMS and logs. Dropping the token is a deliberate product call, not made here.Acceptance criteria
{post_title}and{post_url}resolve to the real post title / permalink.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, nostr_replace(null)deprecation.php -lclean;composer phpcsclean (0 errors) on both files.🤖 Generated with Claude Code