bbPress: Block Links in Posts From New Members
Stops members who joined in the last few days from posting links in forum topics and replies, with a clear message explaining why.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_add_error' ) ) {
return;
}
$wpide_bbp_link_days = 7;
$wpide_bbp_check_links = function ( $content ) use ( $wpide_bbp_link_days ) {
$user = wp_get_current_user();
if ( ! $user->exists() || current_user_can( 'moderate' ) ) {
return $content;
}
$is_new = time() - strtotime( $user->user_registered . ' UTC' ) < $wpide_bbp_link_days * DAY_IN_SECONDS;
if ( $is_new && preg_match( '#(https?://|www\.|<a\s)#i', $content ) ) {
bbp_add_error( 'wpide_bbp_links', sprintf( '<strong>Error:</strong> New members can post links after %d days. Please remove the link and try again.', $wpide_bbp_link_days ) );
}
return $content;
};
add_filter( 'bbp_new_topic_pre_content', $wpide_bbp_check_links );
add_filter( 'bbp_new_reply_pre_content', $wpide_bbp_check_links );
Notes
Moderators and keymasters can always post links.
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.