Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to disable HTML in BuddyPress private message

  • @hellowed

    Participant

    I want to avoid my users from sending private messages with html codes.
    Currently, users can send html tags such as <a> and <span> and receivers of
    messages receive them as html tag.
    All I want to know is a way to display messages as they are typed.

Viewing 5 replies - 1 through 5 (of 5 total)
  • @danbp

    Participant

    hi @hellowed,

    try this (add to child theme functions.php or better, bp-custom.php) It will remove a and span and h1 html tag

    function bpfr_remove_html_from_private_msg($message){
    		$replacement = ''; 
    return preg_replace( "/ <(span|a|h1)[^>]*>/", $replacement, $message);
    	
    }
    add_filter('messages_message_content_before_save', 'bpfr_remove_html_from_private_msg');

    @henrywright

    Moderator

    Hey @danbp,

    WordPress provides a function for that. Check out wp_filter_nohtml_kses(). It strips all HTML from the string you provide so there’s no need to use preg_replace().

    function hellowed_remove_html_private_messages( $message ) {
    
        $message = wp_filter_nohtml_kses( $message );
        return $message;
    }
    add_filter( 'messages_message_content_before_save', 'hellowed_remove_html_private_messages' );

    @danbp

    Participant

    Wow, i searched for that and didn’t found. 👿 Thank you @henrywright for this information. 😀

    @goakes

    Participant

    Hello

    Is it possible to remove HTML from all of the message boxes. Google feels the site is being hacked due to URL being inserted. I need to put a stop to this.

    Any help appreciated.

    Gary

    @goakes

    Participant

    Hello
    There are message boxes in activity (public) and groups as well as private. Is the word private replaced with activity and groups for the other message boxes? If not, how do identify these?

    Thanks for the support.

    Gary

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to disable HTML in BuddyPress private message’ is closed to new replies.
Skip to toolbar