3
votes

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?

1

1 Answers

3
votes

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.