Skip to:
Content
Pages
Categories
Search
Top
Bottom

Prevent banned words from deleting the user’s post?


  • FTLRalph
    Participant

    @ftlralph

    If a user types a banned word, BP shows the “You have posted an inappropriate word.” message and the comment is lost.

    This can be frustrating if it was a long post/comment and one single word trashed the whole thing without warning.

    I’m looking through available hooks and functions but can’t seem to figure out what would be the best course of action to, for example, run the “bp_activity_check_moderation_keys” function but not just return a WP_Error, instead just highlight the comment box in red/show a message up top rather than clearing it away.

Viewing 7 replies - 1 through 7 (of 7 total)

  • shanebp
    Moderator

    @shanebp

    If you are talking about activity posts…

    The default behavior is NOT to remove the content, but to refuse to post it and show the error message and leave the content in the textbox.
    Are you running some other code re moderation?

    Anyhow…
    Unfortunately, there are no hooks in the moderation functions.
    So you would need to remove the hook that is added in buddypress\bp-activity\bp-activity-filters.php

    add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
    add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys',  2, 1 );

    and replace it will a hook that leads to a custom function that does what you want.


    FTLRalph
    Participant

    @ftlralph

    Thanks

    But it might actually just be activity comments then, I hadn’t checked posts, but when leaving a comment the entire submission form goes away and the “You have posted an inappropriate word” message is shown in its place

    The type of behavior for posts you describe is essentially what I was looking to do with comments


    shanebp
    Moderator

    @shanebp

    The default behavior for activity comments is also NOT to remove the content, but to refuse to post it and show the error message and leave the content in the comment textbox.


    FTLRalph
    Participant

    @ftlralph

    I’m using 3.2.0 BP plugin with just a CSS-modified bp-default theme. It definitely fades out the comment and replaces it with basically a “nah son” message with no way to go back.

    k

    I don’t *think* the theme has anything to do with this, as it’s all form-related stuff that has its origins in the plugin files.

    Where would be the best place/function to look to see how comments get pre-processed before submitting the form?


    FTLRalph
    Participant

    @ftlralph

    Bump – if anyone can assist, what hook should I look for to see how comments get pre-processed before submitting the form? In order to display a message that the content is inappropriate or something beforehand


    FTLRalph
    Participant

    @ftlralph

    It does look like it’s a bp-legacy thing.

    I’m no JavaScript guy but in the js file included in default bp-legacy themes there appears to be this code which is the only place I can force it to cancel the form submission, but I’d need to detect something is wrong here in the JavaScript first.

    This is the relevant section of the buddypress-activity.js file:

    // Submitting comments and replies
    if ( 'ac_form_submit' === target.prop( 'name' ) ) {
    	var comment_content, comment_data;
    
    	form = target.closest( 'form' );
    	item_id = activity_id;
    
    	// Stop event propagation
    	event.preventDefault();
    
    	if ( target.closest( 'li' ).data( 'bp-activity-comment-id' ) ) {
    		item_id    = target.closest( 'li' ).data( 'bp-activity-comment-id' );
    	}
    
    	comment_content = $( form ).find( 'textarea' ).first();
    
    	target.addClass( 'loading' ).prop( 'disabled', true );
    	comment_content.addClass( 'loading' ).prop( 'disabled', true );
    
    	comment_data = {
    		action                        : 'new_activity_comment',
    		_wpnonce_new_activity_comment : $( '#_wpnonce_new_activity_comment' ).val(),
    		comment_id                    : item_id,
    		form_id                       : activity_id,
    		content                       : comment_content.val()
    	};
    
    	// Add the Akismet nonce if it exists
    	if ( $( '#_bp_as_nonce_' + activity_id ).val() ) {
    		comment_data['_bp_as_nonce_' + activity_id] = $( '#_bp_as_nonce_' + activity_id ).val();
    	}
    
    	parent.ajax( comment_data, 'activity' ).done( function( response ) {
    		target.removeClass( 'loading' );
    		comment_content.removeClass( 'loading' );
    		$( '.acomment-reply' ).attr( 'aria-expanded', 'false' );
    		// etc...

    shanebp
    Moderator

    @shanebp

    Have you tried using the filter hooks to write functions that bypass the blacklist and moderation checks? You can find the hooks in this file: buddypress\bp-core\bp-core-moderation.php

    For example, this could go in your theme > functions.php or in bp-custom.php :

    function bp_bypass_checks( $flag, $user_id, $title, $content ) {
    	return true;	
    }
    add_filter( 'bp_bypass_check_for_blacklist', 'bp_bypass_checks', 1, 4 );
    add_filter( 'bp_bypass_check_for_moderation', 'bp_bypass_checks', 1, 4 );
Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar