Surface specific moderation errors for activity comments#4898
Surface specific moderation errors for activity comments#4898GaryJones wants to merge 2 commits intobuddyboss:releasefrom
Conversation
The AJAX handler in bp_nouveau_ajax_new_activity_comment() calls bp_activity_new_comment() with the default error_type of 'bool'. This causes WP_Error objects from bp_core_check_for_moderation() (e.g. "You have posted too many links") to be silently converted to false before the AJAX handler can read them. Users see the generic "There was an error posting your reply. Please try again." instead of the specific moderation message. Pass 'error_type' => 'wp_error' and check is_wp_error() on the return value so that specific error messages are surfaced.
|
Thanks for your pull request. It looks like this may be your first contribution to the BuddyBoss Platform open source project. Please note that this project and all contributions to it are public and bounded by the GPL v2.0 license, and that a record of the contribution (including all personal information you submit with it, including your full name and email address) is maintained indefinitely and may be redistributed with this project. If you are not okay with these terms, please close this pull request. Alternatively, you can let us know about your concerns by adding a comment to this pull request. |
|
@claude Review the PR |
|
Claude finished @chetansatasiya's task in 1m 33s —— View job PR Review
SummaryThis is a clean, minimal, and well-targeted fix. The root cause analysis in the PR description is accurate, and the implementation correctly uses the existing Code Review:
|
Problem
When a group activity comment triggers WordPress's built-in link moderation (Settings → Discussion → "Hold a comment in the queue if it contains X or more links"), users see the generic error:
BuddyBoss's own moderation layer (
bp_core_check_for_moderation()) produces a specificWP_Errorwith the message "You have posted too many links", but this error is silently discarded before it reaches the AJAX response. The same problem affects any error originating frombp_core_check_for_moderation(), including matches against the moderation word list.Root cause
bp_nouveau_ajax_new_activity_comment()inbp-templates/bp-nouveau/includes/activity/ajax.phpcallsbp_activity_new_comment()without specifyingerror_type, so it defaults to'bool'.The call chain is:
bp_nouveau_ajax_new_activity_comment()→bp_activity_new_comment()(error_type:'bool')bp_activity_new_comment()→bp_activity_add()(error_type:'bool')bp_activity_add()→$activity->save()save()firesbp_activity_before_save→bp_activity_check_moderation_keys()→bp_core_check_for_moderation()returnsWP_Error('bp_moderation_too_many_links', 'You have posted too many links')$activity->errorsand sets$activity->component = falseto force failuresave()sees empty component, checkserror_type— since it's'bool', returnsfalse(theWP_Erroris discarded here)falsepropagates back up throughbp_activity_add()→bp_activity_new_comment()→ the AJAX handler$bp->activity->errors['new_comment']but this was never populated (that only happens for errors withinbp_activity_new_comment()itself), so the generic fallback message is sentFix
Two changes in
bp_nouveau_ajax_new_activity_comment():Pass
'error_type' => 'wp_error'tobp_activity_new_comment()soWP_Errorobjects propagate through the call chain instead of being converted tofalseCheck
is_wp_error( $comment_id )on the return value and extract the actual error message for the AJAX responseThe existing
$bp->activity->errors['new_comment']fallback is preserved as anelseiffor backwards compatibility.This is consistent with how
bp_activity_new_comment()was designed to work — theerror_typeparameter has been supported since BuddyPress 2.6.0.Steps to reproduce
Test plan
comment_max_linksset to 2, post a group activity comment with 2+ links → should see "You have posted too many links"