# BuddyPress: Strip Links From New Members' Activity Updates

> Turns links into plain text in activity updates posted by members who joined recently, which takes the reward out of spam sign-ups.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: buddypress, spam, activity
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/buddypress-strip-links-new-members/

## Code

```php
if ( ! function_exists( 'buddypress' ) ) {
    return;
}

// Members registered fewer than this many days ago cannot post links.
$wpide_bp_link_days = 7;

add_action( 'bp_activity_before_save', function ( $activity ) use ( $wpide_bp_link_days ) {
    if ( empty( $activity->user_id ) || empty( $activity->content ) || user_can( $activity->user_id, 'bp_moderate' ) ) {
        return;
    }

    $user = get_userdata( $activity->user_id );

    if ( ! $user || time() - strtotime( $user->user_registered . ' UTC' ) > $wpide_bp_link_days * DAY_IN_SECONDS ) {
        return;
    }

    $content = preg_replace( '#<a\b[^>]*>(.*?)</a>#is', '$1', $activity->content );
    $content = preg_replace( '#\bhttps?://#i', '', $content );
    $activity->content = preg_replace( '#\bwww\.#i', 'www ', $content );
} );
```

## Notes

Change $wpide_bp_link_days to set how long members count as new. Moderators are never affected.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "BuddyPress: Strip Links From New Members' Activity Updates" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
