Skip to:

bp_activity_filter_kses function

  • daltontastic


    All throughout my site I have some hidden groups, and if you are a member of them I use the groups_is_user_member snippet to do certain things. For example if you’re a member of the “Verified” group you have a verified icon by your name on profile and in the activity feed.
    I’m encountering a problem with that method though and it’s probably out of silly human error.

    I am trying to give premium members access to different HTML tags than regular members. I removed this script from the BuddyPress source code and placed it in bp-custom.php. It wasn’t working so I echoed $id and it was 0, so I’m guessing bp-custom.php has no idea user’s are logged in and probably can’t access groups_is_user_member either? It didn’t work when it was in bp-activity/bp-activity-filters.php either.

    If I remove the group IF statement I can use all the HTML tags so that isn’t the problem. The problem is that the IF statement has no idea if I’m logged in or a member of the group.

    $id               = get_current_user_id();
    $premium_group_id = 13;
    function bp_activity_filter_kses($content)
        global $allowedtags;
        $activity_allowedtags = $allowedtags;
        if (groups_is_user_member($id, $premium_group_id)) {
            $activity_allowedtags['a']['href']   = array();
            $activity_allowedtags['b']           = array();
            $activity_allowedtags['i']           = array();
            $activity_allowedtags['darkblue']    = array();
            $activity_allowedtags['darkgreen']   = array();
            $activity_allowedtags['darkaqua']    = array();
            $activity_allowedtags['darkred']     = array();
            $activity_allowedtags['darkpurple']  = array();
            $activity_allowedtags['gold']        = array();
            $activity_allowedtags['gray']        = array();
            $activity_allowedtags['darkgray']    = array();
            $activity_allowedtags['blue']        = array();
            $activity_allowedtags['green']       = array();
            $activity_allowedtags['aqua']        = array();
            $activity_allowedtags['red']         = array();
            $activity_allowedtags['lightpurple'] = array();
            $activity_allowedtags['yellow']      = array();
            $activity_allowedtags['a']['href']   = array();
        } else {
            $activity_allowedtags['a']['href'] = array();
        $activity_allowedtags = apply_filters('bp_activity_allowed_tags', $activity_allowedtags);
        return wp_kses($content, $activity_allowedtags);
Viewing 5 replies - 1 through 5 (of 5 total)

  • r-a-y


    Do not remove the bp_activity_filter_kses() function.

    Hook into the 'bp_activity_allowed_tags' filter and do your checks there.



    I guess I misinterpreted this function in the first place. I was under the impression that this function decided if tags were stripped before posting, but it’s actually a function that effects all status updates. So my setup wouldn’t even work anyways because if you weren’t Premium you’d be unable to see other’s colorful text.

    Anyhow this function confuses me in some ways. It lets you use <b> <i> and even if you remove them from the function. Seems weird.



    `that last part was an A HREF tag lol




    color buttons are TinyMCE tools and not html tags. The only way to get them would be to use the editor toolbar.

    Here a scenario you could use:
    – create a child-theme and add post-form.php to it (copy from bp-templates/bp-legacy/buddyPress/activity/post-form.php).
    Result: your-child-theme/buddypress/activity/post-form.php

    In that file, go to line:40 where textarea start.
    Inser this action hook:

    <?php if ( bp_is_groups_component() ) : ?>
    	<?php do_action( 'blablabla' ); ?>
    <?php endif ?>

    Then add this <?php if ( ! bp_is_groups_component() ) : ?>
    <textarea class="bp-suggestions"......bla...bla...</textarea>
    and add <?php endif ?> after the textarea closing tag.

    This contionnals will show a custom area for the desired group and prevent update area to appear on all other groups home pages.

    So if a user is member of different groups, he will get a texteditor for group_id 13 and the normal update area on all others.

    The custom template is ready. Now the fonctions we need.

    Open bp-custom.php (or create it) and paste in those snippets.

    Adding the texteditor:

    function bpfr_whats_new_tiny_editor() {
    	// deactivation of the visual tab, so user can't play with style tools
    //add_filter ( 'user_can_richedit' , create_function ( '$a' , 'return false;' ) , 50 );
    $content = "";
    	// building the what's new textarea
    	if ( isset( $_GET['r'] ) ) :
    	$content = esc_textarea( $_GET['r'] ); 
    	// adding tinymce tools
    	$editor_id = 'whats-new';
    	$settings = array( 
    			'textarea_name' => 'whats-new', 
    			'teeny' => false, 
    			'media_buttons' => true, 
    			'drag_drop_upload' => true, 
    			'quicktags' => array(
    			'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close'
    	// get the editor	
    	wp_editor( $content, $editor_id, $settings );
    add_action( 'whats_new_textarea', 'bpfr_whats_new_tiny_editor' );

    A simple function who add the original textarea for users who are group members, but not allowed to rich edit.

    function my_textarea() { ?>
    			<textarea class="bp-suggestions" name="whats-new" id="whats-new" cols="50" rows="10"
    				<?php if ( bp_is_group() ) : ?>data-suggestions-group-id="<?php echo esc_attr( (int) bp_get_current_group_id() ); ?>" <?php endif; ?>
    			><?php if ( isset( $_GET['r'] ) ) : ?>@<?php echo esc_textarea( $_GET['r'] ); ?> <?php endif; ?></textarea>

    And the last one, where you set up the group allowed to publish updates using edit tools.

    function trotro() {
    if ( bp_is_groups_component() ) :
    $check = groups_is_user_member( bp_loggedin_user_id(), bp_get_group_id() );
    $check_group = bp_get_group_id(); 
    	if ($check != 0 && $check_group == 21 && 'leon' == bp_current_item() ){
    		echo 'Wow! You can rich edit in this group.';
    	} else {
    		echo 'Sorry, you cannot rich edit in this group';
    add_action( 'blablabla', 'trotro' );

    Now, any member which is part of the group leon, group id 23 can publish updates and use the color picker and all other things which are on the edit bar.

    Only thing you have to do is to adjust leon and id to your rules.

    Successfully tested on 2.6 and 2016.

    May this help you to go further with your BuddyPress project. 🙂



    Hey thanks that is very detailed!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar