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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.