Surface specific moderation errors for activity comments#4898
Open
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Open
Surface specific moderation errors for activity comments#4898GaryJones wants to merge 1 commit intobuddyboss:releasefrom
GaryJones wants to merge 1 commit 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. |
chetansatasiya
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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"