Buddypress bp_activity_add(activity_action) hides the link “target”

I'm developing a social network with Buddypress, I created a RSS plugin to pull the RSS feed from the specified websites. Everything is working, except when the RSS is posted to the activity stream. When I create the activity content to print a link, I set the link target to "_new" to open it in a new page. Here's the code:

function wprss_add_to_activity_feed($item, $inserted_ID) {

    $permalink          = $item->get_permalink();
    $title              = $item->get_title();
    $admin              = get_user_by('login', 'admin');

    # Generates the link
    $activity_action    = sprintf( __( '%s published a new RSS link: %s - ', 'buddypress'), bp_core_get_userlink( $admin->ID ), '<a href="' . $permalink .'" target="_blank" title="'.$title.'">' . attribute_escape( wprss_limit_rss_title_chars($title) ) . '</a>');

    /* Record this in activity streams */
    bp_activity_add( array(
        'user_id' => $admin->ID,
        'item_id' => $inserted_ID,
        'action' => $activity_action,
        'component' => 'rss',
        'primary_link' => $permalink,
        'type' => 'activity_update',
        'hide_sitewide' => false


It should come up with something like that:

<a href="link" target="_new" title="link">Test</a>

But it prints like that:

<a href="link" title="link">Test</a>

Why is this happening?


The 'target' attribute is probably getting stripped by BuddyPress's implementation of the kses filters. You can whitelist the attribute as follows:

function se16329156_whitelist_target_in_activity_action( $allowedtags ) {
    $allowedtags['a']['target'] = array();
    return $allowedtags;
add_filter( 'bp_activity_allowed_tags', 'se16329156_whitelist_target_in_activity_action' );

This probably won't retroactively fix the issue for existing activity items - it's likely that they had the offending attribute stripped before being stored in the database. But it should help for future items.

Need Your Help

Run exe with pre arguments in Java

java windows subprocess installutil

I want to run an exe with a pre-argument in java. For example, if this is executed in a command prompt.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.